mimiqcircuits.operations.measure

Measurement operations.

Classes

AbstractMeasurement()

Base class for measurement operations, such as Measure and MeasureXX.

Measure()

Single-qubit measurement in the computational (Z) basis.

MeasureX()

Single-qubit measurement in the X basis.

MeasureY()

Single-qubit measurement in the Y basis.

MeasureZ()

Single-qubit measurement in the Z basis, an alias of Measure.

class Measure[source]

Bases: AbstractMeasurement

Single-qubit measurement in the computational (Z) basis.

Projects the qubit onto \(|0⟩\) or \(|1⟩\) and writes the outcome, 0 or 1, to a classical bit. The instruction takes one qubit and one bit.

Warning

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

Examples

>>> from mimiqcircuits import *
>>> # measure qubit 0 into bit 0
>>> c = Circuit()
>>> c.push(Measure(), 0, 0)
1-qubit, 1-bit circuit with 1 instruction:
└── M @ q[0], c[0]

Targets can be ranges, lists or tuples; one instruction is added per qubit-bit pair:

>>> c = Circuit()
>>> c.push(Measure(), range(0,3), range(0,3))
3-qubit, 3-bit circuit with 3 instructions:
├── M @ q[0], c[0]
├── M @ q[1], c[1]
└── M @ q[2], c[2]
supports_canonical_rewrite()[source]

Whether CanonicalRewrite may decompose this operation.

Operations opt in: only those the canonical rewrite knows how to handle return True.

Returns:

bool

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 MeasureX[source]

Bases: AbstractMeasurement

Single-qubit measurement in the X basis.

Projects the qubit onto \(|+⟩\) or \(|-⟩\) and writes 0 or 1 to a classical bit. It decomposes into a Hadamard gate, a Z-basis Measure and a second Hadamard gate, so the qubit is left in the measured X eigenstate.

Warning

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

See also

Measure, MeasureY, MeasureZ, Reset

Examples

>>> from mimiqcircuits import *
>>> MeasureX()
MX
>>> # measure qubit 2 into bit 1
>>> c = Circuit()
>>> c.push(MeasureX(), 2, 1)
3-qubit, 2-bit circuit with 1 instruction:
└── MX @ q[2], c[1]
>>> c.push(MeasureX(), 3, 4)
4-qubit, 5-bit circuit with 2 instructions:
├── MX @ q[2], c[1]
└── MX @ q[3], c[4]
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 MeasureY[source]

Bases: AbstractMeasurement

Single-qubit measurement in the Y basis.

Projects the qubit onto \(|{+i}⟩\) or \(|{-i}⟩\) and writes 0 or 1 to a classical bit. It decomposes into a GateHYZ, a Z-basis Measure and a second GateHYZ, so the qubit is left in the measured Y eigenstate.

Warning

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

See also

Measure, MeasureX, MeasureZ, Reset

Examples

>>> from mimiqcircuits import *
>>> MeasureY()
MY
>>> c = Circuit()
>>> c.push(MeasureY(), 2, 1)
3-qubit, 2-bit circuit with 1 instruction:
└── MY @ q[2], c[1]
>>> c.push(MeasureY(), 3, 4)
4-qubit, 5-bit circuit with 2 instructions:
├── MY @ q[2], c[1]
└── MY @ q[3], c[4]
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 MeasureZ[source]

Bases: AbstractMeasurement

Single-qubit measurement in the Z basis, an alias of Measure.

MeasureZ() returns a Measure instance, not a MeasureZ.

See also

Measure, MeasureX, MeasureY, Reset

Examples

>>> from mimiqcircuits import *
>>> # the constructor returns a plain Measure
>>> MeasureZ()
M
>>> c = Circuit()
>>> c.push(MeasureZ(), 0, 0)
1-qubit, 1-bit circuit with 1 instruction:
└── M @ q[0], c[0]
>>> c.push(MeasureZ(), 1, 2)
2-qubit, 3-bit circuit with 2 instructions:
├── M @ q[0], c[0]
└── M @ q[1], c[2]