mimiqcircuits.operations.whilestatement

Conditional loop (WhileStatement).

Classes

WhileStatement(operation, bitstring)

Conditional loop operation.

class mimiqcircuits.operations.whilestatement.WhileStatement(operation, bitstring)[source]

Bases: Operation

Conditional loop operation.

Repeatedly applies the provided operation while the classical register matches the specified BitString.

WhileStatement is the loop counterpart of IfStatement. The body operation op is executed once for every iteration in which the classical register’s state equals the BitString. For the loop to terminate, op must mutate at least one of the bits used in the condition; WhileStatement allows body bits to alias condition bits, which is the only way to make progress.

There is no built-in iteration cap — a non-terminating circuit is the user’s responsibility, mirroring how every classical language treats while.

Examples

>>> from mimiqcircuits import *
>>> c = Circuit()
>>> c.push(WhileStatement(Not(), BitString('1')), 0, 0)
1-bit circuit with 1 instruction:
└── WHILE(c==1) ! @ c[0], condition[0]

See also

  • IfStatement

__init__(operation, bitstring)[source]
property op
property bitstring
iswrapper()[source]
getparams()[source]
inverse()[source]
power(power)[source]
control(num_controls)[source]
format_with_targets(qubits, bits, zvars)[source]
evaluate(d)[source]
get_operation()[source]
get_bitstring()[source]
asciiwidth(qubits, bits, zvars)[source]