mimiqcircuits.operations.measure¶
Measurement operations.
Classes
|
Base class for measurement operations, such as |
|
Single-qubit measurement in the computational (Z) basis. |
|
Single-qubit measurement in the X basis. |
|
Single-qubit measurement in the Y basis. |
|
Single-qubit measurement in the Z basis, an alias of |
- class Measure[source]¶
Bases:
AbstractMeasurementSingle-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,powerandcontrolraiseTypeError.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
CanonicalRewritemay decompose this operation.Operations opt in: only those the canonical rewrite knows how to handle return
True.- Returns:
bool
- class MeasureX[source]¶
Bases:
AbstractMeasurementSingle-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
Measureand a second Hadamard gate, so the qubit is left in the measured X eigenstate.Warning
Measurements are not reversible:
inverse,powerandcontrolraiseTypeError.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]
- class MeasureY[source]¶
Bases:
AbstractMeasurementSingle-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-basisMeasureand a secondGateHYZ, so the qubit is left in the measured Y eigenstate.Warning
Measurements are not reversible:
inverse,powerandcontrolraiseTypeError.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]
- class MeasureZ[source]¶
Bases:
AbstractMeasurementSingle-qubit measurement in the Z basis, an alias of
Measure.MeasureZ()returns aMeasureinstance, not aMeasureZ.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]