mimiqcircuits.operations.measurepauli

Pauli product measurement (MeasurePauli).

Classes

MeasurePauli(pauli)

Pauli product measurement.

class MeasurePauli(pauli)[source]

Bases: AbstractMeasurement

Pauli product measurement.

Projective measurement of the \(N\)-qubit observable \(P = P_1 \otimes P_2 \otimes \dots \otimes P_N\), with each \(P_i \in \{I, X, Y, Z\}\).

The instruction targets \(N\) qubits and one classical bit. The state is projected onto the \(+1\) or \(-1\) eigenspace of \(P\) and the bit records the outcome: 0 for \(+1\), 1 for \(-1\). Qubits marked I are targets of the instruction but are not measured.

To measure \(-P\), measure \(P\) and flip the bit with Not.

Parameters:

pauli (PauliString | str) – The observable, as a PauliString or a string of I, X, Y, Z. Stored in the pauli attribute as a PauliString.

Raises:
  • TypeError – If pauli is neither a PauliString nor a str.

  • ValueError – If the string is empty, contains a character other than I, X, Y, Z, or is the identity.

See also

PauliString, RPauli, MeasureZZ, MeasureXX, MeasureYY, pauli_based_computation()

Each measured qubit is rotated to the Z basis (H for X, SDG then H for Y), CX gates collect the parity of the measured qubits on the last one, that qubit is measured, and the CX gates and rotations are undone. Only H, S, SDG, CX, Measure and ID (on a trailing identity factor, to keep the width) appear, so QASMBasis decomposes it. StimBasis and CliffordTBasis keep it as it is, as Stim measures Pauli products natively (MPP).

Measurements are not reversible: inverse, power and control raise TypeError.

Examples

Measure \(X_0 Z_2\) on qubits 0 to 2 and store the outcome in bit 0. Qubit 1 is a target, but is left untouched:

>>> from mimiqcircuits import *
>>> MeasurePauli("XIZ")
MP(XIZ)
>>> c = Circuit()
>>> c.push(MeasurePauli("XIZ"), 0, 1, 2, 0)
3-qubit, 1-bit circuit with 1 instruction:
└── MP(XIZ) @ q[0:2], c[0]

One decomposition step shows the basis change and parity collection:

>>> decompose_step(MeasurePauli("XZ"))
2-qubit, 1-bit circuit with 5 instructions:
├── H @ q[0]
├── CX @ q[0], q[1]
├── M @ q[1], c[0]
├── CX @ q[0], q[1]
└── H @ q[0]
pstring()[source]

Return the Pauli string as a plain str.

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool

get_operation()[source]

Return the operation that this one wraps, or the operation itself.

Wrappers such as Control or Power return the operation they wrap; other operations return themselves.

Returns:

Operation