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¶
Holds the live values of the mutable arguments of a run. |
Functions¶
|
Get a readable type name of a value, with the module for types that are not builtin. |
|
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
intornumpy.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".Noneif the argument cannot be updated: a string without options, or a seed without a kernel type.- Return type:
"enumeration"if the definition hasoptionsthat are notNone, 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.
updatevalidates a batch of new values against the argument definitions and applies it atomically.snapshotreturns 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
optionsis 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 aScannable-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
minandmaxof the definition as they are, in base units: ARTIQ dividesmin,maxandstepbyscaleonly to display them in the GUI, while the value passed to the experiment is already multiplied byscale. For an argument withunit="us"andscale=1e-6, a value of5e-6is valid and a value of5is not. The bounds are enforced for every numeric argument that has them in its definition, includingScannable-derived ones, although the argument builder does not pass them toScannableand 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 anumpyinteger that is not a bool and fits in 64 bits signed. It must be a multiple ofstepcounted frommin, or from 0 when there is nomin. 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 aValueError. Thestepof a float argument is not checked. An enumeration accepts a string that is one ofoptionsand stores it as a plainstr.- 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,floatorstr. A number for a float argument comes back asfloat.- Raises:
TypeError -- If
valuesis 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,floatorstr.- 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,maxand, 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, abovemax, or an int that is off its step.- Return type:
None