Skip to content

laboneq_applications.analysis.iq_blobs

This module defines the analysis for an IQ-blob experiment.

The experiment is defined in laboneq_applications.experiments.

In this analysis, we collect the single shots acquire for each prepared stated and then use LinearDiscriminantAnalysis from the sklearn library to classify the data into the prepared states. From this classification, we calculate the correct-state-assignment matrix and the correct-state-assignment fidelity. Finally, we plot the single shots for each prepared state and the correct-state-assignment matrix.

IQBlobAnalysisOptions

Option class for the tasks in the iq-blob analysis workflows.

Attributes:

Name Type Description
save_figures bool

Whether to save the figures. Default: True.

close_figures bool

Whether to close the figures. Default: True.

close_figures: bool = workflow.option_field(True, description='Whether to close the figures.') class-attribute instance-attribute

save_figures: bool = workflow.option_field(True, description='Whether to save the figures.') class-attribute instance-attribute

IQBlobAnalysisWorkflowOptions

Option class for IQ-blob analysis workflows.

Attributes:

Name Type Description
do_fitting bool

Whether to perform the fit. Default: True.

do_plotting bool

Whether to create plots. Default: 'True'.

do_plotting_iq_blobs bool

Whether to create the IQ-blob plots of the single shots. Default: 'True'.

do_plotting_assignment_matrices bool

Whether to create the assignment matrix plots. Default: 'True'.

do_fitting: bool = workflow.option_field(True, description='Whether to perform the fit.') class-attribute instance-attribute

do_plotting: bool = workflow.option_field(True, description='Whether to create plots.') class-attribute instance-attribute

do_plotting_assignment_matrices: bool = workflow.option_field(True, description='Whether to create the assignment matrix plots.') class-attribute instance-attribute

do_plotting_iq_blobs: bool = workflow.option_field(True, description='Whether to create the IQ-blob plots of the single shots.') class-attribute instance-attribute

analysis_workflow(result, qubits, states, options=None)

The IQ Blobs analysis Workflow.

The workflow consists of the following steps:

Parameters:

Name Type Description Default
result RunExperimentResults

The experiment results returned by the run_experiment task.

required
qubits Qubits

The qubits on which to run the analysis. May be either a single qubit or a list of qubits. The UIDs of these qubits must exist in the result.

required
states Sequence[str]

The basis states the qubits should be prepared in. May be either a string, e.g. "gef", or a list of letters, e.g. ["g","e","f"].

required
options IQBlobAnalysisWorkflowOptions | None

The options for building the workflow as an instance of [IQBlobAnalysisWorkflowOptions]. See the docstring of this class for more details.

None

Returns:

Name Type Description
WorkflowBuilder None

The builder for the analysis workflow.

Example
result = analysis_workflow(
    results=results
    qubits=[q0, q1],
    amplitudes=[
        np.linspace(0, 1, 11),
        np.linspace(0, 0.75, 11),
    ],
    options=analysis_workflow.options(),
).run()

calculate_assignment_fidelities(qubits, assignment_matrices)

Calculate the correct assignment fidelity from the correct assignment matrices.

Parameters:

Name Type Description Default
qubits Qubits

The qubits on which to run the analysis. May be either a single qubit or a list of qubits. The UIDs of these qubits must exist in the assignment_matrices.

required
assignment_matrices dict[str, None]

the dictionary of assignment matrices returned by calculate_assignment_matrices.

required

Returns:

Type Description
dict[str, float]

dict with qubit UIDs as keys and the assignment fidelity for each qubit as keys.

calculate_assignment_matrices(qubits, processed_data_dict, fit_results)

Calculate the correct assignment matrices from the result of the classification.

Parameters:

Name Type Description Default
qubits Qubits

The qubits on which to run the analysis. May be either a single qubit or a list of qubits. The UIDs of these qubits must exist in the processed_data_dict.

required
processed_data_dict dict[str, dict[str, ArrayLike | dict]]

the processed data dictionary returned by collect_shots

required
fit_results dict[str, None] | dict

the classification fit results returned by fit_data.

required

Returns:

Type Description
dict[str, None]

dict with qubit UIDs as keys and the assignment matrix for each qubit as keys.

collect_shots(qubits, result, states)

Collect the single shots acquired for each preparation state in states.

Parameters:

Name Type Description Default
qubits Qubits

The qubits on which to run the analysis. May be either a single qubit or a list of qubits. The UIDs of these qubits must exist in result.

required
result RunExperimentResults

The experiment results returned by the run_experiment task.

required
states Sequence[str]

The basis states the qubits should be prepared in. May be either a string, e.g. "gef", or a list of letters, e.g. ["g","e","f"].

required

Returns:

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

dict with qubit UIDs as keys and values as a dict with the following keys: shots_per_state - dict with states as keys and raw single shots as values. shots_combined - list of the real and imaginary part of the shots in shots_per_state, in a form expected by LinearDiscriminantAnalysis. ideal_states_shots - list of the same shape as shots_combined with ints specifying the state (0, 1, 2) the qubit is expected to be found in ideally for each shot.

fit_data(qubits, processed_data_dict)

Perform a classification of the shots using LinearDiscriminantAnalysis.

Parameters:

Name Type Description Default
qubits Qubits

The qubits on which to run the analysis. May be either a single qubit or a list of qubits. The UIDs of these qubits must exist in the processed_data_dict.

required
processed_data_dict dict[str, dict[str, ArrayLike | dict]]

the processed data dictionary returned by collect_shots

required

Returns:

Type Description
dict | dict[str, None]

dict with qubit UIDs as keys and the classification result for each qubit as

dict | dict[str, None]

keys.

plot_assignment_matrices(qubits, states, assignment_matrices, assignment_fidelities, options=None)

Create the correct-assignment-matrices plots.

Parameters:

Name Type Description Default
qubits Qubits

The qubits on which to run the analysis. May be either a single qubit or a list of qubits. The UIDs of these qubits must exist in assignment_matrices and assignment_fidelities.

required
states Sequence[str]

The basis states the qubits should be prepared in. May be either a string, e.g. "gef", or a list of letters, e.g. ["g","e","f"].

required
assignment_matrices dict[str, ArrayLike]

the dictionary of assignment matrices returned by calculate_assignment_matrices.

required
assignment_fidelities dict[str, float]

the dictionary of assignment fidelities returned by calculate_assignment_matrices.

required
options IQBlobAnalysisOptions | None

The options for building the workflow as an instance of [IQBlobAnalysisOptions]. See the docstring of this class for more details.

None

Returns:

Type Description
dict[str, Figure]

dict with qubit UIDs as keys and the figures for each qubit as values.

plot_iq_blobs(qubits, states, processed_data_dict, fit_results, options=None)

Create the IQ-blobs plots.

Parameters:

Name Type Description Default
qubits Qubits

The qubits on which to run the analysis. May be either a single qubit or a list of qubits. The UIDs of these qubits must exist in processed_data_dict and fit_results.

required
states Sequence[str]

The basis states the qubits should be prepared in. May be either a string, e.g. "gef", or a list of letters, e.g. ["g","e","f"].

required
processed_data_dict dict[str, dict[str, ArrayLike | dict]]

the processed data dictionary returned by collect_shots.

required
fit_results dict[str, None] | None

the classification fit results returned by fit_data.

required
options IQBlobAnalysisOptions | None

The options for building the workflow as an instance of [IQBlobAnalysisOptions]. See the docstring of this class for more details.

None

Returns:

Type Description
dict[str, Figure]

dict with qubit UIDs as keys and the figures for each qubit as values.

dict[str, Figure]

If a qubit uid is not found in fit_results, the fit is not plotted.