qat.lang.AQASM.qint.QInt

class qat.lang.AQASM.qint.QInt(start=0, length=1, scope=None, reverse_bit_order=False, qbits_list=None)

Class for quantum integer type. The qubit list in a QInt is by default encoded such that the most significant bit is on the left. The order can be reversed using the reverse_bit_order argument.

As other quantum types, this class is not designed to be constructed by hand, but rather via the .qalloc method of the Program class or the .new_wires method of the QRoutine class.

Example:

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

rout = QRoutine()
qint = rout.new_wires(10, QInt)
print(qint, type(qint))

# or, with reversed bit order:
qint = rout.new_wires(10, QInt, reverse_bit_order=True)
QInt(q[0]..q[9]) <class 'qat.lang.AQASM.qint.QInt'>

Quantum integers have two sets of overloaded operators:

  • arithmetic operators (+ and *): combine QInt and/or QArithExp to produce a QArithExp. See documentation of QArithExp for more details.

  • comparison operators (<,>,<=,>=,==,!=): combine a QInt/QArithExp and or a classical int in order to produce a comparison expression, QCompExp, that behave similarly to a QClause and can be thus used to construct oracles or conditionals.

Moreover, the += and -= operators are also overloaded and triggers a circuit evaluating the right-hand term and adding it to the quantum integer.

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

rout = QRoutine()
qint1 = rout.new_wires(10, QInt)
qint2 = rout.new_wires(10, QInt)
qint3 = rout.new_wires(10, QInt)

# This does nothing
qint1 + qint2

# This generates a circuit that adds qint1 in qint3 and qint2 in qint3
qint3 += qint1 + qint2

# This generates a circuit that adds -qint1 in qint3 and -qint2 in qint3
qint3 -= qint1 + qint2

Comparisons results can be used exactly as QClause:

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

rout = QRoutine()
qint1 = rout.new_wires(10, QInt)
qint2 = rout.new_wires(10, QInt)

# Flips the phase of states such that qint1 is smaller than 3
(qint1 < 3).phase()

# Flips the phase of states such that qint1 + qint2 is smaller than 14
(qint1 + qint2 < 14).phase()
Parameters
  • start (int) – the start index of the underlying register

  • length (int) – the length of the integer

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

  • reverse_bit_order (bool) – if set to True, reverse the bit order of the integer.

Instance attributes:

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

cast(val)

Casts some integer value into some other integer value with the correct bit-order. This is used when casting execution samples.

Parameters

val (int) – some integer

evaluate(nbqbit=None)

Evaluate the QInt as a formula. Effectively does nothing and returns a copy of self.

qbits_list()

Returns the underlying list of qubits.

Returns

a list of quantum booleans

Return type

list of Qbit

set_value(val)

Sets the QInt to some classical value.

Note

This method assumes that the QInt is unitialized (i.e is still in state \(|0\rangle\)). Effectively, the register is xored with the classical value.

Parameters

val (int) – some integer value