Utilities (qiskit_addon_slc.utils)¶
Various utilities.
This module provides a number of utility functions. Some of these exist only temporarily to work around open issues of the Qiskit SDK. When this is the case, they are marked as such and may be removed without deprecation or further notice.
- find_indices(circuit, bits_or_instruction, /)[source]¶
Find the qubit-indices of the provided bit indices or circuit instructions.
Caution
This function is not considered part of the stable API! It will get removed without warning or deprecation when the same functionality is supported natively by the Qiskit SDK. See this issue for more details.
- Parameters:
circuit (QuantumCircuit) – the quantum circuit whose qubit indices to find.
bits_or_instruction (Bit | CircuitInstruction | Sequence[Bit]) – the bits whose indices to find. If this is a
CircuitInstruction, the qubits which this instruction acts upon are used.
- Returns:
The indices of the queried bits in the circuit’s registers. If a single bit object was provided, a single
intis returned for its index. Otherwise the return type will be alist[int]whose length equals the number of provided bits.- Raises:
TypeError – when an unexpected type of
bits_or_instructiongets provided.- Return type:
- generate_noise_model_paulis(instructions, coupling_map=None, circuit=None)[source]¶
Generate the 1- and 2-weight Pauli terms for each of the unique 2q layer boxes provided.
- Parameters:
instructions (list[CircuitInstruction]) – the output of
find_unique_box_instructions(). Any of the provided instructions are assumed to either consists of only measurement gates or correspond to a layer of 2-qubit gate instructions. For the former, the generated noise model will contain only single-qubitXerrors, for the latter all 1- and 2-weight Pauli errors on the reduced coupling map will be included.coupling_map (CouplingMap | None) – the coupling map of the backend on which the instructions have been laid out. If this is
None, a 1d line of qubits is assumed.circuit (QuantumCircuit | None) – the transpiled circuit which has been laid out on the provided coupling map. This may only be
Nonewhen thecoupling_mapis alsoNone.
- Returns:
A dictionary mapping the
refattributes of theInjectNoiseannotation of each unique Box to the 1- and 2-weight Pauli terms whose errors are learned for this box.- Return type:
- get_extremal_eigenvalue(spo, **kwargs)[source]¶
Finds the extremal eigenvalue of the provided operator.
This converts the provided operator to a sparse matrix whose minimal eigenvalue is required.
Note
The current implementation is definitely not optimized in terms of performance.
- Parameters:
spo (SparsePauliOp) – the operator whose minimal eigenvalue to find.
kwargs –
additional keyword arguments for
davidson1(). When not specified otherwise, the following defaults will be used:tol: 1e-6
max_cycle: 500
max_space: 12
lindep: 1e-11
max_memory: 2000
Other values will default to PySCF’s default values.
- Returns:
A pair indicating whether the Davidson algorithm has converged and the obtained minimal eigenvalue.
- Return type:
- iter_circuit(circuit, *, reverse=False, log_process=True)[source]¶
Iterates over the instructions in a circuit.
Note
This function recurses into
BoxOpinstructions.Note
Barriers in the circuit are being ignored.
- Parameters:
circuit (QuantumCircuit) – the circuit to iterate over.
reverse (bool) – whether to iterate the circuit in reverse order.
log_process (bool) – whether to log process.
- Yields:
Tuples of length four, consisting of the encountered circuit instruction, the canonical qubit indices (i.e. the integer indices of the acted-upon qubits in the context of the input
circuit), theInjectNoiseattributes:modifier_refandref. The latter two items may beNoneindicating a circuit instruction that was not part of an unrolledBoxOp.- Return type:
Generator[tuple[CircuitInstruction, list[int], str | None, str | None]]
- map_modifier_ref_to_ref(circuit)[source]¶
Iterate a circuit and map
InjectNoiseannotation references.- Parameters:
circuit (QuantumCircuit) – the circuit to iterate over.
- Returns:
A dictionary mapping each
InjectNoise.modifier_refto itsInjectNoise.ref.- Return type:
- remove_measure(circuit)[source]¶
Remove any
Measureoperations from the provided circuit.Note
This function recurses into
BoxOpinstructions.- Parameters:
circuit (QuantumCircuit) – the circuit whose measurements to remove.
- Returns:
The circuit without any Measure operations.
- Return type: