> ## Documentation Index
> Fetch the complete documentation index at: https://docs.classiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Block Encoding

## 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:**

| Name | Description |
| - | - |
| [from\_unitary](#from_unitary) | |
| [from\_dense\_diagonals](#from_dense_diagonals) | Block encoding of a matrix given by dense diagonals, via amplitude loading + LCU. |
| [from\_constant\_diags](#from_constant_diags) | Block encoding of a matrix given by constant diagonals, via LCU. |
| [from\_sparse\_pauli\_op](#from_sparse_pauli_op) | Block encoding of a Hamiltonian, given as a sparse Pauli operator, via LCU. |
| [from\_matrix](#from_matrix) | Block encoding of an arbitrary matrix via Pauli decomposition and LCU. |
| [from\_sparse\_oracles](#from_sparse_oracles) | Block encoding of an s-sparse matrix via sparsity + amplitude oracles. |
| [weighted\_sum](#weighted_sum) | Block encoding of sum\_j coefficients\[j] \* A\_j via a single LCU. |
| [product](#product) | Block encoding of a product with logarithmic flag overhead. |
| [tensor\_product](#tensor_product) | Block encoding of A1 (x) A2 of two block encodings acting on disjoint data subsystems. |
| [inverse](#inverse) | Block encoding of A^{-1} via QSVT polynomial inversion. |
| [qubitize](#qubitize) | Qubitization walk operator W = R \* U (Low-Chuang); powers of W give Chebyshev polynomials of the encoded matrix via Qmod's `power`. |
| [bound\_call](#bound_call) | |
| [to\_matrix](#to_matrix) | Reconstruct the encoded matrix A, up to a global phase, via statevector simulation. |

**Attributes:**

| Name | Type | Description |
| - | - | - |
| `unitary` | `Callable[..., None]` | |
| `block_size` | `int` | |
| `alpha` | `float` | |
| `epsilon` | `float` | |
| `data_size` | `int` | Number of qubits the data register `A` acts on. |
| `hermitian_be` | `bool` | Whether the unitary `U` itself (not the encoded matrix `A`) is Hermitian. Needed e.g. for qubitization's walk operator, which requires a Hermitian `U` to be a product of two reflections. |

### from\_unitary

<pre><code>from\_unitary(
cls: ,
unitary: QCallable,
block\_size: int,
alpha: float,
data\_size: int,
hermitian\_be: bool = False
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `unitary` | `QCallable` | | *required* |
| `block_size` | `int` | | *required* |
| `alpha` | `float` | | *required* |
| `data_size` | `int` | | *required* |
| `hermitian_be` | `bool` | | False |

### from\_dense\_diagonals

<pre><code>from\_dense\_diagonals(
cls: ,
diagonals: Sequence\[tuple\[Sequence\[float], int]],
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of a matrix given by dense diagonals, via amplitude loading + LCU.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `diagonals` | `Sequence[tuple[Sequence[float], int]]` | | *required* |
| `hermitian_be` | `bool \| None` | | None |

### from\_constant\_diags

<pre><code>from\_constant\_diags(
cls: ,
diagonals: Sequence\[tuple\[float, int]],
cyclic: bool = False,
size: int,
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of a matrix given by constant diagonals, via LCU.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `diagonals` | `Sequence[tuple[float, int]]` | | *required* |
| `cyclic` | `bool` | | False |
| `size` | `int` | | *required* |
| `hermitian_be` | `bool \| None` | | None |

### from\_sparse\_pauli\_op

<pre><code>from\_sparse\_pauli\_op(
cls: ,
pauli\_op: SparsePauliOp,
graycode: bool = False,
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of a Hamiltonian, given as a sparse Pauli operator, via LCU.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `pauli_op` | `SparsePauliOp` | | *required* |
| `graycode` | `bool` | | False |
| `hermitian_be` | `bool \| None` | | None |

### from\_matrix

<pre><code>from\_matrix(
cls: ,
mat: np.ndarray,
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of an arbitrary matrix via Pauli decomposition and LCU.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `mat` | `np.ndarray` | | *required* |
| `hermitian_be` | `bool \| None` | | None |

### from\_sparse\_oracles

<pre><code>from\_sparse\_oracles(
cls: ,
oracle\_amplitude: QCallable,
oracle\_column: QCallable,
sparsity: int,
data\_size: int,
hermitian\_be: bool = False
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of an s-sparse matrix via sparsity + amplitude oracles.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `oracle_amplitude` | `QCallable` | Amplitude oracle `oracle_amplitude(amp, ell, data)`. | *required* |
| `oracle_column` | `QCallable` | Sparsity oracle `oracle_column(ell, data)`. | *required* |
| `sparsity` | `int` | Number of nonzeros per row/column; must be a power of 2. | *required* |
| `data_size` | `int` | Number of qubits the data register acts on; not derivable from the oracles, which may be written generically for any size. | *required* |
| `hermitian_be` | `bool` | whether the block-encoding unitary itself is Hermitian; not derivable from arbitrary caller-supplied oracles, so this is trusted as given (default `False`). | False |

### weighted\_sum

<pre><code>weighted\_sum(
cls: ,
coefficients: Sequence\[complex],
bes: Sequence\[<a href="#blockencoding">BlockEncoding</a>],
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

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:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `coefficients` | `Sequence[complex]` | Weight c\_j applied to each block encoding's matrix A\_j. | *required* |
| `bes` | Sequence\[[BlockEncoding](#blockencoding)] | Block encodings to combine, one per coefficient. | *required* |
| `hermitian_be` | `bool \| None` | `None` (default) auto-infers it; pass `True`/`False` to override. | None |

### product

<pre><code>product(
cls: ,
bes: list\[<a href="#blockencoding">BlockEncoding</a>],
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of a product with logarithmic flag overhead.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `bes` | list\[[BlockEncoding](#blockencoding)] | | *required* |
| `hermitian_be` | `bool \| None` | | None |

### tensor\_product

<pre><code>tensor\_product(
cls: ,
be1: <a href="#blockencoding">BlockEncoding</a>,
be2: <a href="#blockencoding">BlockEncoding</a>,
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of A1 (x) A2 of two block encodings acting on disjoint
data subsystems. See `_block_encoding_tensor_product` for the qubit
ordering convention.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `cls` | \`\` | | *required* |
| `be1` | [BlockEncoding](#blockencoding) | | *required* |
| `be2` | [BlockEncoding](#blockencoding) | | *required* |
| `hermitian_be` | `bool \| None` | | None |

### inverse

<pre><code>inverse(
self: ,
kappa: float,
degree: int | None = None,
eps: float | None = None,
hermitian\_be: bool | None = None
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Block encoding of A^{-1} via QSVT polynomial inversion.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `self` | \`\` | | *required* |
| `kappa` | `float` | | *required* |
| `degree` | `int \| None` | | None |
| `eps` | `float \| None` | | None |
| `hermitian_be` | `bool \| None` | | None |

### qubitize

<pre><code>qubitize(
self:
) -> <a href="#blockencoding">BlockEncoding</a></code></pre>

Qubitization walk operator W = R \* U (Low-Chuang); powers of W give
Chebyshev polynomials of the encoded matrix via Qmod's `power`.

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `self` | \`\` | | *required* |

### bound\_call

<pre><code>bound\_call(
self: ,
data: Any,
block: Any
) -> Callable\[\[], None]</code></pre>

**Parameters:**

| Name | Type | Description | Default |
| - | - | - | - |
| `self` | \`\` | | *required* |
| `data` | `Any` | | *required* |
| `block` | `Any` | | *required* |

### to\_matrix

<pre><code>to\_matrix(
self:
) -> np.ndarray</code></pre>

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:**

| Name | Type | Description | Default |
| - | - | - | - |
| `self` | \`\` | | *required* |
