Decomposition¶
qsp_proc.decomposition
¶
Public API for decomposition routines and validation helpers.
DecompositionResult
dataclass
¶
Output of recursive carving: constant residue, projectors, and carve metadata.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
11 12 13 14 15 16 17 18 | |
MatrixLaurentPoly
¶
Two-by-two matrix-valued Laurent polynomial F(z) = sum_k C_k z^k.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
coeffs
property
¶
Dense coefficient array (copy).
Same encapsulation pattern as :class:~qsp_proc.polynomials.laurent.LaurentPoly.
min_degree
property
¶
Minimum Laurent exponent with a stored block.
max_degree
property
¶
Maximum Laurent exponent with a stored block.
exponents
property
¶
Stored Laurent exponents as a dense integer range.
degree
property
¶
Half-width degree max(|min_degree|, |max_degree|).
__init__(coeffs, min_degree)
¶
Initialize from dense (num_coeffs, 2, 2) blocks and minimum Laurent exponent.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
24 25 26 27 28 29 30 31 32 33 34 35 36 | |
coefficient(k)
¶
Return coefficient matrix C_k, or a 2x2 zero matrix if outside support.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
66 67 68 69 70 71 | |
evaluate(z)
¶
Evaluate at scalar or batched z with trailing output shape (2, 2).
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
73 74 75 76 77 78 79 80 81 82 83 | |
__matmul__(other)
¶
Multiply two matrix-valued Laurent polynomials via coefficient convolution.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
is_su2_on_circle(num_samples=512, tol=1e-10)
¶
Whether F(e^{iθ}) is approximately in SU(2) on uniform circle samples.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
decompose(p, q, convention='gqsp', tol=1e-10)
¶
Unified decomposition entry point for supported QSP conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
LaurentPoly
|
Primary Laurent polynomial |
required |
q
|
LaurentPoly
|
Complementary Laurent polynomial / Fejér factor from completion. |
required |
convention
|
str
|
Convention selector ( |
'gqsp'
|
tol
|
float
|
Numerical tolerance used by decomposition routines and verification. |
1e-10
|
Returns:
| Type | Description |
|---|---|
DecompositionResult
|
Recursive carving decomposition result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\decomposition\carving.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
reconstruct_from_decomposition(result, num_samples=256)
¶
Reconstruct F(z) from E_0 and carved projectors.
Uses
F(z) = E_0 @ prod_{j=1}^{m} E_{P_j}(z), where
E_{P_j}(z) = (I - P_j) + z^{s_j} P_j, where exponents follow
result.carve_sides (top carve -> s_j = +1, bottom carve -> s_j = -1).
If carve_sides is unavailable (legacy results), parity fallback is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Decomposition output containing |
required |
num_samples
|
int
|
Reserved for API compatibility and optional future checks. |
256
|
Returns:
| Type | Description |
|---|---|
MatrixLaurentPoly
|
Reconstructed matrix-valued Laurent polynomial. |
Source code in src\qsp_proc\decomposition\carving.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
verify_decomposition(p, q, result, convention='gqsp', num_samples=512, tol=1e-08)
¶
Verify a decomposition by sampled operator-norm reconstruction error.
This computes:
max_z ||F(z) - F_recon(z)||_op over uniformly sampled points on U(1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
LaurentPoly
|
Primary Laurent polynomial |
required |
q
|
LaurentPoly
|
Complementary Laurent polynomial |
required |
result
|
DecompositionResult
|
Decomposition result. |
required |
convention
|
str
|
QSP convention selector; currently only |
'gqsp'
|
num_samples
|
int
|
Number of unit-circle samples. |
512
|
tol
|
float
|
Tolerance used for optional debug logging threshold. |
1e-08
|
Returns:
| Type | Description |
|---|---|
float
|
Maximum sampled operator-norm error. |
Source code in src\qsp_proc\decomposition\carving.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
qsp_proc.decomposition.carving
¶
QSP decomposition via recursive carving (Skelton 2025, Appendix D, Algorithm 2).
Core routines factor a matrix-valued Laurent polynomial by rank-1 projectors and
extract a constant SU(2) residue. Matrix construction lives in
:mod:qsp_proc.decomposition.builders; the polynomial type in
:mod:qsp_proc.decomposition.matrix_laurent_poly.
extract_projector_from_rank1(C, tol=1e-10)
¶
Recover rank-1 projector P satisfying C @ P = 0 via SVD null-space extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
C
|
ndarray
|
Input matrix with shape |
required |
tol
|
float
|
Numerical tolerance for rank detection and projector validation. |
1e-10
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Projector matrix |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\decomposition\carving.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
snap_to_projector(near_proj, tol=1e-10)
¶
Snap a near-projector to an exact rank-1 projector via eigendecomposition.
Following Theorem 2 / Algorithm 2 (Skelton 2025), this selects the eigenvector
associated with the eigenvalue closest to 1 and forms
P = |e0><e0| to enforce exact projector structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
near_proj
|
ndarray
|
Approximate Hermitian projector with shape |
required |
tol
|
float
|
Numerical tolerance for input validation and spectral sanity checks. |
1e-10
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Exact rank-1 projector matrix with shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If input shape is invalid, not approximately Hermitian, or projector validation fails. |
Source code in src\qsp_proc\decomposition\carving.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
carve_one_step(F, projector, from_top=True)
¶
Apply one recursive carving step via right-multiplication by E_P^{-1}.
Implements Appendix D.1.3 (Eq. 88):
- from_top=True: E_P^{-1}(z) = Q + z^{-1} P
- from_top=False: E_P^{-1}(z) = Q + z P
where Q = I - P.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
MatrixLaurentPoly
|
Current matrix-valued Laurent polynomial |
required |
projector
|
ndarray
|
Rank-1 |
required |
from_top
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
MatrixLaurentPoly
|
Updated matrix-valued Laurent polynomial after one carving step. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\decomposition\carving.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
recursive_carve(F, tol=1e-10)
¶
Run the full recursive carving loop (Algorithm 2, Skelton 2025).
Starting from a padded matrix-valued Laurent polynomial, this repeatedly extracts a rank-1 projector from the active boundary coefficient, snaps it to an exact Hermitian projector, and carves one layer until a constant matrix remains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
MatrixLaurentPoly
|
Input matrix-valued Laurent polynomial to decompose. |
required |
tol
|
float
|
Numerical tolerance for projector-snapping and diagnostics. |
1e-10
|
Returns:
| Type | Description |
|---|---|
DecompositionResult
|
Decomposition result containing snapped constant unitary |
DecompositionResult
|
projectors in carve order. |
Source code in src\qsp_proc\decomposition\carving.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
decompose(p, q, convention='gqsp', tol=1e-10)
¶
Unified decomposition entry point for supported QSP conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
LaurentPoly
|
Primary Laurent polynomial |
required |
q
|
LaurentPoly
|
Complementary Laurent polynomial / Fejér factor from completion. |
required |
convention
|
str
|
Convention selector ( |
'gqsp'
|
tol
|
float
|
Numerical tolerance used by decomposition routines and verification. |
1e-10
|
Returns:
| Type | Description |
|---|---|
DecompositionResult
|
Recursive carving decomposition result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src\qsp_proc\decomposition\carving.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
reconstruct_from_decomposition(result, num_samples=256)
¶
Reconstruct F(z) from E_0 and carved projectors.
Uses
F(z) = E_0 @ prod_{j=1}^{m} E_{P_j}(z), where
E_{P_j}(z) = (I - P_j) + z^{s_j} P_j, where exponents follow
result.carve_sides (top carve -> s_j = +1, bottom carve -> s_j = -1).
If carve_sides is unavailable (legacy results), parity fallback is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
DecompositionResult
|
Decomposition output containing |
required |
num_samples
|
int
|
Reserved for API compatibility and optional future checks. |
256
|
Returns:
| Type | Description |
|---|---|
MatrixLaurentPoly
|
Reconstructed matrix-valued Laurent polynomial. |
Source code in src\qsp_proc\decomposition\carving.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
verify_decomposition(p, q, result, convention='gqsp', num_samples=512, tol=1e-08)
¶
Verify a decomposition by sampled operator-norm reconstruction error.
This computes:
max_z ||F(z) - F_recon(z)||_op over uniformly sampled points on U(1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
LaurentPoly
|
Primary Laurent polynomial |
required |
q
|
LaurentPoly
|
Complementary Laurent polynomial |
required |
result
|
DecompositionResult
|
Decomposition result. |
required |
convention
|
str
|
QSP convention selector; currently only |
'gqsp'
|
num_samples
|
int
|
Number of unit-circle samples. |
512
|
tol
|
float
|
Tolerance used for optional debug logging threshold. |
1e-08
|
Returns:
| Type | Description |
|---|---|
float
|
Maximum sampled operator-norm error. |
Source code in src\qsp_proc\decomposition\carving.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
qsp_proc.decomposition.builders
¶
Convention-specific construction of matrix-valued Laurent polynomials for decomposition.
build_matrix_poly_gqsp(p, q)
¶
Build G-QSP matrix polynomial F = [[P, Q], [-Q_tilde, P_tilde]].
For
P(z) = sum_k p_k z^k and Q(z) = sum_k q_k z^k, this constructs
coefficient blocks
C_k = [[p_k, q_k], [-conj(q_{-k}), conj(p_{-k})]].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
LaurentPoly
|
Laurent polynomial |
required |
q
|
LaurentPoly
|
Laurent polynomial |
required |
Returns:
| Type | Description |
|---|---|
MatrixLaurentPoly
|
Matrix-valued Laurent polynomial |
Source code in src\qsp_proc\decomposition\builders.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
build_matrix_poly_laurent_qsp(a, b, gamma)
¶
Build Laurent-QSP matrix polynomial from A, B and gamma.
Implements Appendix D.1.2 (Skelton 2025):
F(z) = A(z)I + iB(z)sigma_X + iC(z)sigma_Y + iD(z)sigma_Z, where
(C, D) = gamma_to_cd(gamma). Equivalently,
F = [[A + iD, iB + C], [iB - C, A - iD]].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
LaurentPoly
|
Laurent polynomial |
required |
b
|
LaurentPoly
|
Laurent polynomial |
required |
gamma
|
LaurentPoly
|
Completion output Laurent polynomial |
required |
Returns:
| Type | Description |
|---|---|
MatrixLaurentPoly
|
Matrix-valued Laurent polynomial |
Source code in src\qsp_proc\decomposition\builders.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
gamma_to_cd(gamma)
¶
Convert gamma into reciprocal/anti-reciprocal Laurent polynomials.
Implements Appendix D.1.1 (Skelton 2025):
C(z) = (gamma(z) + gamma(1/z)) / 2,
D(z) = (gamma(z) - gamma(1/z)) / (2i).
If gamma(z) = sum_k g_k z^k, then
c_k = (g_k + g_-k)/2 and d_k = (g_k - g_-k)/(2i).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gamma
|
LaurentPoly
|
Input Laurent polynomial |
required |
Returns:
| Type | Description |
|---|---|
tuple[LaurentPoly, LaurentPoly]
|
Tuple |
Source code in src\qsp_proc\decomposition\builders.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
pad_to_half_degree(F)
¶
Apply Algorithm 2 zero-padding: F(z)=sum_k C_k z^k -> F'(w)=sum_k C_k w^{2k}.
This doubles the Laurent exponent grid by inserting zero 2x2 blocks at
odd exponents. If n = degree(F), the output support is exactly
[-2n, 2n] with coefficient-array shape (4n + 1, 2, 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
MatrixLaurentPoly
|
Input matrix-valued Laurent polynomial. |
required |
Returns:
| Type | Description |
|---|---|
MatrixLaurentPoly
|
Re-parameterized matrix-valued Laurent polynomial |
Source code in src\qsp_proc\decomposition\builders.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
qsp_proc.decomposition.matrix_laurent_poly
¶
Matrix-valued Laurent polynomial storage and carving output types.
DecompositionResult
dataclass
¶
Output of recursive carving: constant residue, projectors, and carve metadata.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
11 12 13 14 15 16 17 18 | |
MatrixLaurentPoly
¶
Two-by-two matrix-valued Laurent polynomial F(z) = sum_k C_k z^k.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
coeffs
property
¶
Dense coefficient array (copy).
Same encapsulation pattern as :class:~qsp_proc.polynomials.laurent.LaurentPoly.
min_degree
property
¶
Minimum Laurent exponent with a stored block.
max_degree
property
¶
Maximum Laurent exponent with a stored block.
exponents
property
¶
Stored Laurent exponents as a dense integer range.
degree
property
¶
Half-width degree max(|min_degree|, |max_degree|).
__init__(coeffs, min_degree)
¶
Initialize from dense (num_coeffs, 2, 2) blocks and minimum Laurent exponent.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
24 25 26 27 28 29 30 31 32 33 34 35 36 | |
coefficient(k)
¶
Return coefficient matrix C_k, or a 2x2 zero matrix if outside support.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
66 67 68 69 70 71 | |
evaluate(z)
¶
Evaluate at scalar or batched z with trailing output shape (2, 2).
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
73 74 75 76 77 78 79 80 81 82 83 | |
__matmul__(other)
¶
Multiply two matrix-valued Laurent polynomials via coefficient convolution.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
is_su2_on_circle(num_samples=512, tol=1e-10)
¶
Whether F(e^{iθ}) is approximately in SU(2) on uniform circle samples.
Source code in src\qsp_proc\decomposition\matrix_laurent_poly.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |