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_and_extract_edges_from_qubit_pairs(qpu, tag, qubit_pair_uids, *, element_class=None)

Extracts all edges of type tag in the QPU with the qubit pair passed.

Parameters:

Name Type Description Default
qpu QPU

The QPU where the topology is stored.

required
qubit_pair_uids list[list[str]]

The pairs of UIDs for the qubits that will be used as source and target node from the edge, respectively.

required
tag str

The edge tag to be searched.

required
element_class type[QuantumElement] | None

The quantum element class (optional). By default, the quantum element class is None.

None

Returns:

Type Description
list[TopologyEdge]

The list of extracted edges.

Raises:

Type Description
TypeError

If the elements in the extracted edges are not of the type specified in element_class.

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_parallel_two_qubit_experiment(qpu, qubit_pair_uids)

Checks that an experiment can be run in parallel on the qubit pairs.

Parameters:

Name Type Description Default
qpu QPU

The QPU where the topology is stored.

required
qubit_pair_uids list[list[str]]

The pairs of UIDs for the qubits that will be used as source and target node from the edge.

required

Returns:

Type Description
list[QuantumElement]

The flat list of qubit objects corresponding to qubit_pair_uids.

Raises:

Type Description
ValueError

If a qubit is passed more than once in the full list. (One cannot act on them in parallel.)

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.