Mid-Circuit Measurement
Warning
This feature is under development.
Syntax
measure ( quantum-var )
measure ( quantum-var )
Semantics
- A
measurecall receives a quantum variable of typeQBitand returns aCBoolvalue. - In Qmod Native, when
measureis called, it must be immediately be assigned to a local classical variable, e.g.,x = measure(q);. - Measurements are run-time
values. Currently,
ifis the only control flow statements that supports run-time variables. - Following the
measureoperation, any superposition state of its operand collapses to a computational-basis state corresponding to the classical measured result.
Example
The following function implements the RESET gate using a mid-circuit
measurement.
from classiq import *
@qfunc
def reset(q: QBit):
val = measure(q)
if_(val, lambda: X(q))
qfunc reset(q: qbit) {
val: bool;
val = measure(q);
if (val) {
X(q);
}
}