Skip to content

laboneq_applications.analysis.calibration_traces_rotation

This module contains functions for rotating raw experiment data.

The raw data needs to be translated into qubit populations. This is done either by using principal-component analysis or rotating and projecting the data along the line in the complex plane given by data obtained from calibration traces. The latter is obtained by measuring the qubit after preparing it in a known state, for instance g, e, or f.

CalculateQubitPopulationOptions

Options for the calculate_qubit_population task.

Attributes:

Name Type Description
do_rotation bool

Whether to rotate the raw data based on calibration traces or principal component analysis. Default: True.

do_pca bool

Whether to perform principal component analysis on the raw data independent of whether there were calibration traces in the experiment. Default: False.

use_cal_traces bool

Whether to include calibration traces in the experiment. Default: True.

cal_states str | tuple

The states to prepare in the calibration traces. Can be any string or tuple made from combining the characters 'g', 'e', 'f'. Default: same as transition

calculate_population_1d(raw_data, sweep_points, calibration_traces=None, *, do_pca=False)

Rotate and project 1D data.

The data is projected along the line between the points in the calibration traces.

Parameters:

Name Type Description Default
raw_data ArrayLike

array of complex data corresponding to the results of an integrated average result, usually of dimension (nr_sweep_points, 1).

required
sweep_points ArrayLike

Sweep points of the acquisition.

required
calibration_traces list[ArrayLike | complex] | None

A list with two entries of the complex data corresponding to the calibration traces, from the lowest transmon state to the highest.

None
do_pca bool

whether to do principal component analysis on the data. If False, the data will be rotated along the line in the complex plane between the two calibration points and then projected onto it.

False

Returns:

Type Description
dict

A dictionary with the following keys:

  • sweep_points: the sweep points.
  • sweep_points_with_cal_traces: the sweep points extended with as many points as there are calibration traces.
  • sweep_points_cal_traces: the sweep points added for the calibration traces.
  • data_raw: the raw data.
  • data_raw_with_cal_traces: the raw data with the calibration traces appended.
  • data_raw_cal_traces: the raw data of the calibration traces.
  • population: the rotated data.
  • population_with_cal_traces: the rotated data with the rotated calibration traces appended.
  • population_cal_traces: the rotated calibration traces.
  • num_cal_traces: the number of calibration traces.

calculate_population_2d(raw_data, sweep_points_1d, sweep_points_2d, calibration_traces=None, *, do_pca=False)

Rotate and project 2D data.

The data is projected along the line between the points in the calibration traces.

Parameters:

Name Type Description Default
raw_data ArrayLike

array of complex data corresponding to the results of an integrated average result, usually of dimension (nr_sweep_points, 1).

required
sweep_points_1d ArrayLike

The sweep points corresponding to the innermost sweep.

required
sweep_points_2d ArrayLike

The sweep points corresponding to the outermost sweep.

required
calibration_traces list[ArrayLike | complex] | None

A list with the complex data corresponding to the calibration traces, from the lowest transmon state to the highest. Can be a list of numbers or arrays with the list having as many entries as there are calibration states.

None
do_pca bool

whether to do principal component analysis on the data. If False, the data will be rotated along the line in the complex plane between the two calibration points and then projected onto it.

False

Returns:

Type Description
dict

A dictionary with the following keys:

  • sweep_points_1d: the sweep points of the innermost sweep.
  • sweep_points_1d_with_cal_traces: the innermost sweep points extended with as many points as there are calibration traces.
  • sweep_points_1d_cal_traces: the innermost sweep points added for the calibration traces.
  • sweep_points_2d: the sweep points of the outermost sweep.
  • data_raw: the raw data.
  • data_raw_with_cal_traces: the raw data with the calibration traces appended.
  • data_raw_cal_traces: the raw data of the calibration traces.
  • population: the rotated data.
  • population_with_cal_traces: the rotated data with the rotated calibration traces appended.
  • population_cal_traces: the rotated calibration traces.
  • num_cal_traces: the number of calibration traces.

calculate_qubit_population(qubits, result, sweep_points, options=None)

Calculates the qubit population from the raw data.

The data is processed in the following way:

  • If calibration traces were used in the experiment, the raw data is rotated based on the calibration traces. See rotate_data_to_cal_trace_results for more details.
  • If no calibration traces were used in the experiment, or do_pca = True is passed in options, principal-component analysis is performed on the data. See principal_component_analysis for more details.

Parameters:

Name Type Description Default
qubits QuantumElements

The qubits on which the amplitude-Rabi experiments was run. May be either a single qubit or a list of qubits.

required
result RunExperimentResults

the result of the experiment, returned by the run_experiment task.

required
sweep_points QubitSweepPoints

The sweep points used in the experiment for each qubit. If qubits is a single qubit, sweep_points must be an array. Otherwise, it must be a list of arrays.

required
options CalculateQubitPopulationOptions | None

The options for building the workflow as an instance of CalculateQubitPopulationOptions. See the docstrings of this class for more details.

None

Returns:

Type Description
dict[str, dict[str, ArrayLike]]

dict with qubit UIDs as keys and the dictionary of processed data for each qubit as values. See calculate_population_1d for what this dictionary looks like.

Raises:

Type Description
TypeError

If result is not an instance of RunExperimentResults.

ValueError

If the qubits and sweeps have incompatible shapes.

calculate_qubit_population_2d(qubits, result, sweep_points_1d, sweep_points_2d, options=None, result_handle='')

Calculates the qubit population from the raw data.

The data is processed in the following way:

  • If calibration traces were used in the experiment, the raw data is rotated based on the calibration traces. See rotate_data_to_cal_trace_results for more details.
  • If no calibration traces were used in the experiment, or do_pca = True is passed in options, principal-component analysis is performed on the data. See principal_component_analysis for more details.

Parameters:

Name Type Description Default
qubits QuantumElements

The qubits on which the amplitude-Rabi experiments was run. May be either a single qubit or a list of qubits.

required
result RunExperimentResults

the result of the experiment, returned by the run_experiment task.

required
sweep_points_1d QubitSweepPoints

The sweep points corresponding to the innermost sweep. If qubits is a single qubit, sweep_points must be an array. Otherwise, it must be a list of arrays.

required
sweep_points_2d QubitSweepPoints

The sweep points corresponding to the outermost sweep. If qubits is a single qubit, sweep_points must be an array. Otherwise, it must be a list of arrays.

required
options CalculateQubitPopulationOptions | None

The options for building the workflow as an instance of CalculateQubitPopulationOptions. See the docstrings of this class for more details.

None
result_handle str

An optional suffix appended to the qubit UID when looking up the result handle, e.g. "_0" or "_1" for experiments that store multiple measurement outcomes per qubit under distinct handles. Defaults to "".

''

Returns:

Type Description
dict[str, dict[str, ArrayLike]]

dict with qubit UIDs as keys and the dictionary of processed data for each qubit as values. See calculate_population_1d for what this dictionary looks like.

Raises:

Type Description
TypeError

If result is not an instance of RunExperimentResults.

ValueError

If the qubits and sweeps have incompatible shapes.

calculate_rotation_matrix(delta_i, delta_q)

Calculates the matrix that rotates the data to lie along the Q-axis.

Input can be either the I and Q coordinates of the zero cal_point or the difference between the 1 and 0 cal points.

Parameters:

Name Type Description Default
delta_i float | ArrayLike

difference between the real parts of the first and second cal-state data, usually of dimension (nr_sweep_points, 1).

required
delta_q float | ArrayLike

difference between the imaginary parts of the first and second cal-state data, usually of dimension (nr_sweep_points, 1).

required

Returns:

Type Description
NDArray[float64]

the 2x2 rotation matrix as a numpy array

extract_raw_data_dict(raw_data, sweep_points, calibration_traces=None)

Extract the raw data information.

Parameters:

Name Type Description Default
raw_data ArrayLike

array of complex data corresponding to the results of an integrated average result, usually of dimension (nr_sweep_points, 1).

required
sweep_points ArrayLike

Sweep points of the acquisition.

required
calibration_traces list[ArrayLike | complex] | None

A list with two entries of the complex data corresponding to the calibration traces, from the lowest transmon state to the highest.

None

Returns:

Type Description
dict

A dictionary with the following keys:

  • sweep_points: the sweep points.
  • sweep_points_with_cal_traces: the sweep points extended with as many points as there are calibration traces.
  • sweep_points_cal_traces: the sweep points added for the calibration traces.
  • data_raw: the raw data.
  • data_raw_with_cal_traces: the raw data with the calibration traces appended.
  • data_raw_cal_traces: the raw data of the calibration traces.

principal_component_analysis(raw_data)

Rotates and projects 1D data using principal component analysis (PCA).

Parameters:

Name Type Description Default
raw_data ArrayLike

Array of complex data corresponding to the results of an integrated average result, usually of dimension (nr_sweep_points, 1).

required

Returns:

Type Description
ArrayLike

data array after PCA with the same dimension as raw_data.

rotate_data_to_cal_trace_results(raw_data, raw_data_cal_pt_0, raw_data_cal_pt_1)

Rotates and projects the raw data.

The raw data is projected onto the line in the IQ plane between two calibration points, then normalized to the distance in the IQ plane between the two calibration points. The calibration points are the results of preparing two transmon states.

If more than one calibration point per state (i.e. len(raw_data_cal_pt_0) > 1), the mean of the cal points will be taken.

Parameters:

Name Type Description Default
raw_data ArrayLike

array of complex data corresponding to the results of an integrated average result, usually of dimension (nr_sweep_points, 1).

required
raw_data_cal_pt_0 ArrayLike | complex

array of complex data or a single complex number corresponding to the data recorded when the qubit is prepared in the first calibration state. "First" here means the lowest transmon state. For example, g if the cal traces measured were g and e or g and f; e if the cal traces measured were e an f

required
raw_data_cal_pt_1 ArrayLike | complex

array of complex data or a single complex number corresponding to the data recorded when the qubit is prepared in the second calibration state. "Second" here means the highest transmon state. For example, e if the cal traces measured were g and e; f if the cal traces measured were g and f or e an f

required

Returns:

Type Description
ArrayLike

rotated, projected, and normalized real-data array with the same dimension as raw_data.