BlockEncoding.from_array#
- classmethod BlockEncoding.from_array(A: ndarray[tuple[Any, ...], dtype[Any]] | csr_array | csr_matrix) BlockEncoding[source]#
Constructs a BlockEncoding from a 2-D array.
- Parameters:
- Andarray | csr_array | csr_matrix
2-D array of shape
(N,N,)for a power of twoN.
- Returns:
- BlockEncoding
A BlockEncoding representing the Hermitian part \((A+A^{\dagger})/2\).
- Raises:
- ValueError
If
Ais not a 2-D square matrix.- ValueError
If the dimension of
Ais not a power of two.
Notes
Block encoding based on Pauli decomposition \(O=\sum_i\alpha_i P_i\) where \(\alpha_i\) are real positive coefficients and \(P_i\) are Pauli strings (including the respective sign).
Normalization: The block-encoding normalization factor is \(\alpha = \sum_i \alpha_i\).
Examples
>>> import numpy as np >>> from qrisp.block_encodings import BlockEncoding >>> A = np.array([[0,1,0,1],[1,0,0,0],[0,0,1,0],[1,0,0,0]]) >>> B = BlockEncoding.from_array(A)