noise_management
qiskit_addon_utils.noise_management
Noise management tools.
trex_factors
trex_factors(measurement_noise_map, basis_dict, /)
Calculates TREX mitigation algorithm’s expectation value scale factor for each Pauli term in basis_dict.
Calculates <Z^n> for each Pauli term in each observable, where n is the non identity indices in the Pauli term. The calculation is done using learned measurement noise.
Parameters
- measurement_noise_map (PauliLindbladMap) – Learned measurement noise in PauliLindbladMap format.
- basis_dict (dict[Pauli, list[SparsePauliOp | None]]) – Mapping between measure bases and observables in which the TREX algorithm mitigates their
- calculation. (expectation value)
Returns
A list of numpy array of floats that represent the TREX mitigation algorithm’s expectation value scale factor for each Pauli term in each observable in each basis in the given basis_dict.
gamma_from_noisy_boxes
gamma_from_noisy_boxes(noise_models, box_id_to_noise_id, noise_scales_each_box=None)
Calculate the gamma factor for a circuit given the Pauli-Lindblad noise models for the boxes in that circuit.
This function expects the noise models to represent the noise in the circuit, and thus to have positive Lindblad rates. The returned gamma is that associated with the inverse noise maps needed to cancel the noise in the circuit.
Parameters
- noise_models (dict[str, PauliLindbladMap]) – Dict of noise-model IDs (strings) and learned noise models for each unique noisy box in the circuit.
- box_id_to_noise_id (dict[str, str]) – Dict of box IDs and noise-model IDs.
- noise_scales_each_box (dict[str, ndarray] | None) – Dict of box IDs and factors by which to rescale the Lindblad error rates of each generator in the associated noise model.
Returns
The gamma factor.
Raises
ValueError if the length** of an array in noise_scales_each_box does not equal the length of rates of **the associated – PauliLindbladMap in noise_models.
Return type
PostSelectionSummary
class PostSelectionSummary(primary_cregs, measure_map, edges, *, post_selection_suffix='_ps')
Bases: object
A helper class to store the properties of a quantum circuit required to post select the results.
Initialize a PostSelectionSummary object.
Parameters
- primary_cregs (set[str]) – The names of the “primary” classical registers, namely those that do not end with the post selection suffix.
- measure_map (dict[int, tuple[str, int]]) – A map between qubit indices to the register and clbits that uniquely define a measurement on those qubits.
- edges (set[frozenset[int]]) – A list of tuples defining pairs of neighboring qubits.
- post_selection_suffix (str) – The suffix of the post selection registers.
edges
Type: set[frozenset[int]]
A set of edges to consider for edge-based post selection.
from_circuit
classmethod from_circuit(circuit, coupling_map, *, post_selection_suffix='_ps')
Initialize from quantum circuits.
Parameters
- circuit (QuantumCircuit) – The circuit to create a summary of.
- coupling_map (CouplingMap |list[tuple[int, int]]) – A coupling map or a list of tuples indicating pairs of neighboring qubits.
- post_selection_suffix (str) – A fixed suffix to append to the names of the classical registers when copying them.
Return type
measure_map
Type: dict[int, tuple[str, int]]
A map from qubit indices to the register and clbit index used to measure those qubits.
post_selection_suffix
Type: str
The suffix of the post selection registers.
primary_cregs
Type: set[str]
The names of the “primary” classical registers.
PostSelector
class PostSelector(summary)
Bases: object
A class to process the results of quantum programs based on the outcome of post selection measurements.
Initialize a PostSelector object.
Parameters
summary (PostSelectionSummary) – A summary of the circuit being post selected.
compute_mask
compute_mask(result, strategy=PostSelectionStrategy.NODE)
Compute boolean masks indicating what shots should be kept or discarded for the given result.
This function compares the bits returned by every pair of measurement and post selection measurement, identifying all those that failed to flip. The shots that should be kept are marked as True in the returned mask, those that should be discarded are marked as False.
By construction, the returned mask has the same shape as the arrays in corresponding result, but with one fewer dimension (the last axis of every array, over clbits, is not present in the mask).
Parameters
- result (dict[str, ndarray[tuple[int, ...], dtype[bool]]]) – The result to post-process. It must be a
QuantumProgramResultcontaining a single item or a dictionary. - strategy (str | PostSelectionStrategy) – The post selection strategy used to process the result.
Return type
from_circuit
classmethod from_circuit(circuit, coupling_map, *, post_selection_suffix='_ps')
Initialize from quantum circuits.
Parameters
- circuits – The circuits to process the results of.
- coupling_map (CouplingMap |list[tuple[int, int]]) – A coupling map or a list of tuples indicating pairs of neighboring qubits.
- post_selection_suffix (str) – A fixed suffix to append to the names of the classical registers when copying them.
- circuit (QuantumCircuit)
Return type
summary
Type: PostSelectionSummary
A summary of the circuit being post selected.