Skip to content

laboneq.workflow.tasks.run_experiment

This module provides a task to run a compiled experiment in a session.

ErrorList: TypeAlias = list[tuple[list[int], str, str]] module-attribute

AcquiredResult() dataclass

This class represents the results acquired for a single result handle.

The acquired result consists of actual data, axis name(s) and one or more axes, and resembles the structure of a LabOne Q result with the same name.

Attributes:

Name Type Description
data ArrayLike

A multidimensional numpy array, where each dimension corresponds to a sweep loop nesting level, the outermost sweep being the first dimension.

axis_name list[str | list[str]]

A list of axis names. Each element may be either a string or a list of strings.

axis list[ArrayLike | list[ArrayLike]]

A list of axis grids. Each element may be either a 1D numpy array or a list of such arrays.

RunExperimentOptions

Bases: TaskOptions

Options for the run_experiment task.

Attributes:

Name Type Description
return_legacy_results bool

Whether to return an instance of the LabOne Q Results instead of an instance of RunExperimentResults. Default: False.

return_legacy_results: bool = workflow.option_field(False, description='Whether to return an instance of the LabOne Q Results instead of an instance of RunExperimentResults.') class-attribute instance-attribute

RunExperimentResults(data, neartime_callbacks=None, errors=None)

Bases: AttributeWrapper

The results of running an experiment.

The results are accessible via dot notation, where the levels are separated by slashes in the handle.

Example:

acquired = AcquiredResult(
    data=numpy.array([1, 2, 3]),
    axis_name=["Amplitude"],
    axis=[numpy.array([0, 1, 2])],
)
results = RunExperimentResults(data={"cal_trace/q0/g": acquired})
assert results.cal_trace.q0.g is acquired
assert list(results.cal_trace.q0.keys()) == ["g"]

Attributes:

Name Type Description
data

The extracted sweep results from the experiment. The keys are the acquisition handles.

neartime_callbacks AttributeWrapper

The results of the near-time user callbacks. The keys are the names of the near-time callback functions. The values are the list of results in execution order.

errors ErrorList

The errors that occurred during running the experiment. Each item in the list is a tuple of (sweep indices, realt-time section uid, error message).

errors: ErrorList property

The errors that occurred during running the experiment.

neartime_callbacks: AttributeWrapper property

The results of the near-time user callbacks.

extract_results(results)

Extract the results from the LabOne Q results.

Parameters:

Name Type Description Default
results Results | None

The LabOne Q results to extract the results from.

required

Returns:

Type Description
RunExperimentResults

The extracted results.

Example
from laboneq_library.tasks.run_experiment import extract_results

laboneq_results = session.run(compiled_experiment)
extracted_results = extract_results(laboneq_results)

run_experiment(session, compiled_experiment, *, options=None)

Run the compiled experiment on the quantum processor via the specified session.

Parameters:

Name Type Description Default
session Session

The connected session to use for running the experiment.

required
compiled_experiment CompiledExperiment

The compiled experiment to run.

required
options RunExperimentOptions | None

The options for this task as an instance of [RunExperimentOptions].

None

Returns:

Type Description
RunExperimentResults | Results

The measurement results as ... ... the LabOne Q Results class (returned from Session.run()) if return_raw_results is True. ... an instance of RunExperimentResults if return_raw_results is False.