ParityHandle#

class ParityHandle(instruction)[source]#

A lightweight handle representing the result of a parity computation in quantum circuits.

ParityHandle objects are returned by qrisp.QuantumCircuit.parity() and serve as keys in the detector and observable maps produced by to_stim(). They enable tracking of parity check results throughout circuit manipulation pipelines.

Attributes:
instructionInstruction

The Instruction object containing the ParityOperation that sits in the circuit’s data list (qc.data).

clbitslist[Clbit]

Get the clbits involved in this parity from the underlying instruction.

expectationint

Get the expected parity value from the underlying instruction.

observablebool

Get whether this parity is an observable from the underlying instruction.

Examples

ParityHandles are typically created via qrisp.QuantumCircuit.parity():

>>> from qrisp import QuantumCircuit
>>> qc = QuantumCircuit(2, 2)
>>> qc.h(0)
>>> qc.cx(0, 1)
>>> qc.measure([0, 1], [0, 1])
>>> handle = qc.parity([qc.clbits[0], qc.clbits[1]], expectation=0)
>>> handle.clbits
[Clbit(cb_2), Clbit(cb_3)]
>>> handle.expectation
0

Use handles as keys in Stim conversion maps:

>>> stim_circuit, meas_map, det_map = qc.to_stim(
...     return_measurement_map=True,
...     return_detector_map=True
... )
>>> det_map[handle]  # Get the Stim detector index
0