mimiqcircuits.operations.measurereset

Measure and reset operations.

Classes

MeasureReset()

Measure a qubit in the Z basis, then reset it to \(|0⟩\).

MeasureResetX()

Measure a qubit in the X basis, then reset it to \(|+⟩\).

MeasureResetY()

Measure a qubit in the Y basis, then reset it to \(|{+i}⟩\).

MeasureResetZ()

Alias of MeasureReset.

class MeasureReset[source]

Bases: AbstractMeasurement

Measure a qubit in the Z basis, then reset it to \(|0⟩\).

Writes the outcome to a classical bit and then applies GateX to the qubit if the outcome is 1, which leaves it in \(|0⟩\). It decomposes into Measure followed by an IfStatement of GateX conditioned on that bit. The instruction takes one qubit and one bit.

Warning

Not reversible: inverse, power and control raise TypeError.

See also

MeasureResetX, MeasureResetY, Reset

Examples

>>> from mimiqcircuits import *
>>> # measure qubit 1 into bit 0 and leave it in |0>
>>> c = Circuit()
>>> c.push(MeasureReset(), 1, 0)
2-qubit, 1-bit circuit with 1 instruction:
└── MR @ q[1], c[0]

>>> # the same as a measurement followed by a conditional X
>>> MeasureReset().decompose()
1-qubit, 1-bit circuit with 2 instructions:
├── M @ q[0], c[0]
└── IF(c==1) X @ q[0], condition[0]
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 MeasureResetX[source]

Bases: AbstractMeasurement

Measure a qubit in the X basis, then reset it to \(|+⟩\).

Writes 0 for \(|+⟩\) and 1 for \(|-⟩\) to a classical bit and leaves the qubit in \(|+⟩\). It decomposes into a Hadamard gate, a MeasureReset and a second Hadamard gate. The instruction takes one qubit and one bit.

Warning

Not reversible: inverse, power and control raise TypeError.

Examples

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

>>> # rotate to the Z basis, measure and reset, rotate back
>>> MeasureResetX().decompose()
1-qubit, 1-bit circuit with 3 instructions:
├── H @ q[0]
├── MR @ q[0], c[0]
└── H @ q[0]
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 MeasureResetY[source]

Bases: AbstractMeasurement

Measure a qubit in the Y basis, then reset it to \(|{+i}⟩\).

Writes 0 for \(|{+i}⟩\) and 1 for \(|{-i}⟩\) to a classical bit and leaves the qubit in \(|{+i}⟩\). It decomposes into a GateHYZ, a MeasureReset and a second GateHYZ. The instruction takes one qubit and one bit.

Warning

Not reversible: inverse, power and control raise TypeError.

Examples

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

>>> # rotate to the Z basis, measure and reset, rotate back
>>> MeasureResetY().decompose()
1-qubit, 1-bit circuit with 3 instructions:
├── HYZ @ q[0]
├── MR @ q[0], c[0]
└── HYZ @ q[0]
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 MeasureResetZ[source]

Bases: AbstractMeasurement

Alias of MeasureReset.

MeasureResetZ() returns a MeasureReset instance.

Examples

>>> from mimiqcircuits import *
>>> MeasureResetZ()
MR