atomiq.overrides

Validated, thread-safe store for live updates of mutable arguments.

The store holds the current host-native value of every argument that may change while a scan runs. Writers call ArgumentOverrideStore.update from any thread. The scan reads a consistent copy with ArgumentOverrideStore.snapshot at each chunk fetch.

Attributes

Classes

ArgumentOverrideStore

Holds the live values of the mutable arguments of a run.

Functions

_type_name(value)

Get a readable type name of a value, with the module for types that are not builtin.

_kind_from_seed(definition, seed)

Get the kind of an argument, using the same rule as the point schema.

Module Contents

atomiq.overrides._KIND_BOOL = 'bool'
atomiq.overrides._KIND_ENUM = 'enumeration'
atomiq.overrides._KIND_INT = 'int'
atomiq.overrides._KIND_FLOAT = 'float'
atomiq.overrides._INT64_MIN = -9223372036854775808
atomiq.overrides._INT64_MAX = 9223372036854775807
atomiq.overrides._type_name(value)[source]

Get a readable type name of a value, with the module for types that are not builtin.

Parameters:

value (object) -- Any object.

Returns:

The qualified type name, for example int or numpy.bool.

Return type:

str

atomiq.overrides._kind_from_seed(definition, seed)[source]

Get the kind of an argument, using the same rule as the point schema.

Parameters:
  • definition (dict) -- Argument definition dict.

  • seed (object) -- Submitted value of the argument.

Returns:

one of "bool", "int" and "float". None if the argument cannot be updated: a string without options, or a seed without a kernel type.

Return type:

"enumeration" if the definition has options that are not None, else the kind of the kernel type of the seed value

class atomiq.overrides.ArgumentOverrideStore(definitions, values, mutable, active_axes)[source]

Holds the live values of the mutable arguments of a run.

The store is seeded with the submitted values. update validates a batch of new values against the argument definitions and applies it atomically. snapshot returns a copy of all values. A lock guards both methods, so a snapshot never contains part of a batch.

The kind of an argument is fixed at construction, by the same rule as the point schema: an argument whose definition has options is an enumeration, every other kind comes from the kernel type of the seed value. The caller must pass seeds that are consistent with the schema. In particular the seed of a Scannable-derived argument is a float and the seed of an int argument is an int. An argument whose seed has no kernel type, or is a string without options, cannot be updated.

Values are host-native. Numbers are compared with min and max of the definition as they are, in base units: ARTIQ divides min, max and step by scale only to display them in the GUI, while the value passed to the experiment is already multiplied by scale. For an argument with unit="us" and scale=1e-6, a value of 5e-6 is valid and a value of 5 is not. The bounds are enforced for every numeric argument that has them in its definition, including Scannable-derived ones, although the argument builder does not pass them to Scannable and the GUI does not enforce them.

A bool argument accepts only a Python bool. numpy.bool_ and ints are rejected, like on the RPC wire. An int argument accepts an int or a numpy integer that is not a bool and fits in 64 bits signed. It must be a multiple of step counted from min, or from 0 when there is no min. A float argument accepts a finite int or float that is not a bool and stores it as float. A number that is too large for a float is a ValueError. The step of a float argument is not checked. An enumeration accepts a string that is one of options and stores it as a plain str.

Parameters:
  • definitions (dict) -- Argument definitions, keyed by argument name. They are deep copied, so later changes to the passed dicts have no effect.

  • values (dict) -- Submitted host-native values, keyed by argument name. They seed the store.

  • mutable (set) -- Names of the arguments that may be updated.

  • active_axes (set) -- Names of the arguments that are active scan axes. They cannot be updated.

_definitions
_values
_kinds
_mutable
_active_axes
_lock
update(values)[source]

Validate a batch of new values and apply it.

Every entry is validated first. If one is invalid, the exception is raised and no value changes.

Parameters:

values (dict) -- New host-native values, keyed by argument name.

Returns:

dict of the values of the batch as stored, keyed by argument name. A value is a bool, int, float or str. A number for a float argument comes back as float.

Raises:
  • TypeError -- If values is not a dict, a key is not a string, or a value has the wrong type for its argument.

  • KeyError -- If a name is not a known argument.

  • ValueError -- If an argument is not mutable, is an active scan axis, is out of range, is off its step, or is an enumeration value that is not in the options.

Return type:

dict

snapshot()[source]

Get a copy of the current values.

Returns:

dict of all values, keyed by argument name.

Return type:

dict

_validate(name, value)[source]

Check one value against its definition.

Parameters:
  • name (str) -- Name of the argument.

  • value (object) -- New host-native value.

Returns:

The value in its stored form, a bool, int, float or str.

Raises:
  • TypeError -- If the name is not a string or the value has the wrong type.

  • KeyError -- If the name is not a known argument.

  • ValueError -- If the argument is not mutable, is an active scan axis, or the value is invalid.

Return type:

object

static _check_range(name, number, definition, kind)[source]

Check a number against min, max and, for ints, step.

Parameters:
  • name (str) -- Name of the argument.

  • number (float) -- Value to check.

  • definition (dict) -- Argument definition.

  • kind (str) -- Kind of the argument, "int" or "float".

Raises:

ValueError -- If the number is below min, above max, or an int that is off its step.

Return type:

None