Skip to content

Mid-Circuit Measurement

Warning

This feature is under development.

Syntax

measure ( quantum-var )

measure ( quantum-var )

Semantics

  • A measure call receives a quantum variable of type QBit and returns a CBool value.
  • In Qmod Native, when measure is called, it must be immediately be assigned to a local classical variable, e.g., x = measure(q);.
  • Measurements are run-time values. Currently, if is the only control flow statements that supports run-time variables.
  • Following the measure operation, 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);
  }
}