Skip to content

laboneq_applications.core.validation

Utilities for the LabOne Q Applications library.

convert_qubits_sweeps_to_lists(qubits, sweep_points=None)

Convert the qubits and sweep points to lists.

Check for the following conditions
  • qubits must be a QuantumElement or a sequence of QuantumElement.
  • All elements of sweep points must be lists of numbers or arrays.

If single qubit is passed, convert it and the sweep points to a list (if sweep points is not None). If the conditions are met, return the qubits and sweep points.

Parameters:

Name Type Description Default
qubits QuantumElement | Sequence[QuantumElement]

Either a single QuantumElement or a list of QuantumElement.

required
sweep_points Sequence[float] | Sequence[Sequence[float] | ndarray] | ndarray | None

The sweep points for each qubit. If qubits is a single QuantumElement, sweep_points must be a list of numbers or an array. Otherwise it must be a list of lists of numbers or arrays. The sweep_points can also be None, in which case the function returns the validated and converted qubits

None

Returns:

Type Description
tuple[Sequence[QuantumElement], Sequence[Sequence[float] | ndarray] | ndarray] | Sequence[QuantumElement]

A tuple containing the validated qubits and sweep points or only the validated

tuple[Sequence[QuantumElement], Sequence[Sequence[float] | ndarray] | ndarray] | Sequence[QuantumElement]

and converted qubits if sweep_points is None.

Raises:

Type Description
ValueError

If the conditions are not met.

validate_and_convert_qubits_sweeps(qubits, sweep_points=None)

Validate and convert the qubits and sweep points.

Validates the length of the qubits and sweep points by calling validate_length_qubits_sweeps. See docstring there for details.

Then converts the qubits and sweep points to lists. by calling convert_qubits_sweeps_to_lists. See docstring there for details.

Returns:

Type Description
tuple[Sequence[QuantumElement], Sequence[Sequence[float] | ndarray] | ndarray] | Sequence[QuantumElement]

A tuple containing the validated qubits and sweep points or only the validated

tuple[Sequence[QuantumElement], Sequence[Sequence[float] | ndarray] | ndarray] | Sequence[QuantumElement]

and converted qubits if sweep_points is None.

validate_and_convert_single_qubit_sweeps(qubits, sweep_points=None)

Converts and validates qubits, sweep points and the experiment result.

Check for the following conditions
  • type of qubits must be QuantumElement or a subclass of it.
  • sweep_points is a list or array with all its elements lists of numbers or arrays (see validate_and_convert_sweeps_to_arrays)
  • the length of qubits and sweep_points is the same (see validate_length_qubits_sweeps)

If sweep_points was a list of numbers, sweep_points is converted into a numpy array. If sweep_points was a list of lists of numbers, every elements in sweep_points is converted into a numpy array (see validate_and_convert_sweeps_to_arrays).

Parameters:

Name Type Description Default
qubits QuantumElement | Sequence[QuantumElement]

Either a single QuantumElement or a list of QuantumElement.

required
sweep_points Sequence[float] | Sequence[Sequence[float] | ndarray] | ndarray | None

The sweep points for each qubit.

None

Returns:

Type Description
tuple[QuantumElement, Sequence[float] | ndarray] | QuantumElement

A tuple containing the validated qubits and sweep points or only the validated

tuple[QuantumElement, Sequence[float] | ndarray] | QuantumElement

and converted qubits if sweep_points is None.

validate_and_convert_sweeps_to_arrays(sweep_points)

Convert sweep_points into numpy arrays.

Check for the following conditions
  • sweep_points must be a list or an array
  • All elements of sweep points must be lists of numbers or arrays.

Parameters:

Name Type Description Default
sweep_points Sequence[float] | Sequence[Sequence[float] | ndarray] | ndarray

The sweep points to be converted into numpy arrays.

required

Returns:

Type Description
Sequence[Sequence[float] | ndarray] | ndarray

The sweep points as a numpy array if sweep_points was a list of numbers, or

Sequence[Sequence[float] | ndarray] | ndarray

as a list of numpy arrays, if sweep_points was a list of lists of numbers.

Raises:

Type Description
ValueError

If the conditions are not met.

validate_length_qubits_sweeps(qubits, sweep_points=None)

Validate the length of the qubits and sweep points.

Check for the following conditions
  • qubits must be a QuantumElement or a sequence of QuantumElement.
  • If a single qubit is passed, the sweep points must be a list or array of numbers.
  • Length of qubits and sweep points must be the same.
  • All elements of sweep points must be lists of numbers or arrays.

If the conditions are met, return the qubits and sweep points.

Parameters:

Name Type Description Default
qubits QuantumElement | Sequence[QuantumElement]

Either a single QuantumElement or a list of QuantumElement.

required
sweep_points Sequence[float] | Sequence[Sequence[float] | ndarray] | ndarray | None

The sweep points for each qubit. If qubits is a single QuantumElement, sweep_points must be a list of numbers or an array. Otherwise it must be a list of lists of numbers or arrays. The sweep_points can also be None, in which case the function returns the validated qubits

None

Returns:

Type Description
tuple[Sequence[QuantumElement], Sequence[Sequence[float] | ndarray] | ndarray] | Sequence[QuantumElement]

A tuple containing the validated qubits and sweep points or only the validated

tuple[Sequence[QuantumElement], Sequence[Sequence[float] | ndarray] | ndarray] | Sequence[QuantumElement]

qubits if sweep_points is None.

Raises:

Type Description
ValueError

If the conditions are not met.

validate_result(result)

Checks that result is an instance of RunExperimentResults.

Parameters:

Name Type Description Default
result RunExperimentResults

the acquired results

required

Raises:

Type Description
TypeError

If result is not an instance of RunExperimentResults.