BoxMullerTables

class BoxMullerTables(n_lookup: int = 512)[source][source]

Bases: object

Lookup tables shared by the QUA macro and its Python replay.

cos[k] = cos(2*pi*k/n) and ln[k] = sqrt(-2 ln((k+1)/(n+1))) for k = 0..n-1. Use get() to reuse cached instances.

Parameters:

n_lookup – Table length; a power of two between 4 and 2**14 so the ln and cos indices come from disjoint bits of the 28-bit draw.

Raises:

ValueError – If n_lookup is not a supported power of two.

classmethod get(n_lookup: int = 512) → BoxMullerTables[source][source]

Return a cached BoxMullerTables for n_lookup.

declare_qua()[source][source]

Declare the tables as QUA fixed arrays; must be called inside with program():.

Returns:

Tuple (cos_array, ln_array) of QUA arrays.