BlockEncoding
Describes a block encoding of a matrix A. A unitary U is an (alpha, block_size, epsilon)-block-encoding of A if: A = alpha * (<0|^block_size (x) I) U (|0>^block_size (x) I)
Methods:
Attributes:
from_unitary
from_unitary(
cls: ,
unitary: QCallable,
block_size: int,
alpha: float,
data_size: int,
hermitian_be: bool = False
) -> BlockEncoding
Parameters:
from_dense_diagonals
from_dense_diagonals(
cls: ,
diagonals: Sequence[tuple[Sequence[float], int]],
hermitian_be: bool | None = None
) -> BlockEncoding
Block encoding of a matrix given by dense diagonals, via amplitude loading + LCU.
Parameters:
from_constant_diags
from_constant_diags(
cls: ,
diagonals: Sequence[tuple[float, int]],
cyclic: bool = False,
size: int,
hermitian_be: bool | None = None
) -> BlockEncoding
Block encoding of a matrix given by constant diagonals, via LCU.
Parameters:
from_sparse_pauli_op
from_sparse_pauli_op(
cls: ,
pauli_op: SparsePauliOp,
graycode: bool = False,
hermitian_be: bool | None = None
) -> BlockEncoding
Block encoding of a Hamiltonian, given as a sparse Pauli operator, via LCU.
Parameters:
from_matrix
from_matrix(
cls: ,
mat: np.ndarray,
hermitian_be: bool | None = None,
method: str = ‘pauli’,
angle_threshold: float = 0.0
) -> BlockEncoding
Block encoding of an arbitrary matrix.
Parameters:
Returns:
- Type: BlockEncoding
- BlockEncoding of the input matrix.
from_sparse_oracles
from_sparse_oracles(
cls: ,
oracle_amplitude: QCallable,
oracle_column: QCallable,
sparsity: int,
data_size: int,
hermitian_be: bool | None = None,
oracle_row: QCallable | None = None,
variant: Literal[‘lcu’, ‘general’, ‘hermitian’] | None = None,
alpha: float | None = None,
weights: Sequence[float] | None = None
) -> BlockEncoding
Block encoding of an s-sparse matrix via sparsity + amplitude oracles.
The encoded matrix acts on the data register as |j> -> sum_i A_ij |i> / s.
Three circuit variants are available:
-
“lcu”: A = sum_l A^(l), a sum of s 1-sparse matrices from a
Konig decomposition of the sparsity pattern. Block size: 1 + log2(s).
For s = 1 the oracles get a clean 1-qubit index fixed to l = 0.
oracle_column:|l>``|j>->|l>|c(j, l)> (a permutation of j for every l).oracle_amplitude: loads A_ for index = l, data = j. -
“general”: row and column oracles, no Konig decomposition needed.
Block size: 1 + n.
oracle_column:|l>``|j>-> |c(j, l)>|j>, c(j, l) = l-th nonzero row of column j.oracle_row:|l>``|i>-> |r(i, l)>|i>, r(i, l) = l-th nonzero column of row i.oracle_amplitude: loads A_ for index = l, data = j. -
“hermitian”: Hermitian block encoding (U = U^dagger) of a Hermitian A,
usable directly in qubitization. Block size: 2 + n.
oracle_column: as for “general”.oracle_amplitude: loads w_ for index = l, data = j, where w_ij * conj(w_ji) = A_ij (e.g. sqrt(A_ij) for nonnegative A). Diagonal entries are encoded as |w_jj|^2, so they must be nonnegative.
alpha.
Weighted LCU (“lcu” only): with per-term scales weights m_l, the uniform
D = H^n is replaced by a PREPARE of the probabilities m_l / sum(m), the
amplitude oracle loads A^(l) / m_l, and alpha = sum(m) <= s * max(m).
Error: 0 (exact encoding).
Parameters:
Returns:
- Type: BlockEncoding
- Block encoding of A with subnormalization
alpha.
from_scipy_sparse
from_scipy_sparse(
cls: ,
matrix: spmatrix | sparray | np.ndarray,
variant: Literal[‘auto’, ‘lcu’, ‘general’, ‘hermitian’] = ‘auto’,
impl: Literal[‘graycode’, ‘unary’] = ‘graycode’
) -> BlockEncoding
Block encoding of a scipy sparse matrix.
Automatically extracts sparsity structure and builds table-lookup oracles.
The zero matrix gets a trivial block encoding (one block qubit moved to |1>).
This is the most convenient way to create a sparse block encoding when
you have explicit matrix data.
Scaling factor: “lcu”: the sum over the Konig layers of their largest
|A_ij| (weighted LCU, at most s * max|A_ij|); “general”/“hermitian”:
s * max|A_ij|.
Block size depends on variant:
- “lcu”: 1 + ceil(log2(s))
- “general”: 1 + n
- “hermitian”: 2 + n
Returns:
- Type: BlockEncoding
- BlockEncoding of the sparse matrix.
from_sparsity_pattern
from_sparsity_pattern(
cls: ,
pattern: SparsityPattern,
data_size: int,
variant: Literal[‘auto’, ‘lcu’, ‘general’, ‘hermitian’] = ‘auto’,
impl: Literal[‘graycode’, ‘unary’] = ‘graycode’
) -> BlockEncoding
Block encoding from a structured sparsity pattern.
Uses arithmetic-based oracles for maximum efficiency. This is preferred
over from_scipy_sparse() when the matrix has known structure (banded,
circulant, lattice Laplacian, etc.).
Parameters:
Returns:
- Type: BlockEncoding
- BlockEncoding with efficient arithmetic oracles.
weighted_sum
weighted_sum(
cls: ,
coefficients: Sequence[complex],
bes: Sequence[BlockEncoding],
hermitian_be: bool | None = None
) -> BlockEncoding
Block encoding of sum_j coefficients[j] * A_j via a single LCU.
A nonzero phase on a coefficient is realized by lcu’s phase table
(prepare_select/assign_phase_table) as a genuine relative phase between
the LCU branches.
Scaling factor: sum_j |coefficients[j] * alpha_j|.
Block size: max_j(block_size_j) + max(ceil(log2(len(bes))), 1) (LCU select register).
Error: 0 (exact encoding, given exact inputs).
Parameters:
product
product(
cls: ,
bes: list[BlockEncoding],
hermitian_be: bool | None = None
) -> BlockEncoding
Block encoding of a product with logarithmic flag overhead.
Parameters:
tensor_product
tensor_product(
cls: ,
be1: BlockEncoding,
be2: BlockEncoding,
hermitian_be: bool | None = None
) -> BlockEncoding
Block encoding of A1 (x) A2 of two block encodings acting on disjoint
data subsystems.
Note: the reconstructed matrix (to_matrix()) is np.kron(A2, A1), not
np.kron(A1, A2) — qubit index order, not Kronecker-product argument
order, determines it.
Parameters:
inverse
inverse(
self: ,
kappa: float,
degree: int | None = None,
eps: float | None = None,
hermitian_be: bool | None = None
) -> BlockEncoding
Block encoding of A^ via QSVT polynomial inversion.
Parameters:
qubitize
qubitize(
self:
) -> BlockEncoding
Qubitization walk operator W = R * U (Low-Chuang); powers of W give
Chebyshev polynomials of the encoded matrix via Qmod’s power.
Parameters:
bound_call
bound_call(
self: ,
data: Any,
block: Any
) -> Callable[[], None]
Parameters:
to_matrix
to_matrix(
self:
) -> np.ndarray
Reconstruct the encoded matrix A, up to a global phase, via statevector simulation.
Note: The result is exact up to an overall global phase.
Parameters: