QUA2DArray¶
- class QUA2DArray(*args, **kwargs)[source][source]¶
Bases:
ParameterTwo-dimensional view over a single flattened 1D QUA array.
QUA only supports 1D arrays at declaration time. This class packs
n_rows * n_colselements into one backingParameterand exposes 2D indexing, row-wiseassign(), and the usualParameterstreaming and host I/O helpers.Create a 2D logical view over one flattened 1D QUA array.
Internally this is a
Parameterof lengthn_rows * n_cols. Afterdeclare(), use 2D indexing (arr[i, j]), row proxies (arr[i][j]), and slices (arr[i, :],arr[:, j]).Two construction patterns are supported:
Shape only – pass row and column counts; elements initialize to zero.
From initial data – pass a 2D nested
listornumpy.ndarraywithndim == 2and omitn_cols; shape is inferred from the value.
- Parameters:
name – Parameter name (also used as the stream / OPNIC field name).
n_rows_or_value – Row count (
int), or a 2D initial value as a nestedlistornumpy.ndarray.n_cols – Number of columns. Required when
n_rows_or_valueis anint. Omit when a 2D value array is supplied.qua_type – Element QUA type:
int,fixed,bool, or the strings"int","fixed","bool". Inferred when a 2D value array is passed.input_type – Optional streaming mode (
InputType):INPUT_STREAM,IO1,IO2, orOPNIC. Same semantics asParameter.direction – Required when
input_typeisOPNIC(Direction). Ignored otherwise.units – Units label (default: empty string).
- Raises:
ValueError – If
n_colsis missing for an integer row count, dimensions are not positive, or a 2D value array is ragged or not rank-2.TypeError – If
n_rows_or_valueis not anint, 2D list, or 2D array.
Examples
Shape-only construction:
QUA2DArray("weights", 32, 8, qua_type=fixed)
From a 2D NumPy array:
QUA2DArray("bias_grid", np.zeros((4, 16)))
Inside a QUA program:
from qm.qua import program with program(): grid = QUA2DArray("fake_data", 50, 8, qua_type=fixed) grid.declare() grid.assign(0, [1, 0, 1, 0, 1, 0, 1, 0]) cell = grid[0, 0] row = grid[0]
- assign(row: QuaVariable[int] | QuaLiteral[int] | QuaBinaryOperation[int] | QuaArrayCell[int] | QuaArrayLength[int] | QuaLibFunctionOutput[int] | QuaFunctionOutput[int] | QuaBroadcast[int] | _QuaGlobalVarOperation[int] | int, col_or_vals: QuaVariable[int] | QuaLiteral[int] | QuaBinaryOperation[int] | QuaArrayCell[int] | QuaArrayLength[int] | QuaLibFunctionOutput[int] | QuaFunctionOutput[int] | QuaBroadcast[int] | _QuaGlobalVarOperation[int] | int | Sequence | QuaArrayVariable, val: QuaVariable[NumberT] | QuaLiteral[NumberT] | QuaBinaryOperation[NumberT] | QuaArrayCell[NumberT] | QuaArrayLength[NumberT] | QuaLibFunctionOutput[NumberT] | QuaFunctionOutput[NumberT] | QuaBroadcast[NumberT] | _QuaGlobalVarOperation[NumberT] | NumberT = None)[source][source]¶
Generalized assign: - assign(row, col, value) → one element - assign(row, [v0, v1, …]) → entire row from Python list/ndarray - assign(row, qua_array) → entire row from a QuaArray-like
This allows you to assign a single value to a specific cell, assign an entire row from a Python list or numpy array, or assign an entire row from another QUA array variable. Note that the row index is 0-based. This method overrides the default assign method to handle 2D arrays and does not propose the same handling of conditional assignment as the original QUA assign.
- Parameters:
row – Row index (0-based).
col_or_vals – Column index (0-based) or sequence of values for a full row assignment.
val – Value to assign when
col_or_valsis a column index.
- stream_processing(mode: Literal['save', 'save_all'] = 'save_all', buffer: Tuple[int] | int = None)[source][source]¶
Stream processing for the 2D array. - mode: “save” to save only the last row, “save_all” to save all rows. - buffer: size of the buffer to use for streaming.
- push_to_opx(value: ndarray | List[List[Number]], job: RunningQmJob, verbosity: int = 1, time_out: int = 30)[source][source]¶
Push the 2D array to the OPX. - value: single value or a sequence of values to push. - job: RunningQmJob instance to use for pushing. - verbosity: level of verbosity for the operation. - time_out: time out in seconds for the operation.