atomiq.overrides ================ .. py:module:: atomiq.overrides .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: atomiq.overrides._KIND_BOOL atomiq.overrides._KIND_ENUM atomiq.overrides._KIND_INT atomiq.overrides._KIND_FLOAT atomiq.overrides._INT64_MIN atomiq.overrides._INT64_MAX Classes ------- .. autoapisummary:: atomiq.overrides.ArgumentOverrideStore Functions --------- .. autoapisummary:: atomiq.overrides._type_name atomiq.overrides._kind_from_seed Module Contents --------------- .. py:data:: _KIND_BOOL :value: 'bool' .. py:data:: _KIND_ENUM :value: 'enumeration' .. py:data:: _KIND_INT :value: 'int' .. py:data:: _KIND_FLOAT :value: 'float' .. py:data:: _INT64_MIN :value: -9223372036854775808 .. py:data:: _INT64_MAX :value: 9223372036854775807 .. py:function:: _type_name(value) Get a readable type name of a value, with the module for types that are not builtin. :param value: Any object. :returns: The qualified type name, for example ``int`` or ``numpy.bool``. .. py:function:: _kind_from_seed(definition, seed) Get the kind of an argument, using the same rule as the point schema. :param definition: Argument definition dict. :param seed: 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. :rtype: ``"enumeration"`` if the definition has ``options`` that are not ``None``, else the kind of the kernel type of the seed value .. py:class:: ArgumentOverrideStore(definitions, values, mutable, active_axes) 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``. :param definitions: Argument definitions, keyed by argument name. They are deep copied, so later changes to the passed dicts have no effect. :param values: Submitted host-native values, keyed by argument name. They seed the store. :param mutable: Names of the arguments that may be updated. :param active_axes: Names of the arguments that are active scan axes. They cannot be updated. .. py:attribute:: _definitions .. py:attribute:: _values .. py:attribute:: _kinds .. py:attribute:: _mutable .. py:attribute:: _active_axes .. py:attribute:: _lock .. py:method:: update(values) 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. :param values: 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. :raises KeyError: If a name is not a known argument. :raises 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. .. py:method:: snapshot() Get a copy of the current values. :returns: dict of all values, keyed by argument name. .. py:method:: _validate(name, value) Check one value against its definition. :param name: Name of the argument. :param value: 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. :raises KeyError: If the name is not a known argument. :raises ValueError: If the argument is not mutable, is an active scan axis, or the value is invalid. .. py:method:: _check_range(name, number, definition, kind) :staticmethod: Check a number against ``min``, ``max`` and, for ints, ``step``. :param name: Name of the argument. :param number: Value to check. :param definition: Argument definition. :param kind: 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.