helpers ======= .. py:module:: quantify_scheduler.backends.qblox.helpers .. autoapi-nested-parse:: Helper functions for Qblox backend. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: quantify_scheduler.backends.qblox.helpers.Frequencies Functions ~~~~~~~~~ .. autoapisummary:: quantify_scheduler.backends.qblox.helpers.generate_waveform_data quantify_scheduler.backends.qblox.helpers.generate_waveform_names_from_uuid quantify_scheduler.backends.qblox.helpers.generate_uuid_from_wf_data quantify_scheduler.backends.qblox.helpers.add_to_wf_dict_if_unique quantify_scheduler.backends.qblox.helpers.output_name_to_output_indices quantify_scheduler.backends.qblox.helpers.input_name_to_input_indices quantify_scheduler.backends.qblox.helpers.get_io_info quantify_scheduler.backends.qblox.helpers.generate_waveform_dict quantify_scheduler.backends.qblox.helpers.to_grid_time quantify_scheduler.backends.qblox.helpers.is_multiple_of_grid_time quantify_scheduler.backends.qblox.helpers.is_within_half_grid_time quantify_scheduler.backends.qblox.helpers.get_nco_phase_arguments quantify_scheduler.backends.qblox.helpers.get_nco_set_frequency_arguments quantify_scheduler.backends.qblox.helpers.determine_clock_lo_interm_freqs quantify_scheduler.backends.qblox.helpers.generate_port_clock_to_device_map quantify_scheduler.backends.qblox.helpers.assign_pulse_and_acq_info_to_devices quantify_scheduler.backends.qblox.helpers.convert_hw_config_to_portclock_configs_spec quantify_scheduler.backends.qblox.helpers.calc_from_units_volt quantify_scheduler.backends.qblox.helpers.extract_acquisition_metadata_from_acquisitions quantify_scheduler.backends.qblox.helpers.single_scope_mode_acquisition_raise quantify_scheduler.backends.qblox.helpers.generate_hardware_config .. py:function:: generate_waveform_data(data_dict: dict, sampling_rate: float, duration: Optional[float] = None) -> numpy.ndarray Generates an array using the parameters specified in ``data_dict``. :param data_dict: The dictionary that contains the values needed to parameterize the waveform. ``data_dict['wf_func']`` is then called to calculate the values. :type data_dict: dict :param sampling_rate: The sampling rate used to generate the time axis values. :type sampling_rate: float :param duration: The duration of the waveform in seconds. This parameter can be used if ``data_dict`` does not contain a ``'duration'`` key. By default None. :type duration: float or None, optional :returns: **wf_data** -- The (possibly complex) values of the generated waveform. The number of values is determined by rounding to the nearest integer. :rtype: np.ndarray :raises TypeError: If ``data_dict`` does not contain a ``'duration'`` entry and ``duration is None``. .. py:function:: generate_waveform_names_from_uuid(uuid: Any) -> Tuple[str, str] Generates names for the I and Q parts of the complex waveform based on a unique identifier for the pulse/acquisition. :param uuid: A unique identifier for a pulse/acquisition. :returns: * *uuid_I* -- Name for the I waveform. * *uuid_Q* -- Name for the Q waveform. .. py:function:: generate_uuid_from_wf_data(wf_data: numpy.ndarray, decimals: int = 12) -> str Creates a unique identifier from the waveform data, using a hash. Identical arrays yield identical strings within the same process. :param wf_data: The data to generate the unique id for. :param decimals: The number of decimal places to consider. :returns: A unique identifier. .. py:function:: add_to_wf_dict_if_unique(wf_dict: Dict[str, Any], waveform: numpy.ndarray) -> Tuple[Dict[str, Any], str, int] Adds a waveform to the waveform dictionary if it is not yet in there and returns the uuid and index. If it is already present it simply returns the uuid and index. :param wf_dict: The waveform dict in the format expected by the sequencer. :param waveform: The waveform to add. :returns: * *Dict[str, Any]* -- The (updated) wf_dict. * *str* -- The uuid of the waveform. * *int* -- The index. .. py:function:: output_name_to_output_indices(output_name: str) -> Optional[Union[Tuple[int], Tuple[int, int]]] Return the output indices associated with the output name specified in the hardware config. For the baseband modules, output index 'n' corresponds to physical module output 'n+1'. For RF modules, output indices '0' and '1' (or: '2' and '3') correspond to 'path0' and 'path1' of some sequencer, and both these paths are routed to the **same** physical module output '1' (or: '2'). :param output_name: Hardware config output name (e.g. 'complex_output_0'). :returns: A tuple containing output indices corresponding to certain physical module outputs. .. py:function:: input_name_to_input_indices(input_name: str) -> Union[Tuple[int], Tuple[int, int]] Return the input indices associated with the input name specified in the hardware config. For the baseband modules, input index 'n' corresponds to physical module input 'n+1'. For RF modules, input indices '0' and '1' correspond to 'path0' and 'path1' of some sequencer, and both paths are connected to physical module input '1'. :param input_name: Hardware config input name (e.g. 'complex_input_0'). :returns: A tuple containing input indices corresponding to certain physical module inputs. .. py:function:: get_io_info(io_name: str) -> Tuple[quantify_scheduler.backends.qblox.enums.IoMode, Union[Tuple[int], Tuple[int, int]], Union[Tuple[int], Tuple[int, int]]] Return a "sequencer mode" based on the paths used by the sequencer, as well as the input or output indices associated to the io name the sequencer is supposed to use. Sequencer modes: - :attr:`.IoMode.REAL`: only path0 is used. - :attr:`.IoMode.IMAG`: only path1 is used. - :attr:`.IoMode.COMPLEX`: both path0 and path1 paths are used. - :attr:`.IoMode.DIGITAL`: the digital outputs are used. :param io_name: The io name from the hardware config that the sequencer is supposed to use. :returns: * The sequencer mode * The output indices * The input indices .. py:function:: generate_waveform_dict(waveforms_complex: Dict[str, numpy.ndarray]) -> Dict[str, dict] Takes a dictionary with complex waveforms and generates a new dictionary with real valued waveforms with a unique index, as required by the hardware. :param waveforms_complex: Dictionary containing the complex waveforms. Keys correspond to a unique identifier, value is the complex waveform. :returns: A dictionary with as key the unique name for that waveform, as value another dictionary containing the real-valued data (list) as well as a unique index. Note that the index of the Q waveform is always the index of the I waveform +1. :rtype: dict[str, dict] .. admonition:: Examples .. jupyter-execute:: import numpy as np from quantify_scheduler.backends.qblox.helpers import generate_waveform_dict complex_waveforms = {12345: np.array([1, 2])} generate_waveform_dict(complex_waveforms) # {'12345_I': {'data': [1, 2], 'index': 0}, # '12345_Q': {'data': [0, 0], 'index': 1}} .. py:function:: to_grid_time(time: float, grid_time_ns: int = constants.GRID_TIME) -> int Convert time value in s to time in ns, and verify that it is aligned with grid time. Takes a float value representing a time in seconds as used by the schedule, and returns the integer valued time in nanoseconds that the sequencer uses. The time value needs to be aligned with grid time, i.e., needs to be a multiple of :data:`~.constants.GRID_TIME`, within a tolerance of 1 picosecond. :param time: A time value in seconds. :param grid_time_ns: The grid time to use in nanoseconds. :returns: The integer valued nanosecond time. :raises ValueError: If `time` is not a multiple of :data:`~.constants.GRID_TIME` within the tolerance. .. py:function:: is_multiple_of_grid_time(time: float, grid_time_ns: int = constants.GRID_TIME) -> bool Determine whether a time value in seconds is a multiple of the grid time. Within a tolerance as defined by :meth:`~quantify_scheduler.backends.qblox.helpers.to_grid_time`. :param time: A time value in seconds. :param grid_time_ns: The grid time to use in nanoseconds. :returns: `True` if `time` is a multiple of the grid time, `False` otherwise. .. py:function:: is_within_half_grid_time(a, b, grid_time_ns: int = constants.GRID_TIME) Determine whether two time values in seconds are within half grid time of each other. :param a: A time value in seconds. :param b: A time value in seconds. :param grid_time_ns: The grid time to use in nanoseconds. :returns: `True` if `a` and `b` are less than half grid time apart, `False` otherwise. .. py:function:: get_nco_phase_arguments(phase_deg: float) -> int Converts a phase in degrees to the int arguments the NCO phase instructions expect. We take `phase_deg` modulo 360 to account for negative phase and phase larger than 360. :param phase_deg: The phase in degrees :returns: The int corresponding to the phase argument. .. py:function:: get_nco_set_frequency_arguments(frequency_hz: float) -> int Converts a frequency in Hz to the int argument the NCO set_freq instruction expects. :param frequency_hz: The frequency in Hz. :returns: The frequency expressed in steps for the NCO set_freq instruction. :raises ValueError: If the frequency_hz is out of range. .. py:class:: Frequencies .. py:attribute:: clock :type: float .. py:attribute:: LO :type: Optional[float] .. py:attribute:: IF :type: Optional[float] .. py:method:: validate() .. py:function:: determine_clock_lo_interm_freqs(freqs: Frequencies, downconverter_freq: Optional[float] = None, mix_lo: bool = True) -> Frequencies From known frequency for the local oscillator or known intermodulation frequency, determine any missing frequency, after optionally applying `downconverter_freq` to the clock frequency. If `mix_lo` is ``True``, the following relation is obeyed: :math:`f_{RF} = f_{LO} + f_{IF}`. If `mix_lo` is ``False``, :math:`f_{RF} = f_{LO}` is upheld. .. warning:: Using `downconverter_freq` requires custom Qblox hardware, do not use otherwise. :param freqs: Frequencies object containing clock, local oscillator (LO) and Intermodulation frequency (IF), the frequency of the numerically controlled oscillator (NCO). :type freqs: Frequencies :param downconverter_freq: Frequency for downconverting the clock frequency, using: :math:`f_\mathrm{out} = f_\mathrm{downconverter} - f_\mathrm{in}`. :type downconverter_freq: Optional[float] :param mix_lo: Flag indicating whether IQ mixing is enabled with the LO. :type mix_lo: bool :returns: :class:`.Frequencies` object containing the determined LO and IF frequencies and the optionally downconverted clock frequency. :Warns: * **RuntimeWarning** -- In case `downconverter_freq` is set equal to 0, warns to unset via ``null``/``None`` instead. * **RuntimeWarning** -- In case LO is overridden to clock due to `mix_lo` being `False` :raises ValueError: In case `downconverter_freq` is less than 0. :raises ValueError: In case `downconverter_freq` is less than `clock_freq`. :raises ValueError: In case `mix_lo` is `True` and neither LO frequency nor IF has been supplied. :raises ValueError: In case `mix_lo` is `True` and both LO frequency and IF have been supplied and do not adhere to :math:`f_{RF} = f_{LO} + f_{IF}`. .. py:function:: generate_port_clock_to_device_map(hardware_cfg: Dict[str, Any]) -> Dict[Tuple[str, str], str] Generates a mapping that specifies which port-clock combinations belong to which device. Here, device means a top-level entry in the hardware config, e.g. a Cluster, not which module within the Cluster. Each port-clock combination may only occur once. :param hardware_cfg: The hardware config dictionary. :returns: A dictionary with as key a tuple representing a port-clock combination, and as value the name of the device. Note that multiple port-clocks may point to the same device. :raises ValueError: If a port-clock combination occurs multiple times in the hardware configuration. .. py:function:: assign_pulse_and_acq_info_to_devices(schedule: quantify_scheduler.Schedule, device_compilers: Dict[str, Any], hardware_cfg: Dict[str, Any]) Traverses the schedule and generates `OpInfo` objects for every pulse and acquisition, and assigns it to the correct `InstrumentCompiler`. :param schedule: The schedule to extract the pulse and acquisition info from. :param device_compilers: Dictionary containing InstrumentCompilers as values and their names as keys. :param hardware_cfg: The hardware config dictionary. :raises RuntimeError: This exception is raised then the function encountered an operation that has no pulse or acquisition info assigned to it. :raises KeyError: This exception is raised when attempting to assign a pulse with a port-clock combination that is not defined in the hardware configuration. :raises KeyError: This exception is raised when attempting to assign an acquisition with a port-clock combination that is not defined in the hardware configuration. .. py:function:: convert_hw_config_to_portclock_configs_spec(hw_config: Dict[str, Any]) -> Dict[str, Any] Converts possibly old hardware configs to the new format introduced by the new dynamic sequencer allocation feature. Manual assignment between sequencers and port-clock combinations under each output is removed, and instead only a list of port-clock configurations is specified, under the new ``"portclock_configs"`` key. Furthermore, we scan for ``"latency_correction"`` defined at sequencer or portclock_configs level and store under ``"port:clock"`` under toplevel ``"latency_corrections"`` key. :param hw_config: The hardware config to be upgraded to the new specification. :returns: A hardware config compatible with the specification required by the new dynamic sequencer allocation feature. .. py:function:: calc_from_units_volt(voltage_range, name: str, param_name: str, cfg: Dict[str, Any]) -> Optional[float] Helper method to calculate the offset from mV or V. Then compares to given voltage range, and throws a ValueError if out of bounds. :param voltage_range: The range of the voltage levels of the device used. :param name: The name of the device used. :param param_name: The name of the current parameter the method is used for. :param cfg: The hardware config of the device used. :returns: The normalized offsets. :raises RuntimeError: When a unit range is given that is not supported, or a value is given that falls outside the allowed range. .. py:function:: extract_acquisition_metadata_from_acquisitions(acquisitions: List[quantify_scheduler.backends.types.qblox.OpInfo], repetitions: int) -> quantify_scheduler.schedules.schedule.AcquisitionMetadata Variant of :func:`~quantify_scheduler.helpers.schedule.extract_acquisition_metadata_from_acquisition_protocols` for use with the Qblox backend. .. py:function:: single_scope_mode_acquisition_raise(sequencer_0, sequencer_1, module_name) Raises an error stating that only one scope mode acquisition can be used per module. :param sequencer_0: First sequencer which attempts to use the scope mode acquisition. :param sequencer_1: Second sequencer which attempts to use the scope mode acquisition. :param module_name: Name of the module. :raises ValueError: Always raises the error message. .. py:function:: generate_hardware_config(compilation_config: quantify_scheduler.backends.graph_compilation.CompilationConfig) Extract the old-style Qblox hardware config from the CompilationConfig. :param config: CompilationConfig from which hardware config is extracted. :type config: CompilationConfig :returns: **hardware_config** -- Qblox hardware configuration. :rtype: dict :raises KeyError: If the CompilationConfig.connectivity does not contain a hardware config. :raises ValueError: If a value is specified in both the hardware options and the hardware config. :raises RuntimeError: If no external local oscillator is found in the generated Qblox hardware configuration.