Represent periodic-shift matrices as immutable LCU decompositions.
Overview¶
| Function | Description |
|---|---|
as_finite_square_complex_matrix | Convert one value to a finite square complex128 matrix. |
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. |
| Class | Description |
|---|---|
PeriodicShiftLCU | Store an immutable periodic-shift linear-combination decomposition. |
PeriodicShiftLCUTerm | Store one nonzero coefficient and one canonical periodic offset. |
Functions¶
as_finite_square_complex_matrix [source]¶
def as_finite_square_complex_matrix(matrix: ArrayLike) -> np.ndarrayConvert one value to a finite square complex128 matrix.
Parameters:
| Name | Type | Description |
|---|---|---|
matrix | ArrayLike | Candidate dense matrix. |
Returns:
np.ndarray — np.ndarray: Finite square complex128 matrix.
Raises:
ValueError— If conversion fails or the result is nonsquare or non-finite.
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.
Classes¶
PeriodicShiftLCU [source]¶
class PeriodicShiftLCUStore an immutable periodic-shift linear-combination decomposition.
Axis zero occupies the least-significant bits of the flattened system
basis. Each term represents coefficient * T_offset, where every axis
of T_offset wraps modulo 2**register_sizes[axis].
Parameters:
| Name | Type | Description |
|---|---|---|
register_sizes | tuple[int, ...] | Positive qubit width of every periodic axis. The empty tuple represents a scalar 1 x 1 matrix at the linalg layer. |
terms | tuple[PeriodicShiftLCUTerm, ...] | Canonical nonzero terms. Terms are stored in lexicographic offset order. 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 or :meth:from_coefficients. Defaults to 0.0 and excludes host floating-point roundoff. |
Raises:
TypeError— If a field has an invalid runtime type.ValueError— If an axis width, term, normalization, or truncation bound is invalid, or terms contain duplicate offsets.
Constructor¶
def __init__(
self,
register_sizes: tuple[int, ...],
terms: tuple[PeriodicShiftLCUTerm, ...],
truncation_error_bound: float = 0.0,
) -> NoneAttributes¶
alpha: float Return the retained LCU one-norm normalization.num_qubits: int Return the flattened system-register width.num_terms: int Return the number of retained periodic-shift terms.register_sizes: tuple[int, ...]terms: tuple[PeriodicShiftLCUTerm, ...]truncation_error_bound: float
Methods¶
from_coefficients¶
@classmethod
def from_coefficients(
cls,
coefficients: Mapping[Offset, complex],
*,
register_sizes: Sequence[int],
atol: float = 0.0,
) -> PeriodicShiftLCUBuild a canonical decomposition from periodic-shift coefficients.
Equivalent signed or unsigned offsets are combined before pruning.
Coefficients whose magnitude is at most atol are omitted, and the
sum of their magnitudes is stored in truncation_error_bound.
Parameters:
| Name | Type | Description |
|---|---|---|
coefficients | Mapping[int | tuple[int, ...], complex] | Finite coefficients keyed by a one-dimensional integer offset or one integer component per axis. |
register_sizes | Sequence[int] | Positive qubit width of each periodic axis. The empty sequence describes a scalar decomposition; any supplied offset must then be the empty tuple. |
atol | float | Non-negative absolute coefficient threshold. Defaults to 0.0, which removes exact zeros only. |
Returns:
PeriodicShiftLCU — Immutable canonical decomposition.
Raises:
TypeError— If coefficients, offsets, widths, oratolhave invalid types.ValueError— If a value is non-finite, an offset has the wrong dimension, a width is invalid, or normalization overflows.
from_matrix¶
@classmethod
def from_matrix(
cls,
matrix: ArrayLike,
*,
register_sizes: Sequence[int],
atol: float = 0.0,
) -> PeriodicShiftLCUDecompose an exact constant-coefficient periodic-shift matrix.
After conversion to complex128, the structural check is exact:
every column must be the periodic translation of the first column
implied by register_sizes. The atol argument has the same
meaning as in :meth:from_coefficients; it prunes extracted
coefficients but does not relax the structural check. Hermiticity is
not required.
Parameters:
| Name | Type | Description |
|---|---|---|
matrix | ArrayLike | Finite square matrix with dimension 2**sum(register_sizes). |
register_sizes | Sequence[int] | Positive qubit width of each axis in flattened least-significant-axis-first order. The empty sequence describes a scalar 1 x 1 matrix. |
atol | float | Non-negative absolute coefficient threshold. Defaults to 0.0, which removes exact zeros only. |
Returns:
PeriodicShiftLCU — Immutable canonical shift decomposition.
Raises:
TypeError— If widths oratolhave invalid types.ValueError— If the matrix is nonnumeric, non-finite, nonsquare, has the wrong dimension, violates the periodic-shift structure, or produces an unrepresentable normalization.
PeriodicShiftLCUTerm [source]¶
class PeriodicShiftLCUTermStore one nonzero coefficient and one canonical periodic offset.
Parameters:
| Name | Type | Description |
|---|---|---|
coefficient | complex | Finite nonzero coefficient multiplying the periodic shift. |
offset | tuple[int, ...] | Non-negative offset residue for every axis. The enclosing :class:PeriodicShiftLCU validates each component against its corresponding axis size. |
Raises:
TypeError— If the coefficient is not numeric or the offset is not an iterable of non-Boolean integers.ValueError— If the coefficient is zero or non-finite, or an offset component is negative.
Constructor¶
def __init__(self, coefficient: complex, offset: tuple[int, ...]) -> NoneAttributes¶
coefficient: complexoffset: tuple[int, ...]