atomiq.atomiq ============= .. py:module:: atomiq.atomiq Attributes ---------- .. autoapisummary:: atomiq.atomiq.default_argument_provider atomiq.atomiq.logger Classes ------- .. autoapisummary:: atomiq.atomiq.KernelChunk atomiq.atomiq.Chunk atomiq.atomiq.AtomiqExperiment atomiq.atomiq.AtomiqBlock Module Contents --------------- .. py:data:: default_argument_provider .. py:data:: logger .. py:class:: KernelChunk(points) Represents a chunk of scan points optimized for kernel execution. This class behave similar to :py:class:`Chunk` but for use inside an ARTIQ kernel with reduced python capabilities. The main change is that this class is not iterable but :py:meth:`KernelChunk.to_list()` must be used to obtain an iterable chunk list. .. py:attribute:: _points .. py:attribute:: kernel_invariants .. py:attribute:: _variable_args :value: [] .. py:method:: __getattribute__(name) .. py:method:: to_list() .. py:method:: __repr__() .. py:class:: Chunk Bases: :py:obj:`list` Extended list class for managing chunks of scan points. Provides convenience methods for accessing common attributes across all points in the chunk. .. py:method:: __getattr__(attr) .. py:method:: get(attr) .. py:method:: get_kernel_chunk() Get a KernelChunk copy of the chunk for ARTIQ kernel execution. .. py:class:: AtomiqExperiment(managers_or_parent, name=None, arg_provider=None, component_map=None, *args, **kwargs) Bases: :py:obj:`artiq.language.environment.EnvExperiment` Base class for top-level experiments that use the :class:`~artiq.language.environment.HasEnvironment` environment manager. Most experiments should derive from this class. .. py:attribute:: CHUNKSIZE :value: 10 .. py:attribute:: TAGS :value: [] .. py:attribute:: components :value: ['log'] .. py:attribute:: heros_realm :value: 'heros' .. py:attribute:: arg_provider .. py:attribute:: _components :value: [] .. py:attribute:: _blocks :value: [] .. py:attribute:: name .. py:attribute:: component_map :value: None .. py:attribute:: clock_at_start .. py:attribute:: identifier .. py:attribute:: step_counter :value: 0 .. py:attribute:: run_id :value: 0 .. py:attribute:: __terminate_asap__ :value: False .. py:attribute:: _sequence_error :value: False .. py:method:: _create_atomiq_hero() .. py:method:: _getmro() .. py:method:: _import_from_block(blkdata) This uses monkey patching of the class to make members available to the current experiment :param blkdata: Block data with the keys "class", "map", "alias" .. py:method:: _add_to_hook_handler(obj_list) Add the hooks the objects in obj_list to the experiment hooks such that they are called when processing the hooks. Only if the child object posses a method with the according name of the hook, it will be called. :param obj_list: list of child objects relative to self (e.g. 'modulator.rfsource.switch') for which the hook should be called .. py:method:: _build_blocks() .. py:method:: _build_components() .. py:method:: _build_arguments() .. py:method:: get_multiscanmanager() Get the MultiScanManager of all arguments. .. py:method:: prepare() Prepares components and structure. Called by ARTIQ in the prepare phase, see ARTIQ documentation for more information on experiment phases. .. note:: If you overwrite this method in your experiment, make sure to call `super().prepare()`. .. py:method:: _build_core() .. py:method:: _build() .. py:method:: build() Initializes arguments. Called by ARTIQ in the build phase, see ARTIQ documentation for more information on experiment phases. .. note:: If you overwrite this method in your experiment, make sure to call `super().build()` .. py:method:: _prerun_core(reset=False) .. py:method:: _set_identifiers_in_master(identifier, run_id, step_counter) makes an rpc call to set the identifier in the master .. py:method:: chunker(mult_scan, size = 100) Generator to call a kernel with chunks of scan points. .. py:method:: _loop_chunks(chunk_list) Loop over a list of chunks in the host, i.e. iterate over starting kernels holding CHUNKSIZE experiments :param chunks: (list) list of chunks. Each entry is again an iterable with CHUNKSIZE Scanpoint objects inside .. py:method:: _run_init() .. py:method:: run() Run entry point for ARTIQ, see ARTIQ documentation for more information on experiment phases. .. warning:: Do not implement this entry point in your experiment. Use the provided sub-phases (`prerun`, `step`, etc.) More information can be found in the :ref:`phases_chunking` documentation. .. py:method:: _runchunk(points) .. py:method:: terminate() Terminate the running experiment as soon as possible. Normally this means after the current chunk. .. py:method:: prerun() Kernel entry point, run once at the beginning of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prerun_host() Host entry point, run once at the beginning of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postfail() .. py:method:: postfail_host() .. py:method:: postrun() Kernel entry point, run once at the end of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postrun_host() Host entry point, run once at the end of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prestep(point) Kernel entry point, run before every step. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: poststep(point) Kernel entry point, run after every step. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prechunk(points) Kernel entry point, run once at the beginning of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postchunk(points) Kernel entry point, run once at the end of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prechunk_host(points) Host entry point, run once at the beginning of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postchunk_host(points) Host entry point, run once at the end of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: step(point) :abstractmethod: Kernel entry point, for the main experiment sequence code. This method **must** be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: analyze() Entry point for analyzing the results of the experiment. This method may be overloaded by the user to implement the analysis phase of the experiment, for example fitting curves. Splitting this phase from :meth:`run` enables tweaking the analysis algorithm on pre-existing data, and CPU-bound analyses to be run overlapped with the next experiment in a pipelined manner. This method must not interact with the hardware. .. py:attribute:: children :value: [] .. py:attribute:: __in_build :value: True .. py:method:: register_child(child) .. py:method:: call_child_method(method, *args, **kwargs) Calls the named method for each child, if it exists for that child, in the order of registration. :param method: Name of the method to call :type method: str :param args: Tuple of positional arguments to pass to all children :param kwargs: Dict of keyword arguments to pass to all children .. py:method:: get_argument(key, processor, group=None, tooltip=None) Retrieves and returns the value of an argument. This function should only be called from ``build``. :param key: Name of the argument. :param processor: A description of how to process the argument, such as instances of :mod:`~artiq.language.environment.BooleanValue` and :mod:`~artiq.language.environment.NumberValue`. :param group: An optional string that defines what group the argument belongs to, for user interface purposes. :param tooltip: An optional string to describe the argument in more detail, applied as a tooltip to the argument name in the user interface. .. py:method:: setattr_argument(key, processor=None, group=None, tooltip=None) Sets an argument as attribute. The names of the argument and of the attribute are the same. The key is added to the instance's kernel invariants. .. py:method:: interactive(title='') Request arguments from the user interactively. This context manager returns a namespace object on which the method :meth:`~artiq.language.environment.HasEnvironment.setattr_argument` should be called, with the usual semantics. When the context manager terminates, the experiment is blocked and the user is presented with the requested argument widgets. After the user enters values, the experiment is resumed and the namespace contains the values of the arguments. If the interactive arguments request is cancelled, raises :exc:`~artiq.language.environment.CancelledArgsError`. .. py:method:: get_device_db() Returns the full contents of the device database. .. py:method:: get_device(key) Creates and returns a device driver. .. py:method:: setattr_device(key) Sets a device driver as attribute. The names of the device driver and of the attribute are the same. The key is added to the instance's kernel invariants. .. py:method:: set_dataset(key, value, *, unit=None, scale=None, precision=None, broadcast=False, persist=False, archive=True) Sets the contents and handling modes of a dataset. Datasets must be scalars (``bool``, ``int``, ``float`` or NumPy scalar) or NumPy arrays. :param unit: A string representing the unit of the value. :param scale: A numerical factor that is used to adjust the value of the dataset to match the scale or units of the experiment's reference frame when the value is displayed. :param precision: The maximum number of digits to print after the decimal point. Set ``precision=None`` to print as many digits as necessary to uniquely specify the value. Uses IEEE unbiased rounding. :param broadcast: the data is sent in real-time to the master, which dispatches it. :param persist: the master should store the data on-disk. Implies broadcast. :param archive: the data is saved into the local storage of the current run (archived as a HDF5 file). .. py:method:: mutate_dataset(key, index, value) Mutate an existing dataset at the given index (e.g. set a value at a given position in a NumPy array) If the dataset was created in broadcast mode, the modification is immediately transmitted. If the index is a tuple of integers, it is interpreted as ``slice(*index)``. If the index is a tuple of tuples, each sub-tuple is interpreted as ``slice(*sub_tuple)`` (multi-dimensional slicing). .. py:method:: append_to_dataset(key, value) Append a value to a dataset. The target dataset must be a list (i.e. support ``append()``), and must have previously been set from this experiment. The broadcast/persist/archive mode of the given key remains unchanged from when the dataset was last set. Appended values are transmitted efficiently as incremental modifications in broadcast mode. .. py:method:: get_dataset(key, default=NoDefault, archive=True) Returns the contents of a dataset. The local storage is searched first, followed by the master storage (which contains the broadcasted datasets from all experiments) if the key was not found initially. If the dataset does not exist, returns the default value. If no default is provided, raises ``KeyError``. By default, datasets obtained by this method are archived into the output HDF5 file of the experiment. If an archived dataset is requested more than one time or is modified, only the value at the time of the first call is archived. This may impact reproducibility of experiments. :param archive: Set to ``False`` to prevent archival together with the run's results. Default is ``True``. .. py:method:: get_dataset_metadata(key, default=NoDefault) Returns the metadata of a dataset. Returns dictionary with items describing the dataset, including the units, scale and precision. This function is used to get additional information for displaying the dataset. See :meth:`set_dataset` for documentation of metadata items. .. py:method:: setattr_dataset(key, default=NoDefault, archive=True) Sets the contents of a dataset as attribute. The names of the dataset and of the attribute are the same. .. py:method:: set_default_scheduling(priority=None, pipeline_name=None, flush=None) Sets the default scheduling options. This function should only be called from ``build``. .. py:class:: AtomiqBlock(*args, **kwargs) Bases: :py:obj:`AtomiqExperiment` Base class for top-level experiments that use the :class:`~artiq.language.environment.HasEnvironment` environment manager. Most experiments should derive from this class. .. py:attribute:: experiment .. py:method:: _getmro() .. py:attribute:: CHUNKSIZE :value: 10 .. py:attribute:: TAGS :value: [] .. py:attribute:: components :value: ['log'] .. py:attribute:: heros_realm :value: 'heros' .. py:attribute:: arg_provider .. py:attribute:: _components :value: [] .. py:attribute:: _blocks :value: [] .. py:attribute:: name .. py:attribute:: component_map :value: None .. py:attribute:: clock_at_start .. py:attribute:: identifier .. py:attribute:: step_counter :value: 0 .. py:attribute:: run_id :value: 0 .. py:attribute:: __terminate_asap__ :value: False .. py:attribute:: _sequence_error :value: False .. py:method:: _create_atomiq_hero() .. py:method:: _import_from_block(blkdata) This uses monkey patching of the class to make members available to the current experiment :param blkdata: Block data with the keys "class", "map", "alias" .. py:method:: _add_to_hook_handler(obj_list) Add the hooks the objects in obj_list to the experiment hooks such that they are called when processing the hooks. Only if the child object posses a method with the according name of the hook, it will be called. :param obj_list: list of child objects relative to self (e.g. 'modulator.rfsource.switch') for which the hook should be called .. py:method:: _build_blocks() .. py:method:: _build_components() .. py:method:: _build_arguments() .. py:method:: get_multiscanmanager() Get the MultiScanManager of all arguments. .. py:method:: prepare() Prepares components and structure. Called by ARTIQ in the prepare phase, see ARTIQ documentation for more information on experiment phases. .. note:: If you overwrite this method in your experiment, make sure to call `super().prepare()`. .. py:method:: _build_core() .. py:method:: _build() .. py:method:: build() Initializes arguments. Called by ARTIQ in the build phase, see ARTIQ documentation for more information on experiment phases. .. note:: If you overwrite this method in your experiment, make sure to call `super().build()` .. py:method:: _prerun_core(reset=False) .. py:method:: _set_identifiers_in_master(identifier, run_id, step_counter) makes an rpc call to set the identifier in the master .. py:method:: chunker(mult_scan, size = 100) Generator to call a kernel with chunks of scan points. .. py:method:: _loop_chunks(chunk_list) Loop over a list of chunks in the host, i.e. iterate over starting kernels holding CHUNKSIZE experiments :param chunks: (list) list of chunks. Each entry is again an iterable with CHUNKSIZE Scanpoint objects inside .. py:method:: _run_init() .. py:method:: run() Run entry point for ARTIQ, see ARTIQ documentation for more information on experiment phases. .. warning:: Do not implement this entry point in your experiment. Use the provided sub-phases (`prerun`, `step`, etc.) More information can be found in the :ref:`phases_chunking` documentation. .. py:method:: _runchunk(points) .. py:method:: terminate() Terminate the running experiment as soon as possible. Normally this means after the current chunk. .. py:method:: prerun() Kernel entry point, run once at the beginning of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prerun_host() Host entry point, run once at the beginning of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postfail() .. py:method:: postfail_host() .. py:method:: postrun() Kernel entry point, run once at the end of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postrun_host() Host entry point, run once at the end of the run phase of an experiment. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prestep(point) Kernel entry point, run before every step. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: poststep(point) Kernel entry point, run after every step. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prechunk(points) Kernel entry point, run once at the beginning of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postchunk(points) Kernel entry point, run once at the end of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: prechunk_host(points) Host entry point, run once at the beginning of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: postchunk_host(points) Host entry point, run once at the end of a chunk. This method can be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: step(point) :abstractmethod: Kernel entry point, for the main experiment sequence code. This method **must** be overloaded by the user. Details can be found in the :ref:`phases_chunking` documentation. .. py:method:: analyze() Entry point for analyzing the results of the experiment. This method may be overloaded by the user to implement the analysis phase of the experiment, for example fitting curves. Splitting this phase from :meth:`run` enables tweaking the analysis algorithm on pre-existing data, and CPU-bound analyses to be run overlapped with the next experiment in a pipelined manner. This method must not interact with the hardware. .. py:attribute:: children :value: [] .. py:attribute:: __in_build :value: True .. py:method:: register_child(child) .. py:method:: call_child_method(method, *args, **kwargs) Calls the named method for each child, if it exists for that child, in the order of registration. :param method: Name of the method to call :type method: str :param args: Tuple of positional arguments to pass to all children :param kwargs: Dict of keyword arguments to pass to all children .. py:method:: get_argument(key, processor, group=None, tooltip=None) Retrieves and returns the value of an argument. This function should only be called from ``build``. :param key: Name of the argument. :param processor: A description of how to process the argument, such as instances of :mod:`~artiq.language.environment.BooleanValue` and :mod:`~artiq.language.environment.NumberValue`. :param group: An optional string that defines what group the argument belongs to, for user interface purposes. :param tooltip: An optional string to describe the argument in more detail, applied as a tooltip to the argument name in the user interface. .. py:method:: setattr_argument(key, processor=None, group=None, tooltip=None) Sets an argument as attribute. The names of the argument and of the attribute are the same. The key is added to the instance's kernel invariants. .. py:method:: interactive(title='') Request arguments from the user interactively. This context manager returns a namespace object on which the method :meth:`~artiq.language.environment.HasEnvironment.setattr_argument` should be called, with the usual semantics. When the context manager terminates, the experiment is blocked and the user is presented with the requested argument widgets. After the user enters values, the experiment is resumed and the namespace contains the values of the arguments. If the interactive arguments request is cancelled, raises :exc:`~artiq.language.environment.CancelledArgsError`. .. py:method:: get_device_db() Returns the full contents of the device database. .. py:method:: get_device(key) Creates and returns a device driver. .. py:method:: setattr_device(key) Sets a device driver as attribute. The names of the device driver and of the attribute are the same. The key is added to the instance's kernel invariants. .. py:method:: set_dataset(key, value, *, unit=None, scale=None, precision=None, broadcast=False, persist=False, archive=True) Sets the contents and handling modes of a dataset. Datasets must be scalars (``bool``, ``int``, ``float`` or NumPy scalar) or NumPy arrays. :param unit: A string representing the unit of the value. :param scale: A numerical factor that is used to adjust the value of the dataset to match the scale or units of the experiment's reference frame when the value is displayed. :param precision: The maximum number of digits to print after the decimal point. Set ``precision=None`` to print as many digits as necessary to uniquely specify the value. Uses IEEE unbiased rounding. :param broadcast: the data is sent in real-time to the master, which dispatches it. :param persist: the master should store the data on-disk. Implies broadcast. :param archive: the data is saved into the local storage of the current run (archived as a HDF5 file). .. py:method:: mutate_dataset(key, index, value) Mutate an existing dataset at the given index (e.g. set a value at a given position in a NumPy array) If the dataset was created in broadcast mode, the modification is immediately transmitted. If the index is a tuple of integers, it is interpreted as ``slice(*index)``. If the index is a tuple of tuples, each sub-tuple is interpreted as ``slice(*sub_tuple)`` (multi-dimensional slicing). .. py:method:: append_to_dataset(key, value) Append a value to a dataset. The target dataset must be a list (i.e. support ``append()``), and must have previously been set from this experiment. The broadcast/persist/archive mode of the given key remains unchanged from when the dataset was last set. Appended values are transmitted efficiently as incremental modifications in broadcast mode. .. py:method:: get_dataset(key, default=NoDefault, archive=True) Returns the contents of a dataset. The local storage is searched first, followed by the master storage (which contains the broadcasted datasets from all experiments) if the key was not found initially. If the dataset does not exist, returns the default value. If no default is provided, raises ``KeyError``. By default, datasets obtained by this method are archived into the output HDF5 file of the experiment. If an archived dataset is requested more than one time or is modified, only the value at the time of the first call is archived. This may impact reproducibility of experiments. :param archive: Set to ``False`` to prevent archival together with the run's results. Default is ``True``. .. py:method:: get_dataset_metadata(key, default=NoDefault) Returns the metadata of a dataset. Returns dictionary with items describing the dataset, including the units, scale and precision. This function is used to get additional information for displaying the dataset. See :meth:`set_dataset` for documentation of metadata items. .. py:method:: setattr_dataset(key, default=NoDefault, archive=True) Sets the contents of a dataset as attribute. The names of the dataset and of the attribute are the same. .. py:method:: set_default_scheduling(priority=None, pipeline_name=None, flush=None) Sets the default scheduling options. This function should only be called from ``build``.