The evaluation of each operator takes only a few clock cycles. For example, the addition (+) and subtraction (-) operations
each take 1 clock cycle to evaluate, i.e. 4ns.
However, the compiler parallelize operations, resulting in a much reduced effective calculation time which will often be zero.
Boolean operations can be used, but using the operators below ('&', '|', etc) and not with the Pythonic operators ('AND', 'OR', etc)
Warning
Attempting to use Pythonic operators on QUA variables, or attempting to evaluate QUA variables directly
(for example, in a Pythonic 'if' statement), would result in an error.
Operator
Symbol
Example
AND
&
a & b
OR
|
a | b
XOR
^
a ^ b
NOT
~
~a
Compounded boolean expressions are supported.
Note
It is necessary to wrap the atomic boolean expressions in parenthesis as seen in the example below,
due to Python operator precedence rules.
withprogram()asarrays_use:v1=declare(int,value=[1,2,4,8,16])v2=declare(int,size=5)# will be initialized with zerosv3=declare(fixed,size=30)# will be initialized with zerosi=declare(int)assign(v3[0],16)withfor_(i,0,i<v2.length(),i+1):assign(v2[i],i*2)withfor_(i,0,i<v1.length(),i+1):assign(v2[i],v2[i]+v3[i])withfor_(i,0,i<v1.length(),i+1):save(v1[i],"v1")save(v2[i],"v2")withfor_(i,0,i<v3.length(),i+1):save(v3[i],"v3")
QUA allows the user the real time evaluation of several mathematical operators and functions.
Besides the standard mathematical operators (+, -, *, /) the user can access various libraries including
Math - trigonometric functions, array reduction functions etc.
Math.cos(x) : Takes the cosine of a fixed in radians
Math.sin(x) : Takes the sine of a fixed in radians
Math.cos2pi(x) : Takes the cosine of a fixed in 2pi radians
Math.sin2pi(x) : Takes the cosine of a fixed in 2pi radians
cos2pi(x) and sin2pi(x) are equivalent to cos(2*pi*x) and sin(2*pi*x) but saves a few clock cycles as the extra multiplication
stage required to calculate 2*pi are removed by simply having 2*pi stored in memory.
Moreover, these functions are immune to overflows.
So whenever working with radians we suggest using the former. The usage is straightforward, for example:
This program will play pulse_1 for 100 iterations, where for each iteration the amplitude will be modulated by the envelope function cos(2pi * frequency * time).
For evaluation of non-real time mathematical expressions one can always use standard python libraries such as numpy.
QUA provides several function to reduce arrays. These functions run more efficiently (with less latency) when compared to a manual implementing in QUA, as they use hardware optimizations.
Math.sum(x) : sums an array. The result is of the same type as the input array.
Math.max(x), Math.min(x) : max,min an array. The result is of the same type as the input array.
Math.argmin(x)/Math.argmax(x): returns the index of the max/min
Math.dot(x,y): returns the dot product of two QUA arrays of the same size
This class generates a pseudo-random number using a the LCG algorithm with the following parameters: a = 137939405, c = 12345, m = 2**28.
The class constructor optionally takes a seed number and can generate int or fixed values.
Note
Unless specified explicitly, the seed is selected in python using the RNG module.
The seed choice occurs when the program object is created, which means that if we execute a QUA program object several times,
the QUA random numbers sequence will be the same for all executions. To have a new seed, one needs to
withprogram()asprog:r=Random()# you can set the seed:r.set_seed(123213)a=declare(int)b=declare(fixed)assign(a,r.rand_int(100))# a will be a number between 0 and 99assign(b,r.rand_fixed())# b will be a number between 0.0 and 1.0
This is equivalent to a ternary operator available in some languages:
i.e. a ? b : c, meaning 'b' if 'a' is true, or 'c' if 'a' is false.
There is less computation overhead (less latency) when running this operation relative to the if_ conditional