mimiqcircuits.operations.pairmeasure

Pair measurement operations (ZZ, XX, YY).

Classes

MeasureXX()

Measure the parity of two qubits in the X basis.

MeasureYY()

Measure the parity of two qubits in the Y basis.

MeasureZZ()

Measure the parity of two qubits in the Z basis.

class MeasureZZ[source]

Bases: AbstractMeasurement

Measure the parity of two qubits in the Z basis.

Measures the two-qubit Pauli operator \(Z \otimes Z\) and writes 0 for eigenvalue +1 (the qubits agree in the Z basis) or 1 for eigenvalue -1 (they differ). Only the parity is measured, so superpositions within each parity sector are kept. The instruction takes two qubits and one bit.

It decomposes into a CX gate, a measurement of the second qubit, and a second CX gate that undoes the first.

Warning

Not reversible: inverse, power and control raise TypeError.

See also

MeasureXX, MeasureYY, MeasurePauli

Examples

>>> from mimiqcircuits import *
>>> # measure the ZZ parity of qubits 0 and 1 into bit 0
>>> c = Circuit()
>>> c.push(MeasureZZ(), 0, 1, 0)
2-qubit, 1-bit circuit with 1 instruction:
└── MZZ @ q[0:1], c[0]

>>> MeasureZZ().decompose()
2-qubit, 1-bit circuit with 3 instructions:
├── CX @ q[0], q[1]
├── M @ q[1], c[0]
└── CX @ q[0], q[1]
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

class MeasureXX[source]

Bases: AbstractMeasurement

Measure the parity of two qubits in the X basis.

Measures the two-qubit Pauli operator \(X \otimes X\) and writes 0 for eigenvalue +1 or 1 for eigenvalue -1. The instruction takes two qubits and one bit.

It decomposes into a CX gate from the first qubit to the second and a Hadamard gate on the first, which together map \(X \otimes X\) to \(Z\) on the first qubit, then a measurement of that qubit, then the same two gates in reverse order. The qubits are left in the post-measurement state of the \(X \otimes X\) measurement.

Warning

Not reversible: inverse, power and control raise TypeError.

See also

MeasureZZ, MeasureYY, MeasurePauli

Examples

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

>>> MeasureXX().decompose()
2-qubit, 1-bit circuit with 5 instructions:
├── CX @ q[0], q[1]
├── H @ q[0]
├── M @ q[0], c[0]
├── H @ q[0]
└── CX @ q[0], q[1]
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

class MeasureYY[source]

Bases: AbstractMeasurement

Measure the parity of two qubits in the Y basis.

Measures the two-qubit Pauli operator \(Y \otimes Y\) and writes 0 for eigenvalue +1 or 1 for eigenvalue -1. The instruction takes two qubits and one bit.

It decomposes into an S gate on both qubits, a CX gate from the first qubit to the second and a Hadamard gate on the first, which together map \(Y \otimes Y\) to \(Z\) on the first qubit, then a measurement of that qubit, then the inverse gates in reverse order. The qubits are left in the post-measurement state of the \(Y \otimes Y\) measurement.

Warning

Not reversible: inverse, power and control raise TypeError.

See also

MeasureZZ, MeasureXX, MeasurePauli

Examples

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

>>> MeasureYY().decompose()
2-qubit, 1-bit circuit with 9 instructions:
├── S @ q[0]
├── S @ q[1]
├── CX @ q[0], q[1]
├── H @ q[0]
├── M @ q[0], c[0]
├── H @ q[0]
├── CX @ q[0], q[1]
├── S† @ q[0]
└── S† @ q[1]
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