quantify_core.utilities#

experiment_helpers#

Helpers for performing experiments.

compare_snapshots(old_snapshot, new_snapshot)[source]#

Generate a diff between two quantify snapshots, showing which qcodes parameters have changed.

This function only considers changes in numerical values of quantities and ignores type changes, such as numpy.float64 to float, for example.

We also only consider the values of qcodes parameters, and not metadata like timestamps, which always change from snapshot to snapshot.

Parameters:
  • old_snapshot (dict) – The original snapshot to be compared

  • new_snapshot (dict) – The new snapshot to be compared

Return type:

dict

Returns:

: A dictionary summarising the differences between the two snapshots

create_plotmon_from_historical(tuid=None, label='')[source]#

Creates a plotmon using the dataset of the provided experiment denoted by the tuid in the datadir. Loads the data and draws any required figures.

NB Creating a new plotmon can be slow. Consider using PlotMonitor_pyqt.tuids_extra() to visualize dataset in the same plotmon.

Parameters:
  • tuid (Optional[TUID] (default: None)) – the TUID of the experiment.

  • label (str (default: '')) – if the tuid is not provided, as label will be used to search for the latest dataset.

Return type:

PlotMonitor_pyqt

Returns:

: the plotmon

get_all_parents(instr_mod)[source]#

Get a list of all the parent submodules and instruments of a given QCodes instrument, submodule or parameter.

Parameters:

instr_mod (Union[Instrument, InstrumentChannel, Parameter]) – The QCodes instrument, submodule or parameter whose parents we wish to find

Return type:

List

Returns:

: A list of all the parents of that object (and the object itself)

load_settings_onto_instrument(instrument, tuid=None, datadir=None, exception_handling='raise')[source]#

Loads settings from a previous experiment onto a current Instrument, or any of its submodules or parameters. This information is loaded from the ‘snapshot.json’ file in the provided experiment directory.

Parameters:
  • instrument (Union[Instrument, InstrumentChannel, Parameter]) – the Instrument, InstrumentChannel or Parameter to be configured.

  • tuid (TUID) – the TUID of the experiment. If None use latest TUID.

  • datadir (str) – path of the data directory. If None, uses get_datadir() to determine the data directory.

  • exception_handling (Literal[‘raise’, ‘warn’] (default: 'raise')) – desired behaviour if error occurs when trying to get parameter: raise exception or give warning.

Raises:

ValueError – if the provided instrument has no match in the loaded snapshot.

Return type:

None

dataset_examples#

Factories of exemplary and mock datasets to be used for testing and documentation.

mk_2d_dataset_v1(num_amps=10, num_times=100)[source]#

Generates a 2D Quantify dataset (v1).

Parameters:
  • num_amps (int (default: 10)) – Number of x points.

  • num_times (int (default: 100)) – Number of y points.

mk_nested_mc_dataset(num_points=12, flux_bias_min_max=(-0.04, 0.04), resonator_freqs_min_max=(7000000000.0, 7300000000.0), qubit_freqs_min_max=(4500000000.0, 5000000000.0), t1_values_min_max=(2e-05, 5e-05), seed=112233)[source]#

Generates a dataset with dataset references and several coordinates that serve to index the same variables.

Note that the each value for resonator_freqs, qubit_freqs and t1_values would have been extracted from other dataset corresponding to individual experiments with their own dataset.

Parameters:
  • num_points (int (default: 12)) – Number of datapoints to generate (used for all variables/coordinates).

  • flux_bias_min_max (tuple (default: (-0.04, 0.04))) – Range for mock values.

  • resonator_freqs_min_max (tuple (default: (7000000000.0, 7300000000.0))) – Range for mock values.

  • qubit_freqs_min_max (tuple (default: (4500000000.0, 5000000000.0))) – Range for mock values.

  • t1_values_min_max (tuple (default: (2e-05, 5e-05))) – Range for mock random values.

  • seed (Optional[int] (default: 112233)) – Random number generator seed passed to numpy.random.default_rng.

Return type:

Dataset

mk_shots_from_probabilities(probabilities, **kwargs)[source]#

Generates multiple shots for a list of probabilities assuming two states.

Parameters:
  • probabilities (Union[ndarray, list]) – The list/array of the probabilities of one of the states.

  • **kwargs – Keyword arguments passed to mk_iq_shots().

Returns:

: Array containing the shots. Shape: (num_shots, len(probabilities)).

mk_surface7_cyles_dataset(num_cycles=3, **kwargs)[source]#
See also mk_surface7_sched() inlined in the documentation as an example in:

Quantify dataset - advanced examples

Parameters:
  • num_cycles (int (default: 3)) – The number of repeating cycles before the final measurement.

  • **kwargs – Keyword arguments passed to mk_shots_from_probabilities().

Return type:

Dataset

mk_t1_av_dataset(t1_times=None, probabilities=None, **kwargs)[source]#

Generates a dataset with mock data of a T1 experiment for a single qubit.

Parameters:
  • t1_times (Optional[ndarray] (default: None)) – Array with the T1 times corresponding to each probability in probabilities.

  • probabilities (Optional[ndarray] (default: None)) – The probabilities of finding the qubit in the excited state.

  • **kwargs – Keyword arguments passed to mk_iq_shots().

Return type:

Dataset

mk_t1_av_with_cal_dataset(t1_times=None, probabilities=None, **kwargs)[source]#

Generates a dataset with mock data of a T1 experiment for a single qubit including calibration points for the ground and excited states.

Parameters:
  • t1_times (Optional[ndarray] (default: None)) – Array with the T1 times corresponding to each probability in probabilities.

  • probabilities (Optional[ndarray] (default: None)) – The probabilities of finding the qubit in the excited state.

  • **kwargs – Keyword arguments passed to mk_iq_shots().

Return type:

Dataset

mk_t1_shots_dataset(t1_times=None, probabilities=None, **kwargs)[source]#

Generates a dataset with mock data of a T1 experiment for a single qubit including calibration points for the ground and excited states, including all the individual shots (repeated qubit state measurement for the same exact experiment).

Parameters:
  • t1_times (Optional[ndarray] (default: None)) – Array with the T1 times corresponding to each probability in probabilities.

  • probabilities (Optional[ndarray] (default: None)) – The probabilities of finding the qubit in the excited state.

  • **kwargs – Keyword arguments passed to mk_iq_shots().

Return type:

Dataset

mk_t1_traces_dataset(t1_times=None, probabilities=None, **kwargs)[source]#

Generates a dataset with mock data of a T1 experiment for a single qubit including calibration points for the ground and excited states, including all the individual shots (repeated qubit state measurement for the same exact experiment); and including all the signals that had to be digitized to obtain the rest of the data.

Parameters:
  • t1_times (Optional[ndarray] (default: None)) – Array with the T1 times corresponding to each probability in probabilities.

  • probabilities (Optional[ndarray] (default: None)) – The probabilities of finding the qubit in the excited state.

  • **kwargs – Keyword arguments passed to mk_iq_shots().

Return type:

Dataset

mk_two_qubit_chevron_data(rep_num=5, seed=112233)[source]#

Generates data that look similar to a two-qubit Chevron experiment.

Parameters:
  • rep_num (int (default: 5)) – The number of repetitions with noise to generate.

  • seed (Optional[int] (default: 112233)) – Random number generator seed passed to numpy.random.default_rng.

Returns:

amp_values

Amplitude values.

time_values

Time values.

population_q0

Q0 population values.

population_q1

Q1 population values.

mk_two_qubit_chevron_dataset(**kwargs)[source]#

Generates a dataset that look similar to a two-qubit Chevron experiment.

Parameters:

**kwargs – Keyword arguments passed to mk_two_qubit_chevron_data().

Return type:

Dataset

Returns:

: A mock Quantify dataset.

examples_support#

Utilities used for creating examples for docs/tutorials/tests.

mk_cosine_instrument()[source]#

A container of parameters (mock instrument) providing a cosine model.

Return type:

Instrument

mk_dataset_attrs(tuid=<function gen_tuid>, **kwargs)[source]#

A factory of attributes for Quantify dataset.

See QDatasetAttrs for details.

Parameters:
  • tuid (Union[TUID, Callable[[], TUID]] (default: <function gen_tuid at 0x7aef1b1423a0>)) – If no tuid is provided a new one will be generated. See also tuid.

  • **kwargs – Any other items used to update the output dictionary.

Return type:

Dict[str, Any]

mk_iq_shots(num_shots=128, sigmas=(0.1, 0.1), centers=(-0.2 + 0.65j, 0.7 + 4j), probabilities=(0.4, 0.6), seed=112233)[source]#

Generate clusters of (I + 1j*Q) points with a Gaussian distribution.

Utility to mock the data coming from qubit readout experiments. Clusters are centered around centers and data points are distributed between them according to probabilities.

Parameters:
  • num_shots (int (default: 128)) – The number of shot to generate.

  • sigma – The sigma of the Gaussian distribution used for both real and imaginary parts.

  • centers (Union[Tuple[complex], ndarray[Any, dtype[complex128]]] (default: ((-0.2+0.65j), (0.7+4j)))) – The center of each cluster on the imaginary plane.

  • probabilities (Union[Tuple[float], ndarray[Any, dtype[float64]]] (default: (0.4, 0.6))) – The probabilities of each cluster being randomly selected for each shot.

  • seed (Optional[int] (default: 112233)) – Random number generator seed passed to numpy.random.default_rng.

Return type:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

mk_main_coord_attrs(uniformly_spaced=True, is_main_coord=True, **kwargs)[source]#

A factory of attributes for main coordinates.

See QCoordAttrs for details.

Parameters:
Return type:

Dict[str, Any]

mk_main_var_attrs(grid=True, uniformly_spaced=True, is_main_var=True, has_repetitions=False, **kwargs)[source]#

A factory of attributes for main variables.

See QVarAttrs for details.

Parameters:
Return type:

Dict[str, Any]

mk_secondary_coord_attrs(uniformly_spaced=True, is_main_coord=False, **kwargs)[source]#

A factory of attributes for secondary coordinates.

See QCoordAttrs for details.

Parameters:
Return type:

Dict[str, Any]

mk_secondary_var_attrs(grid=True, uniformly_spaced=True, is_main_var=False, has_repetitions=False, **kwargs)[source]#

A factory of attributes for secondary variables.

See QVarAttrs for details.

Parameters:
Return type:

Dict[str, Any]

mk_trace_for_iq_shot(iq_point, time_values=None, intermediate_freq=50000000.0)[source]#

Generates mock “traces” that a physical instrument would digitize for the readout of a transmon qubit when using a down-converting IQ mixer.

Parameters:
  • iq_point (complex) – A complex number representing a point on the IQ-plane.

  • time_values (Optional[ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]] (default: None)) – The time instants at which the mock intermediate-frequency signal is sampled.

  • intermediate_freq (float (default: 50000000.0)) – The intermediate frequency used in the down-conversion scheme.

Return type:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

Returns:

: An array of complex numbers.

mk_trace_time(sampling_rate=1000000000.0, duration=3e-07)[source]#

Generates a arange in which the entries correspond to time instants up to duration seconds sampled according to sampling_rate in Hz.

See mk_trace_for_iq_shot() for an usage example.

Parameters:
  • sampling_rate (float (default: 1000000000.0)) – The sampling rate in Hz.

  • duration (float (default: 3e-07)) – Total duration in seconds.

Return type:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]

Returns:

: An array with the time instants.

round_trip_dataset(dataset)[source]#

Writes a dataset to disk and loads it back returning it.

Return type:

Dataset

deprecation#

Utilities used to maintain deprecation and reverse-compatibility of the code.

_find_stack_level()[source]#

Find the first place in the stack that is not inside quantify-core (tests notwithstanding).

(adopted from pandas.util._exceptions.find_stack_level)

Return type:

int

deprecated(drop_version, message_or_alias)[source]#

A decorator for deprecating classes and methods.

For each deprecation we must provide a version when this function or class will be removed completely and an instruction to a user about how to port their existing code to a new software version. This is easily done using this decorator.

If callable is passed instead of a message, this decorator assumes that the function or class has moved to another module and generates the standard instruction to use a new function or class. There is no need to re-implement the function logic in two places, since the implementation of new function or class is used in both new and old aliases.

Parameters:
  • drop_version (str) – A version of the package when the deprecated function or class will be dropped.

  • message_or_alias (Union[str, Callable]) – Either an instruction about how to port the software to a new version without the usage of deprecated calls (string), or the new drop-in replacement to the deprecated class or function (callable).

Return type:

Callable[[Callable], Callable]