atomiq.point_schema =================== .. py:module:: atomiq.point_schema .. autoapi-nested-parse:: Point schema entries, tiers and the mapping of argument values to kernel types. The point schema lists every attribute of a scan point together with its tier and kernel type. It is frozen once per run and drives the generated point class, the chunk-fetch RPC and the generated kernel code. Classes ------- .. autoapisummary:: atomiq.point_schema.Tier atomiq.point_schema.PointSchemaEntry Functions --------- .. autoapisummary:: atomiq.point_schema.kernel_type_of atomiq.point_schema.to_wire Module Contents --------------- .. py:class:: Tier(*args, **kwds) Bases: :py:obj:`enum.Enum` Classification of a point attribute by when its value can change. ``CONSTANT`` attributes are fixed for the whole run. They are declared as kernel invariants, so the compiler can hoist their loads out of loops. They hold arguments that are neither scanned nor mutable, and the run id. ``SCANNED`` attributes vary per point. They hold scan axes with more than one value and the step counter. The kernel writes them for every point from the columns of the fetched chunk. ``CHUNK`` attributes belong to mutable arguments that are not an active scan axis. The value is read once per chunk. It is constant within a chunk and may differ between chunks. ``COMPUTED`` attributes are set inside the kernel and never sent by the host. The point identifier is one. .. py:attribute:: CONSTANT :value: 'constant' .. py:attribute:: SCANNED :value: 'scanned' .. py:attribute:: CHUNK :value: 'chunk' .. py:attribute:: COMPUTED :value: 'computed' .. py:class:: PointSchemaEntry One attribute of the frozen point schema. :param name: Attribute name, read as ``point.`` in user code. :param tier: Tier of the attribute. :param type: Kernel type of the attribute, for example ``float`` or ``str``. :param options: Allowed values of an enumeration. The wire value is the index into this tuple. ``None`` for all other entries. .. py:attribute:: name :type: str .. py:attribute:: tier :type: Tier .. py:attribute:: type :type: PointSchemaEntry.type .. py:attribute:: options :type: tuple[str, ...] | None :value: None .. py:function:: kernel_type_of(value) Return the kernel type for a host value. The mapping is ``bool`` to ``bool``, integers to ``numpy.int64``, floats to ``float`` and strings to ``str``. The bool check comes first because ``bool`` is a subclass of ``int``. :param value: Host value of an argument. :returns: The kernel type of the value. :raises TypeError: If the value has no kernel type. .. py:function:: to_wire(value, entry) Cast a host value to the scalar that is sent to the kernel for a schema entry. This only casts. Callers validate the value first, because the casts truncate silently: ``numpy.int64(2.7)`` is 2 and ``bool("False")`` is ``True``. ARTIQ checks RPC return values strictly. A ``numpy.bool_`` is rejected for a bool and an int is rejected for a float, so every value is cast to the exact type of its entry. Enumeration values are sent as a ``numpy.int32`` index into the options of the entry. :param value: Host value of the argument. :param entry: Schema entry of the argument. :returns: The value as the kernel type of the entry, or the option index for an enumeration. :raises ValueError: If the entry has options and the value is not one of them. :raises OverflowError: If an integer value does not fit into ``numpy.int64``.