post_selection (qiskit_addon_utils.noise_management.post_selection
)¶
Functions and classes to perform Post Selection.
- class PostSelectionSummary(primary_cregs, measure_map, edges, *, post_selection_suffix='_ps')[source]¶
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.
- classmethod from_circuit(circuit, coupling_map, *, post_selection_suffix='_ps')[source]¶
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:
- class PostSelector(summary)[source]¶
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(result, strategy=PostSelectionStrategy.NODE)[source]¶
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 asFalse
.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:
- Return type:
- classmethod from_circuit(circuit, coupling_map, *, post_selection_suffix='_ps')[source]¶
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:
- property summary: PostSelectionSummary¶
A summary of the circuit being post selected.