qubrabench.datastructures package¶
Submodules¶
qubrabench.datastructures.qlist module¶
qubrabench.datastructures.qndarray module¶
- class qubrabench.datastructures.qndarray.Qndarray(data, view_of=None)¶
Bases:
QObject
,Generic
[T
]Quantum-accessible ndarray object.
This behaves like numpy.ndarray, but also tracks accesses to elements.
Note
It does not support the full generality of numpy ndarrays. Currently only supports indexing to either access entries or get subviews. If you reshape or copy the data, it is considered a new object, whose stats are tracked separately.
>>> a = np.array([[1, 2], [3, 4]]) >>> qa = Qndarray(a) >>> qa[0, 0] 1
- Accessing entries:
Use qndarray[i, j, …] with ndim indices.
- Creating views:
When accessed using ranges for indices, or only a subset of indices, it creates a view object instead, whose queries are tracked as queries to the original object.
>>> a = np.array([[1, 2], [3, 4]]) >>> row_0 = a[0, :] >>> row_0[0] 1
- copy()¶
- get_raw_data()¶
- item(ix: int | tuple[int, ...]) T ¶
- property ndim¶
- property shape¶
- property size¶
- qubrabench.datastructures.qndarray.block_encode_matrix(matrix: ndarray[Any, dtype[_ScalarType_co]] | Qndarray, *, eps: float) BlockEncoding ¶
Prepares a block-encoding of a dense matrix.
Complexity is described in Lemma 48 of [QSVT2019] for sparse matrices, which can be extended to a dense matrix by picking row and column sparsities to be the full dimension.
This method currently only considers queries to the input matrix, and not other gates/unitaries that are input-independent. Note that eps does not affect queries to the matrix, but only auxillary gates needed.
- Parameters:
matrix – the input matrix to block encode
eps – the required precision of the block-encoding
- Returns:
The block encoding of the input matrix
References
[QSVT2019]: [Quantum singular value transformation and beyond: exponential improvements for quantum matrix arithmetics](https://arxiv.org/abs/1806.01838)
- qubrabench.datastructures.qndarray.state_preparation_unitary(vector: ndarray[Any, dtype[_ScalarType_co]] | Qndarray, *, eps: float) BlockEncoding ¶