QUAArray¶
- class QUAArray(*args, **kwargs)[source][source]¶
Bases:
ParameterA generic N-dimensional view over one big 1D QUA array.
The underlying QUA allocation is always 1D (QUA only supports 1D arrays natively). Multi-dimensional indexing is emulated via row-major (C-order) stride arithmetic, i.e. element [i, j, k] maps to flat index i*s0 + j*s1 + k*s2 where strides are computed from the shape at construction time.
Indices may be a mix of plain Python
int(resolved at compile time) and QUA integer variables (resolved at runtime). The flat-index expression produced by_flat_indexis therefore either a Pythonintor a QUA arithmetic expression, both of which are valid as QUA array subscripts.- Supports:
Full indexing:
arr[i, j, k]→ single QUA variablePartial indexing:
arr[i]→_QUAArrayViewproxySlice expansion:
arr[i, :]→ Python list of variables / viewsWhole-array assign:
arr.assign(value)Element assign:
arr.assign((i, j), val)(delegates to view for partial)
Exactly one of
shapeorvaluemust be provided.- Parameters:
name – Name of the parameter.
shape – Tuple of ints describing the array dimensions, e.g.
(3, 4). The underlying 1D QUA array is zero-initialised.value – A Python list (possibly nested) or numpy array whose shape is used as the array dimensions and whose flattened contents are used as initial values.
qua_type – QUA type of the elements (e.g.
fixed,int,bool).input_type – Input type forwarded to
Parameter.direction – Direction forwarded to
Parameter(OPNIC only).units – Units string forwarded to
Parameter.
- Raises:
TypeError – If neither or both of
shape/valueare supplied, or if their types are wrong.
- assign(indices_or_val, val=None)[source][source]¶
Flexible element / whole-array assignment.
Calling conventions:
arr.assign(value)— whole-array assign.valuemust be a list/ndarray/QUA array accepted byParameter.assign(). Delegates directly to the parent implementation.arr.assign((i,), row_value)/arr.assign((i, j), scalar_val)— partial or full index assign.indices_or_valmust be a tuple of indices (Python ints or QUA variables). For partial indices a_QUAArrayViewis constructed and itsassignis called. For a complete index tuple a directqua_assignis emitted.
Note
Single-element shorthand
arr.assign(i, val)is intentionally not supported — always wrap indices in a tuple to avoid ambiguity with the whole-array form.
- push_to_opx(value: ndarray | List, job: RunningQmJob | JobApi | None = None, qm: QuantumMachine | None = None, verbosity: int = 1, time_out: int = 30)[source][source]¶
Push an N-D array of values into the OPX at runtime.
valueis validated againstself.shape, flattened to a 1-D list in row-major order, and forwarded toParameter.push_to_opx(). This mirrorsQUA2DArray.push_to_opx()for the 2-D case, generalised to arbitrary rank.The
job/qmarguments match the baseParameterAPI: pass aRunningQmJoborJobApi. Current QUA drives IO through the job interface;qmis kept only for older call sites.- Parameters:
value – A numpy array or (possibly nested) Python list whose shape must equal
self.shape.job – Running job or job API handle used for input-stream / IO pushes. Optional; required when
input_typeneeds a live job.qm – Optional
QuantumMachine. Unused with modernJobApiIO (legacy back-compat when an older job object still routed IO via the machine).verbosity – Verbosity level forwarded to
Parameter.push_to_opx().time_out – Timeout in seconds forwarded to
Parameter.push_to_opx().
- Raises:
TypeError –
valueis not a numpy array or list.ValueError –
valueshape does not matchself.shape.
- stream_processing(mode: Literal['save', 'save_all'] = 'save_all', buffer: Tuple[int, ...] | int | None = None)[source][source]¶
Declare stream-processing for this N-D array.
The QUA stream API expects a flat stream to be buffered into a shape before saving. This method builds the correct buffer tuple and calls
stream.buffer(*buffer).save[_all](name).Buffer resolution:
None(default) — useself.shapeas the buffer; the stream is reshaped back to the array’s natural N-D shape. Equivalent toQUA2DArray’s default of(n_rows, n_cols).int(leading-dimension shorthand) — prepend the integer toself.shape, yielding(int, *self.shape). Useful when the array is streamed once per repetition and you want to accumulate that many repetitions before saving.tuple— used as-is. Must be a tuple of positive ints; no further total-size validation is performed here (the QUA compiler will catch mismatches).
- Parameters:
mode –
"save"to keep only the last buffer,"save_all"to accumulate all buffers (default).buffer – Buffer shape — see above.
- Raises:
ValueError –
modeis invalid or the stream has not been declared.TypeError –
bufferis notNone, anint, or atuple.