mimiqcircuits.operations.ifstatement¶
Conditional execution (IfStatement).
Classes
|
Operation applied only when classical bits match a bitstring. |
- class IfStatement(operation, bitstring)[source]¶
Bases:
OperationOperation applied only when classical bits match a bitstring.
IfStatement(op, bs)appliesopwhen the condition bits hold the values inbs, the first condition bit compared with the first character ofbs, and so on. Otherwise it does nothing.The instruction takes the targets of
opfollowed by the condition bits: qubits ofop, classical bits ofop,len(bs)condition bits, then z-variables ofop. The condition bits may overlap with the bits ofop.- Parameters:
operation – The operation to apply, or an operation class built with no arguments.
bitstring (BitString) – The values the condition bits must hold.
- Raises:
ValueError – If
operationis not an operation orbitstringis not aBitString.
Examples
>>> from mimiqcircuits import * >>> c = Circuit() >>> # measure qubit 0 into bit 0 >>> c.push(Measure(), 0, 0) 1-qubit, 1-bit circuit with 1 instruction: └── M @ q[0], c[0] >>> # flip qubit 1 only if bit 0 is 1 >>> c.push(IfStatement(GateX(), BitString('1')), 1, 0) 2-qubit, 1-bit circuit with 2 instructions: ├── M @ q[0], c[0] └── IF(c==1) X @ q[1], condition[0] >>> # measure qubit 1 into bit 3 if bits 1 and 2 are 0 and 1: >>> # the bit of the measurement comes before the condition bits >>> c.push(IfStatement(Measure(), BitString('01')), 1, 3, 1, 2) 2-qubit, 4-bit circuit with 3 instructions: ├── M @ q[0], c[0] ├── IF(c==1) X @ q[1], condition[0] └── IF(c==01) M @ q[1], c[3], condition[1:2]
- property op¶
The conditioned operation. Read-only.
- property bitstring¶
The values the condition bits must hold, as a
BitString.
- iswrapper()[source]¶
Whether the operation wraps another operation.
Truefor composite operations such asControl,Power,Inverse,ParallelorIfStatement,Falseotherwise.- Returns:
bool
- 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
- inverse()[source]¶
Not supported for conditional operations.
- Raises:
NotImplementedError – Always.
- power(power)[source]¶
Not supported for conditional operations.
- Raises:
NotImplementedError – Always.
- control(num_controls)[source]¶
Not supported for conditional operations.
- Raises:
NotImplementedError – Always.
- format_with_targets(qubits, bits, zvars)[source]¶
Nested conditional formatting (explicit IF(c==..) chain).