Represent general complex matrices as linear combinations of Paulis.
Overview¶
| Function | Description |
|---|---|
coerce_finite_complex_scalar | Convert one numeric scalar to a canonical finite complex value. |
coerce_nonnegative_finite_real | Convert one numeric scalar to a canonical non-negative finite float. |
fwht_complex_pauli_coefficients | Compute complex Pauli coefficients via FWHT. |
| Class | Description |
|---|---|
PauliLCU | Store an immutable Pauli linear-combination decomposition. |
PauliLCUTerm | Store one nonzero complex coefficient and one sparse Pauli word. |
Functions¶
coerce_finite_complex_scalar [source]¶
def coerce_finite_complex_scalar(value: object, name: str) -> complexConvert one numeric scalar to a canonical finite complex value.
Parameters:
| Name | Type | Description |
|---|---|---|
value | object | Candidate real or complex numeric scalar. |
name | str | Human-readable value name used in diagnostics. |
Returns:
complex — Finite Python complex value whose zero components have a
positive sign.
Raises:
TypeError— Ifvalueis Boolean or not a numeric scalar.ValueError— If a numeric scalar cannot be represented as a finite Python complex value.
coerce_nonnegative_finite_real [source]¶
def coerce_nonnegative_finite_real(value: object, name: str) -> floatConvert one numeric scalar to a canonical non-negative finite float.
Parameters:
| Name | Type | Description |
|---|---|---|
value | object | Candidate real numeric scalar. |
name | str | Human-readable value name used in diagnostics. |
Returns:
float — Finite non-negative Python float with a positive zero sign.
Raises:
TypeError— Ifvalueis Boolean or not a real numeric scalar.ValueError— If an accepted real scalar cannot be represented as a finite non-negative Python float.
fwht_complex_pauli_coefficients [source]¶
def fwht_complex_pauli_coefficients(matrix: ArrayLike) -> tuple[np.ndarray, int]Compute complex Pauli coefficients via FWHT.
Uses the symplectic indexing where qubit k is determined by bit
k of each mask::
(x_bit, z_bit) -> Pauli
(0, 0) -> I
(1, 0) -> X
(0, 1) -> Z
(1, 1) -> YQubit 0 corresponds to the least-significant bit of the matrix’s computational-basis indices.
Parameters:
| Name | Type | Description |
|---|---|---|
matrix | ArrayLike | Dense finite (N, N) array with N = 2**n. |
Returns:
tuple[np.ndarray, int] — tuple[np.ndarray, int]: Pair (coeffs, num_qubits) where coeffs
is an (N, N) complex128 array indexed by
(x_mask, z_mask).
Raises:
ValueError— Ifmatrixis not a finite square matrix whose dimension is a positive power of two, or cannot be converted to complex numeric data.
Classes¶
PauliLCU [source]¶
class PauliLCUStore an immutable Pauli linear-combination decomposition.
Parameters:
| Name | Type | Description |
|---|---|---|
num_qubits | int | Number of system qubits represented by the Pauli words. Zero is valid for a scalar 1 x 1 matrix. |
terms | tuple[PauliLCUTerm, ...] | Ordered nonzero Pauli terms. The empty tuple represents the zero operator. |
truncation_error_bound | float | Upper bound on the spectral-norm error caused only by coefficients intentionally removed by :meth:from_matrix. Defaults to 0.0. It does not include floating-point FWHT roundoff. |
Raises:
TypeError— Ifnum_qubits,terms, ortruncation_error_boundhas an invalid type.ValueError— If a term addresses a qubit outside the system, duplicate Pauli words are present, the LCU normalization exceeds the finite float range, or the error bound is negative or non-finite.
Constructor¶
def __init__(
self,
num_qubits: int,
terms: tuple[PauliLCUTerm, ...],
truncation_error_bound: float = 0.0,
) -> NoneAttributes¶
alpha: float Return the LCU one-norm normalization.num_qubits: intnum_terms: int Return the number of retained Pauli terms.terms: tuple[PauliLCUTerm, ...]truncation_error_bound: float
Methods¶
from_matrix¶
@classmethod
def from_matrix(cls, matrix: ArrayLike, *, atol: float = 0.0) -> PauliLCUDecompose a general complex matrix into the Pauli basis.
Qubit zero is the least-significant bit of the matrix’s computational
basis index. Coefficients whose magnitude is at most atol are
omitted, and their absolute values are accumulated into
:attr:truncation_error_bound.
Parameters:
| Name | Type | Description |
|---|---|---|
matrix | ArrayLike | Finite square matrix with dimension 2**n. Hermiticity is not required. |
atol | float | Non-negative absolute coefficient threshold. Defaults to 0.0, which removes exact zeros only. |
Returns:
PauliLCU — Immutable ordered Pauli decomposition.
Raises:
TypeError— Ifatolis not a real number.ValueError— Ifatolis negative or non-finite, ormatrixis not a finite square numeric matrix with power-of-two dimension, or the resulting LCU normalization exceeds the finite float range.
PauliLCUTerm [source]¶
class PauliLCUTermStore one nonzero complex coefficient and one sparse Pauli word.
The empty operator tuple denotes the identity. Non-identity operators are canonicalized into increasing qubit-index order.
Parameters:
| Name | Type | Description |
|---|---|---|
coefficient | complex | Finite, nonzero coefficient multiplying the Pauli word. |
operators | tuple[PauliOperator, ...] | Sparse Pauli word. Identity operators must be omitted; use an empty tuple for the all-identity word. |
Raises:
TypeError— If the coefficient is not a numeric scalar, an operator is not aPauliOperator, its Pauli value is invalid, or its index is not an integer.ValueError— If the coefficient is zero or non-finite, an identity operator is stored explicitly, or multiple operators address the same qubit.
Constructor¶
def __init__(self, coefficient: complex, operators: tuple[PauliOperator, ...]) -> NoneAttributes¶
coefficient: complexoperators: tuple[PauliOperator, ...]