qat.lang.AQASM.qbool.QClause

class qat.lang.AQASM.qbool.QClause(scope, operator, operand=None)

Class describing boolean formulae to manipulate qubits.

This class is not designed to be instantiated by hand.

Clauses are created by using the boolean operators (and, or, xor, neg) applied on (an)other formula(e) or qubits. Qubits are implicitly cast toward boolean formulae.

Example:

from qat.lang.AQASM import QRoutine
from qat.lang.AQASM.qbool import QBoolArray

rout = QRoutine()
wires = rout.new_wires(2, QBoolArray)

and_formula = wires[0] & wires[1]
print(type(and_formula))
<class 'qat.lang.AQASM.qbool.QClause'>

A formula should be manipulated via:

  • the .evaluate method, in order to compute its value in superposition

  • the .phase method in order to perform a phase flip of all the basis states that evaluate the formula to true

  • a with statement (see the example below)

Example of evaluate:

from qat.lang.AQASM import QRoutine
from qat.lang.AQASM.qbool import QBoolArray

rout = QRoutine()
wires = rout.new_wires(2, QBoolArray)

and_formula = wires[0] & wires[1]

# By directly allocating an ancilla
result = and_formula.evaluate()

# Or by prior allocation of a result qubit
result = rout.new_wires(1)
and_formula.evaluate(output=result)

# At this stage, `result` carries the logical AND between our two inputs

Example of phase:

from qat.lang.AQASM import QRoutine
from qat.lang.AQASM.qbool import QBoolArray

rout = QRoutine()
wires = rout.new_wires(2, QBoolArray)

and_formula = wires[0] & wires[1]

and_formula.phase()
# At this stage, all classical states such that the first two qubits
# are set to 1 have their phase flipped

Example of with statement conditional:

from qat.lang.AQASM import QRoutine, CNOT
from qat.lang.AQASM.qbool import QBoolArray

rout = QRoutine()
wires = rout.new_wires(2, QBoolArray)

and_formula = wires[0] & wires[1]
output = rout.new_wires(1)

with and_formula as condition:
    CNOT(condition, output)

# We evaluated the expression, got a qbit `condition` carrying the result
# and store the result in `output`
evaluate(output=None)

Builds a circuit evaluating the expression.

Parameters

output (optional, Qbit) – an output qbit

Returns

a quantum boolean carrying the

result of the evaluation

Return type

Qbit

phase()

Flips the phase if and only if the expression/qbits evaluates to True.

qbits_list()

Returns a list of underlying qbits.

Returns

a list of qbits

Return type

list of Qbits