qat.lang.AQASM.qbool.QBool

class qat.lang.AQASM.qbool.QBool(index, scope=None)

Class for quantum boolean type.

This class is not designed to be instantiated by hand, but rather via the .qalloc method of the Program class or the .new_wires method of the QRoutine class.

Moreover, since allocation happens at the register level, the QBoolArray class should be used.

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

rout = QRoutine()
qbool_array = rout.new_wires(2, QBoolArray)
print(type(qbool_array))
print(type(qbool_array[0]))
<class 'qat.lang.AQASM.qbool.QBoolArray'>
<class 'qat.lang.AQASM.qbool.QBool'>

See documentation of the QClause class for more information.

Parameters:
  • index (int) – the qubit index

  • scope (Program/QRoutine) – the scope in which the allocation happened

Instance attributes:

  • index (int): the index of the underlying qbit

  • scope (Program/QRoutine): the scope in which the underlying qbit was declared

cast(val)

Cast an integer value as a boolean.

This method is used when casting execution samples to proper python values.

Parameters:

val (int) – some integer

Returns:

a boolean value

Return type:

bool

cast_to(cls, **kwargs)

Cast the register to another type.

Parameters:

cls (type) – another quantum type class

Returns:

some object constructed via cls

Return type:

object

For instance, the following piece of code casts a quantum boolean to a quantum integer:

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

rout = QRoutine()
array = rout.new_wires(2, QBoolArray)
qbool = array[0]
qint = qbool.cast_to(QInt)
evaluate(output=None)

Evaluate the QBool as an expression. Since QBools are trivial expression, this simply returns self and the output argument is ignored (it is here simply for compatibility with more complicated expressions).

Parameters:

output (Qbit) – an optional output qubit (ignored)

Returns:

a QBool object

Return type:

QBool

phase()

Flips the phase of the state if and only if the QBool is set to True. Effectively applies a \(Z\) gate on self.

qbits_list()

Returns the list of underlying qubits (i.e [self])