nlft_qsp
¶
Modules:
| Name | Description |
|---|---|
approximate |
Provides functions to compute Laurent/Chebyshev/Fourier approximations. |
file |
Module for JSON serialization of various classes in the package. |
nlft |
Defining the nonlinear Fourier transform, as well as functions to compute the forward NLFT. |
numerics |
Module dealing with floating point types and error tolerance. |
plot |
Helper functions to plot polynomials using matplotlib. |
poly |
Definitions of complex sequences, polynomials and Chebyshev expansions, as well as all operations between them. |
qsp |
Definitions of quantum signal processing protocols and public API for QSP solvers. |
rand |
Random generators (mainly used for testing) |
solvers |
Module containing all the solvers for polynomial completion and inverse nonlinear Fourier transform/QSP synthesis. |
util |
Utility functions. |
Classes:
| Name | Description |
|---|---|
ChebyshevQSPPhaseFactors |
Phase factors for a Chebyshev QSP protocol. |
ChebyshevTExpansion |
Linear combination of Chebyshev polynomials of the first kind. |
GQSPPhaseFactors |
Phase factors for a Generalized QSP protocol. |
NonLinearFourierSequence |
Class representing a finitely supported sequence of complex numbers over \(\mathbb{Z}\). |
PhaseFactors |
Set of phase factors for a general Quantum Signal Processing protocol. |
Polynomial |
Represents a general Laurent polynomial of one complex variable. |
QSVTPhaseFactors |
Phase factors for a QSVT/Reflection QSP protocol. |
XQSPPhaseFactors |
Phase factors for a XQSP protocol. |
YQSPPhaseFactors |
Phase factors for a YQSP protocol. |
Functions:
| Name | Description |
|---|---|
chebqsp_approximate |
DEPRECATED: use |
chebqsp_solve |
DEPRECATED: use |
chebyshev_approximate |
Computes the Chebyshev expansion up to \(N\) for a complex-valued function \(f : [-1, 1] \rightarrow \mathbb{C}\). |
fourier_approximate |
Computes the Fourier series of the given function \(f(z)\), \(z = e^{i\theta}\) being a complex number of unit modulus. |
gqsp_solve |
DEPRECATED: use |
plot_chebyshev |
Plots the real part of each object in funcs over the interval \([-1, 1]\). |
plot_fourier |
Plots the absolute value of each object in funcs over the unit circle, i.e., plugging \(z = e^{it}\) for \(t \in [-\pi, \pi]\). |
qsvt_solve |
DEPRECATED: use |
xqsp_solve |
DEPRECATED: use |
xqsp_solve_laurent |
DEPRECATED: use |
yqsp_solve |
DEPRECATED: use |
yqsp_solve_laurent |
DEPRECATED: use |
ChebyshevQSPPhaseFactors
¶
Bases: XQSPPhaseFactors
Phase factors for a Chebyshev QSP protocol.
where the signal operator \(\tilde{x}\) is
Note
This is the ansatz of arXiv:2105.02859 Theorem 9, but the polynomial construction is implemented by conjugating XQSP with a Hadamard gate.
Methods:
| Name | Description |
|---|---|
approximate |
Approximate the given callable object \(f\) (which takes \(x \in [-1, 1]\) and returns a real number) |
solve |
Returns the set of phase factors for a Chebyshev QSP protocol implementing the polynomial \(P(x)\) (as the real part of the top-left polynomial, see Theorem 9 of arXiv:2105.02859). |
Source code in nlft_qsp/qsp.py
approximate(f: Callable, deg: int) -> ChebyshevQSPPhaseFactors
classmethod
¶
Approximate the given callable object \(f\) (which takes \(x \in [-1, 1]\) and returns a real number)
and returns the Chebyshev QSP phase factors implementing an approximating polynomial of degree deg
(as the real part of the top-left polynomial, see Theorem 9 of arXiv:2105.02859).
Note: The parity of deg should coincide with the parity of \(f\), otherwise the Chebyshev approximator might give numerical errors.
Source code in nlft_qsp/qsp.py
solve(T: list[complex_type] | Polynomial | ChebyshevTExpansion) -> ChebyshevQSPPhaseFactors
classmethod
¶
Returns the set of phase factors for a Chebyshev QSP protocol implementing the polynomial \(P(x)\) (as the real part of the top-left polynomial, see Theorem 9 of arXiv:2105.02859).
The target polynomial will be \(T(x) = \sum_{k = 0}^n c_k T_k(x)\) (if T is a ChebyshevTExpansion) or \(T(x) = \sum_{k = 0}^n c_k x^k\) (if T is a Polynomial), where \(T_k(x)\) are the Chebyshev polynomials of the first kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
list[complex_type] | Polynomial | ChebyshevTExpansion
|
a Chebyshev expansion object or the desired Polynomial \(P(x)\) (that will be converted to the Chebyshev basis). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target polynomial does not have definite parity or is not real. |
Note
T can also be a list of complex numbers. This will be regarded as coefficients in the Chebyshev basis. Passing the list directly is discouraged and will be removed in future releases.
Source code in nlft_qsp/qsp.py
ChebyshevTExpansion
¶
Bases: ComplexL0Sequence
Linear combination of Chebyshev polynomials of the first kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
list[complex_type] | Polynomial
|
Either the coefficients of the linear combination, or the symmetric Laurent polynomial \(P(z)\) which is equal up to the change of variable \(x = \frac{z + z^{-1}}{2}\). |
required |
Note
The change of variable between Laurent polynomials and Chebyshev expansions is given by the relation \(T_k(\cos \theta) = \cos k\theta = \frac{z^k + z^{-k}}{2}\). Thus the expansion is
Methods:
| Name | Description |
|---|---|
__call__ |
Evaluates the Chebyshev expansion at the given number. |
__str__ |
Converts the expansion to a human-readable string representation. |
from_laurent_polynomial |
Returns the Chebyshev expansion \(T\) satisfying \(T(x) = \frac{P(z) + P^*(z)}{2}\). |
from_polynomial |
Returns the Chebyshev expansion \(T\) satisfying \(T(x) = P(x)\). |
to_laurent |
Returns the Laurent polynomial \(P(e^{i\theta}) = T(\cos \theta)\) where \(T(x)\) is represented by |
to_polynomial |
Returns the polynomial \(P\) satisfying \(P(x) = T(x)\). |
Source code in nlft_qsp/poly.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
__call__(x: float_type) -> complex_type
¶
Evaluates the Chebyshev expansion at the given number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float_type
|
The point at which to evaluate the expansion. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
complex |
complex_type
|
The evaluated result. |
Source code in nlft_qsp/poly.py
__str__() -> str
¶
Converts the expansion to a human-readable string representation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the expansion. |
Source code in nlft_qsp/poly.py
from_laurent_polynomial(P: Polynomial)
classmethod
¶
Returns the Chebyshev expansion \(T\) satisfying \(T(x) = \frac{P(z) + P^*(z)}{2}\).
Raises:
| Type | Description |
|---|---|
ValueError
|
if \(P\) is not symmetric. |
Note: \(P\) must be symmetric.
Source code in nlft_qsp/poly.py
from_polynomial(P: Polynomial) -> ChebyshevTExpansion
classmethod
¶
Returns the Chebyshev expansion \(T\) satisfying \(T(x) = P(x)\).
to_laurent() -> Polynomial
¶
Returns the Laurent polynomial \(P(e^{i\theta}) = T(\cos \theta)\) where \(T(x)\) is represented by self.
Source code in nlft_qsp/poly.py
GQSPPhaseFactors
¶
Bases: PhaseFactors
Phase factors for a Generalized QSP protocol.
where \(W(z) = \mathrm{diag}(z, 1)\) (mode='analytic') or \(W(z) = \mathrm{diag}(z, z^{-1})\) (mode='laurent').
Note
This class follows the convention of arXiv:2503.03026, Theorem 2, which is different from the original GQSP convention. If the convention of arXiv:2308.01501 Theorem 3 is desired, then one should use the to_mw_gqsp() method.
Methods:
| Name | Description |
|---|---|
from_nlfs |
Computes the GQSP phase factors for a given NLFT sequence. |
phase_offset |
Returns the phase of the leading coefficient of P, where (P, Q) is the pair of polynomials generated by this set. |
solve |
Returns the set of phase factors for a Generalized QSP protocol producing the given polynomial. See here for an overview of the QSP variants. |
solve_laurent |
Returns the set of phase factors for a Generalized QSP protocol producing the given definite-parity polynomial. See here for an overview of the QSP variants. |
to_mw_gqsp |
Converts the GQSP phase factors to the convention of arXiv:2308.01501 Theorem 3. |
to_xqsp |
Converts the QSP phase factors into XQSP phase factors. |
to_yqsp |
Converts the QSP phase factors into YQSP phase factors. |
Source code in nlft_qsp/qsp.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 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 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
from_nlfs(F: NonLinearFourierSequence, alpha: float_type = 0) -> PhaseFactors
classmethod
¶
Computes the GQSP phase factors for a given NLFT sequence. If \(\mathrm{NLFT}(F) = (a, b)\), then the returned phase factors will implement \((e^{i \alpha} z^n a, b)\) in the analytic picture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
NonLinearFourierSequence
|
The sequence to be converted to phase factors. |
required |
alpha
|
float_type
|
In the pair of polynomials \((P, Q)\) generated by the returned phase factors, \(P\) will be multiplied by |
0
|
Note
The support start of \(F\) is ignored, so the support of \(b\) is assumed to start at \(0\).
Source code in nlft_qsp/qsp.py
phase_offset() -> float_type
¶
Returns the phase of the leading coefficient of P, where (P, Q) is the pair of polynomials generated by this set.
solve(P: Polynomial, convention='qsp') -> GQSPPhaseFactors
classmethod
¶
Returns the set of phase factors for a Generalized QSP protocol producing the given polynomial. See here for an overview of the QSP variants. A complementary \(Q\) will be computed with Weiss' algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convention
|
str
|
Whether the phase factors should produce \((P, Q)\) ( |
'qsp'
|
Note
The sup norm of \(P\) should be bounded by \(1 - \eta < 1\). The time required by the algorithm to compute the phase factors will scale with \(1/\eta\).
The support_start of \(P\) will be ignored.
Source code in nlft_qsp/qsp.py
solve_laurent(P: Polynomial, convention='qsp') -> GQSPPhaseFactors
classmethod
¶
Returns the set of phase factors for a Generalized QSP protocol producing the given definite-parity polynomial. See here for an overview of the QSP variants. A complementary \(Q\) will be computed with Weiss' algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convention
|
str
|
Whether the phase factors should produce \((P, Q)\) ( |
'qsp'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If \(P\) does not have definite parity. |
Note
The sup norm of \(P\) should be bounded by \(1 - \eta < 1\). The time required by the algorithm to compute the phase factors will scale with \(1/\eta\).
Source code in nlft_qsp/qsp.py
to_mw_gqsp() -> tuple[list[float_type], list[float_type], float_type]
¶
Converts the GQSP phase factors to the convention of arXiv:2308.01501 Theorem 3.
In particular, a protocol should be constructed of the form
where the matrix \(R\) is of the form
Returns:
| Type | Description |
|---|---|
tuple[list[float_type], list[float_type], float_type]
|
The phase factors \vec{\theta}, \vec{\phi} (as lists) and \lambda, in this order. |
Source code in nlft_qsp/qsp.py
to_xqsp()
¶
Converts the QSP phase factors into XQSP phase factors.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the phase factors do not lie in the XQSP subalgebra. |
Source code in nlft_qsp/qsp.py
to_yqsp()
¶
Converts the QSP phase factors into YQSP phase factors.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the phase factors do not lie in the YQSP subalgebra. |
Source code in nlft_qsp/qsp.py
NonLinearFourierSequence
¶
Bases: ComplexL0Sequence
Class representing a finitely supported sequence of complex numbers over \(\mathbb{Z}\). The class provides methods to compute the nonlinear Fourier transform (NLFT) associated with the sequence.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes a nonlinear Fourier sequence with a given list of complex values and support starting index. |
transform |
Computes the nonlinear Fourier transform \((a(z), b(z))\) over \(SU(2)\) associated with this sequence. |
transform_bounds |
Computes the nonlinear Fourier transform over \(SU(2)\) for the subsequence within the specified range. |
Source code in nlft_qsp/nlft.py
__init__(coeffs: list[complex_type] | np.ndarray = [], support_start: int = 0)
¶
Initializes a nonlinear Fourier sequence with a given list of complex values and support starting index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
list[complex_type] | ndarray
|
A list of complex numbers representing the sequence. The list includes both the lower and upper bounds of the sequence. |
[]
|
support_start
|
int
|
The index of the first element of the sequence in \(\mathbb{Z}\). The support of the sequence will
be in the range [ |
0
|
Source code in nlft_qsp/nlft.py
transform() -> tuple[Polynomial, Polynomial]
¶
Computes the nonlinear Fourier transform \((a(z), b(z))\) over \(SU(2)\) associated with this sequence.
See here for a definition of the nonlinear Fourier transform.
Returns:
| Type | Description |
|---|---|
tuple[Polynomial, Polynomial]
|
The \(SU(2)\)-NLFT of the sequence. |
Source code in nlft_qsp/nlft.py
transform_bounds(inf, sup) -> tuple[Polynomial, Polynomial]
¶
Computes the nonlinear Fourier transform over \(SU(2)\) for the subsequence within the specified range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inf
|
int
|
The lower bound (included) index of the sequence for the transformation. |
required |
sup
|
int
|
The upper bound (excluded) index of the sequence for the transformation. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Polynomial, Polynomial]
|
The \(SU(2)\)-NLFT of the subsequence in [ |
Note
This is used only internally in order to compute the polynomials through a divide-and-conquer strategy.
If only interested in the final polynomials, please refer to transform().
Source code in nlft_qsp/nlft.py
PhaseFactors
¶
Set of phase factors for a general Quantum Signal Processing protocol. It also provides methods to construct polynomials generated by QSP protocols. Each subclass of this class represents a different QSP ansatz.
Methods:
| Name | Description |
|---|---|
degree |
Returns the degree of the polynomials generated by the QSP protocol. |
iX |
Returns a new QSP protocol, obtained by multiplying the given QSP protocol by \(iX\) on the right, where \(X\) is the Pauli matrix. |
iY |
Returns a new QSP protocol, obtained by multiplying the given QSP protocol by \(iY\) on the right, where \(Y\) is the Pauli matrix. |
iZ |
Returns a new QSP protocol, obtained by multiplying the given QSP protocol by \(iZ\) on the right, where \(Z\) is the Pauli matrix. |
polynomials |
Returns the pair of polynomials \((P, Q)\) generated by the given set of phase factors. |
polynomials_bounds |
Returns the pair of polynomials \((P, Q) = A_{inf} \tilde{v} A_{inf+1} \tilde{v} ... \tilde{v} A_{sup-1} \tilde{v} A_{sup}\), |
processing_operator |
Returns the \(k\)-th signal processing operator according to the given QSP variant. |
processing_operator_conjugation |
This applies a conjugation to each signal processing operator returned by |
protocol_conjugation |
Given \((P, Q)\), this applies a final conjugation to the whole protocol, e.g., with the Hadamard gate. |
signal_operator |
Returns the pair of polynomials given by multiplying \((P_1, Q_1) W(z) (P_2, Q_2)\), where |
to_nlfs |
Returns the nonlinear Fourier sequence generating \((z^{-n} P, Q)\), |
Source code in nlft_qsp/qsp.py
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 130 131 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 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 | |
degree()
¶
iX()
¶
Returns a new QSP protocol, obtained by multiplying the given QSP protocol by \(iX\) on the right, where \(X\) is the Pauli matrix. This will make the generated polynomials undergo the transformation \((P, Q) \rightarrow (iQ, iP)\). This method is useful to bring to swap the places of the two polynomials, to switch between NLFT and QSP conventions.
Raises:
| Type | Description |
|---|---|
ValueError
|
if multiplying by \(iX\) does not preserve the subalgebra of the phase factors. |
Source code in nlft_qsp/qsp.py
iY()
¶
Returns a new QSP protocol, obtained by multiplying the given QSP protocol by \(iY\) on the right, where \(Y\) is the Pauli matrix. This will make the generated polynomials undergo the transformation \((P, Q) \rightarrow (-Q, P)\). This method is useful to bring to swap the places of the two polynomials, to switch between NLFT and QSP conventions.
Raises:
| Type | Description |
|---|---|
ValueError
|
if multiplying by \(iY\) does not preserve the subalgebra of the phase factors. |
Source code in nlft_qsp/qsp.py
iZ()
¶
Returns a new QSP protocol, obtained by multiplying the given QSP protocol by \(iZ\) on the right, where \(Z\) is the Pauli matrix. This will make the generated polynomials undergo the transformation \((P, Q) \rightarrow (iP, -iQ)\). This method is useful to bring to swap the places of the two polynomials, to switch between NLFT and QSP conventions.
Raises:
| Type | Description |
|---|---|
ValueError
|
if multiplying by \(iZ\) does not preserve the subalgebra of the phase factors. |
Source code in nlft_qsp/qsp.py
polynomials(inf: int = 0, sup: int = -1, mode: str = 'analytic') -> tuple[Polynomial, Polynomial]
¶
Returns the pair of polynomials \((P, Q)\) generated by the given set of phase factors. The polynomials are computed with a divide-and-conquer strategy (see here).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
Either |
'analytic'
|
Source code in nlft_qsp/qsp.py
polynomials_bounds(inf: int, sup: int) -> tuple[Polynomial, Polynomial]
¶
Returns the pair of polynomials \((P, Q) = A_{inf} \tilde{v} A_{inf+1} \tilde{v} ... \tilde{v} A_{sup-1} \tilde{v} A_{sup}\), where \(\tilde{v} = \mathrm{diag}(z, z^{-1})\) is the signal operator.
Note
This assumes the Laurent picture (\(\tilde{v} = \mathrm{diag}(z, z^{-1})\)). For the analytic picture \(\tilde{w} = \mathrm{diag}(z, 1)\) use polynomials().
Source code in nlft_qsp/qsp.py
processing_operator(k: int)
¶
processing_operator_conjugation(a, b)
¶
This applies a conjugation to each signal processing operator returned by processing_operator(), e.g., with the Hadamard gate.
This is done mainly to make processing_operator() return the operators as expressed by the original ansatze in the papers, while keeping computational efficiency and numerical stability.
Source code in nlft_qsp/qsp.py
protocol_conjugation(P, Q)
¶
Given \((P, Q)\), this applies a final conjugation to the whole protocol, e.g., with the Hadamard gate.
signal_operator(P1: Polynomial, Q1: Polynomial, P2: Polynomial, Q2: Polynomial) -> tuple[Polynomial, Polynomial]
¶
Returns the pair of polynomials given by multiplying \((P_1, Q_1) W(z) (P_2, Q_2)\), where W(z) is the signal operator.
Note
This might not reflect the signal operator as expressed in the original papers. Some basis transformations are implicitly made for computational efficiency.
Source code in nlft_qsp/qsp.py
to_nlfs() -> NonLinearFourierSequence
¶
Returns the nonlinear Fourier sequence generating \((z^{-n} P, Q)\), where \((P, Q)\) is the pair of polynomial generated by the given set of GQSP phase factors.
Note: if the phase factors are not canonical, then the phase of the leading coefficient of \(P\) is adjusted so that it becomes real and positive, and \((z^{-n} P, Q)\) is in the image of the NLFT.
Source code in nlft_qsp/qsp.py
Polynomial
¶
Bases: ComplexL0Sequence
Represents a general Laurent polynomial of one complex variable.
Attributes:
| Name | Type | Description |
|---|---|---|
coeffs |
list[complex_type]
|
List of complex coefficients. |
shape |
tuple
|
The shape of the coefficients. This is always |
support_start |
int
|
Minimum degree that appears in the polynomial. |
Methods:
| Name | Description |
|---|---|
__call__ |
Evaluates the polynomial using Horner's method. |
__init__ |
Initializes a Polynomial instance. |
__str__ |
Converts the polynomial to a human-readable string representation. |
analytic_part |
Discards all the negative degrees, keeping only the non-negative ones. |
anti_analytic_part |
Discards all the positive degrees, keeping only the non-positive ones. |
block_matrix |
Returns a matrix polynomial containing the given polynomials/constants as blocks. |
conjugate |
Returns the conjugate polynomial on the unit circle. If \(p(z) = \sum_k p_k z^k\), then its conjugate is defined as \(p^*(z) = \sum_k p_k^* z^{-k}\). This is also known as the Schwarz reflection across \(\mathbb{T}\). |
diagonal_block_matrix |
Returns a matrix polynomial containing the given polynomials/constants as blocks along the diagonal. |
duplicate |
Creates a duplicate of the current polynomial. |
effective_degree |
Returns the size of the support of the polynomial minus 1 (max degree - min degree). |
eval_at_roots_of_unity |
Evaluates the polynomial at the \(N\)-th roots of unity using the inverse fast Fourier transform. |
hilbert_transform |
Returns the polynomial \(Q\) such that \(P + Q\) yields an analytic polynomial (\(P\) being |
only_negative_degrees |
DEPRECATED: use |
only_positive_degrees |
DEPRECATED: use |
schwarz_transform |
Returns the anti-analytic polynomial whose real part gives the current polynomial. |
sharp |
Same as |
shift |
Creates a new polynomial equal to the current one, multiplied by |
sup_norm |
Estimates the supremum norm of the polynomial over the unit circle |
truncate |
Keeps only the coefficients in \([m, n]\), discarding the others. |
Source code in nlft_qsp/poly.py
207 208 209 210 211 212 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 299 300 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 366 367 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 426 427 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 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
__call__(z) -> complex_type | np.ndarray
¶
Evaluates the polynomial using Horner's method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
complex
|
The point at which to evaluate the polynomial. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
complex |
complex_type | ndarray
|
The evaluated result. |
Source code in nlft_qsp/poly.py
__init__(coeffs: list[complex_type] | np.ndarray = None, support_start: int = 0, shape: tuple[int] = None)
¶
Initializes a Polynomial instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeffs
|
list[complex_type] | ndarray
|
List of complex numbers as coefficients. |
None
|
shape
|
optional
|
Shape of the coefficient array. |
None
|
support_start
|
optional
|
Minimum degree in the polynomial. Defaults to 0. |
0
|
Note
Please provide exactly one of coeffs or shape.
Source code in nlft_qsp/poly.py
__str__() -> str
¶
Converts the polynomial to a human-readable string representation.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the polynomial. |
Source code in nlft_qsp/poly.py
analytic_part() -> Polynomial
¶
Discards all the negative degrees, keeping only the non-negative ones.
Returns:
| Name | Type | Description |
|---|---|---|
Polynomial |
Polynomial
|
A new polynomial containing only the positive-degree coefficients. |
Source code in nlft_qsp/poly.py
anti_analytic_part() -> Polynomial
¶
Discards all the positive degrees, keeping only the non-positive ones.
Returns:
| Name | Type | Description |
|---|---|---|
Polynomial |
Polynomial
|
A new polynomial containing only the non-positive-degree coefficients. |
Source code in nlft_qsp/poly.py
block_matrix(blocks: list[list[Polynomial]])
classmethod
¶
Returns a matrix polynomial containing the given polynomials/constants as blocks.
Raises: ValueError if the block shapes do not match.
Source code in nlft_qsp/poly.py
conjugate() -> Polynomial
¶
Returns the conjugate polynomial on the unit circle. If \(p(z) = \sum_k p_k z^k\), then its conjugate is defined as \(p^*(z) = \sum_k p_k^* z^{-k}\). This is also known as the Schwarz reflection across \(\mathbb{T}\).
Note
For a matrix polynomial, each coefficient is conjugate-transposed.
Source code in nlft_qsp/poly.py
diagonal_block_matrix(blocks: list[Polynomial])
classmethod
¶
Returns a matrix polynomial containing the given polynomials/constants as blocks along the diagonal.
Raises: ValueError if the block shapes do not match.
Source code in nlft_qsp/poly.py
duplicate() -> Polynomial
¶
Creates a duplicate of the current polynomial.
Returns:
| Name | Type | Description |
|---|---|---|
Polynomial |
Polynomial
|
A new Polynomial instance with the same coefficients and support. |
effective_degree() -> int
¶
Returns the size of the support of the polynomial minus 1 (max degree - min degree).
Note
This does not check for leading or trailing zeros in the coefficient array.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The effective degree of the polynomial. |
Source code in nlft_qsp/poly.py
eval_at_roots_of_unity(N: int) -> list[complex_type]
¶
Evaluates the polynomial at the \(N\)-th roots of unity using the inverse fast Fourier transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
A power of two specifying the number of roots. If \(N\) is not a power of two, then the next power of two is implicitly taken. |
required |
Returns:
| Type | Description |
|---|---|
list[complex_type]
|
list[complex]: List of evaluations at the N-th roots of unity. |
list[complex_type]
|
The \(k\)-th element of the list will be \(P(e^{2\pi i k/N})\), \(P\) being |
Source code in nlft_qsp/poly.py
hilbert_transform() -> Polynomial
¶
Returns the polynomial \(Q\) such that \(P + Q\) yields an analytic polynomial (\(P\) being self).
Note
This is actually \(i \mathcal{H}[P]\), i.e., the Hilbert transform as returned is already multiplied by \(i\).
Source code in nlft_qsp/poly.py
only_negative_degrees() -> Polynomial
¶
only_positive_degrees() -> Polynomial
¶
schwarz_transform() -> Polynomial
¶
Returns the anti-analytic polynomial whose real part gives the current polynomial.
Note
This is equivalent to adding $i \mathcal{H}[p]`, where \(\mathcal{H}[p]\) is the Hilbert transform of \(p\).
Source code in nlft_qsp/poly.py
sharp() -> Polynomial
¶
Same as conjugate(), but support_start is left unchanged.
Returns:
| Name | Type | Description |
|---|---|---|
Polynomial |
Polynomial
|
The sharp-conjugate polynomial. |
shift(k: int)
¶
sup_norm(N=1024) -> float_type
¶
Estimates the supremum norm of the polynomial over the unit circle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
the number of samples to compute the maximum from. If \(N\) is not a power of two, then the next power of two is taken. |
1024
|
Returns:
| Name | Type | Description |
|---|---|---|
float_type |
float_type
|
An estimate for the supremum norm of the polynomial over the unit circle. |
Source code in nlft_qsp/poly.py
truncate(m: int, n: int) -> Polynomial
¶
Keeps only the coefficients in \([m, n]\), discarding the others.
Returns:
| Name | Type | Description |
|---|---|---|
Polynomial |
Polynomial
|
A new, truncated polynomial. |
Source code in nlft_qsp/poly.py
QSVTPhaseFactors
¶
Bases: ChebyshevQSPPhaseFactors
Phase factors for a QSVT/Reflection QSP protocol.
with the Hermitian signal operator \(\tilde{r}\):
Note
This is the ansatz of Corollary 8 arXiv:1806.01838, but the polynomial construction is implemented by implicitly adjusting the phase factors from Chebyshev QSP, see arXiv:2105.02859, (A5).
Methods:
| Name | Description |
|---|---|
approximate |
Approximate the given callable object \(f\) (which takes \(x \in [-1, 1]\) and returns a real number) |
from_chebqsp |
Returns a set of QSVT phase factors constructing the same left chebyshev expansion as the given QSP protocol. |
solve |
Returns the set of phase factors for a QSVT protocol implementing the polynomial \(P(x)\) (as the real part of the top-left polynomial, see Theorem 9 of arXiv:2105.02859). |
to_chebqsp |
Returns a set of Chebyshev QSP phase factors constructing the same left chebyshev expansion as the given QSVT protocol. |
Source code in nlft_qsp/qsp.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 | |
approximate(f: Callable, deg: int) -> QSVTPhaseFactors
classmethod
¶
Approximate the given callable object \(f\) (which takes \(x \in [-1, 1]\) and returns a real number)
and returns the QSVT phase factors implementing an approximating polynomial of degree deg
(as the real part of the top-left polynomial, see Theorem 9 of arXiv:2105.02859).
Note: The parity of deg should coincide with the parity of \(f\), otherwise the Chebyshev approximator might give numerical errors.
Source code in nlft_qsp/qsp.py
from_chebqsp(pf: ChebyshevQSPPhaseFactors)
classmethod
¶
Returns a set of QSVT phase factors constructing the same left chebyshev expansion as the given QSP protocol.
Source code in nlft_qsp/qsp.py
solve(T: list[complex_type] | Polynomial | ChebyshevTExpansion) -> QSVTPhaseFactors
classmethod
¶
Returns the set of phase factors for a QSVT protocol implementing the polynomial \(P(x)\) (as the real part of the top-left polynomial, see Theorem 9 of arXiv:2105.02859).
The target polynomial will be \(T(x) = \sum_{k = 0}^n c_k T_k(x)\) (if T is a ChebyshevTExpansion) or \(T(x) = \sum_{k = 0}^n c_k x^k\) (if T is a Polynomial), where \(T_k(x)\) are the Chebyshev polynomials of the first kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
list[complex_type] | Polynomial | ChebyshevTExpansion
|
a Chebyshev expansion object or the desired Polynomial \(P(x)\) (that will be converted to the Chebyshev basis). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target polynomial does not have definite parity or is not real. |
Note
T can also be a list of complex numbers. This will be regarded as coefficients in the Chebyshev basis. Passing the list directly is discouraged and will be removed in future releases.
Source code in nlft_qsp/qsp.py
to_chebqsp() -> ChebyshevQSPPhaseFactors
¶
Returns a set of Chebyshev QSP phase factors constructing the same left chebyshev expansion as the given QSVT protocol.
Source code in nlft_qsp/qsp.py
XQSPPhaseFactors
¶
Bases: PhaseFactors
Phase factors for a XQSP protocol.
where \(W(z) = \mathrm{diag}(z, 1)\) (mode='analytic') or \(W(z) = \mathrm{diag}(z, z^{-1})\) (mode='laurent').
Methods:
| Name | Description |
|---|---|
from_nlfs |
Computes the XQSP phase factors for a given imaginary NLFT sequence. |
solve |
Returns the set of phase factors for a XQSP protocol producing the given polynomial. See here for an overview of the QSP variants. |
solve_laurent |
Returns the set of phase factors for a XQSP protocol producing the given definite-parity Laurent polynomial. See here for an overview of the QSP variants. |
Source code in nlft_qsp/qsp.py
203 204 205 206 207 208 209 210 211 212 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 299 300 301 302 303 304 305 | |
from_nlfs(F: NonLinearFourierSequence) -> PhaseFactors
classmethod
¶
Computes the XQSP phase factors for a given imaginary NLFT sequence. If \(\mathrm{NLFT}(F) = (a, b)\), then the returned phase factors will implement \((z^n a, b)\) in the analytic picture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
NonLinearFourierSequence
|
The imaginary sequence to be converted to phase factors. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if \(F\) is not imaginary. |
Note
The support start of \(F\) is ignored, so the support of \(b\) is assumed to start at \(0\).
Source code in nlft_qsp/qsp.py
solve(P: Polynomial, convention='qsp') -> XQSPPhaseFactors
classmethod
¶
Returns the set of phase factors for a XQSP protocol producing the given polynomial. See here for an overview of the QSP variants. A complementary \(Q\) will be computed with Weiss' algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convention
|
str
|
Whether the phase factors should produce \((P, Q)\) ( |
'qsp'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If \(P\) does not lie in the XQSP subalgebra. |
Note
The sup norm of \(P\) should be bounded by \(1 - \eta < 1\). The time required by the algorithm to compute the phase factors will scale with \(1/\eta\).
The support_start of \(P\) will be ignored. This is a solver for analytic QSP. In order to obtain phase factors for Laurent XQSP, use XQSPPhaseFactors.solve_laurent().
Source code in nlft_qsp/qsp.py
solve_laurent(P: Polynomial, convention='qsp') -> XQSPPhaseFactors
classmethod
¶
Returns the set of phase factors for a XQSP protocol producing the given definite-parity Laurent polynomial. See here for an overview of the QSP variants. A complementary \(Q\) will be computed with Weiss' algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convention
|
str
|
Whether the phase factors should produce \((P, Q)\) ( |
'qsp'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If \(P\) does not lie in the X-constrained subalgebra or \(P\) has not definite-parity. |
Note
The sup norm of \(P\) should be bounded by \(1 - \eta < 1\). The time required by the algorithm to compute the phase factors will scale with \(1/\eta\).
The support_start of \(P\) will be ignored. In order to obtain phase factors for Laurent XQSP, first convert the polynomial into analytic form.
Source code in nlft_qsp/qsp.py
YQSPPhaseFactors
¶
Bases: PhaseFactors
Phase factors for a YQSP protocol.
where \(W(z) = \mathrm{diag}(z, 1)\) (mode='analytic') or \(W(z) = \mathrm{diag}(z, z^{-1})\) (mode='laurent').
Methods:
| Name | Description |
|---|---|
from_nlfs |
Computes the YQSP phase factors for a given real NLFT sequence. |
solve |
Returns the set of phase factors for a YQSP protocol producing the given polynomial. See here for an overview of the QSP variants. |
solve_laurent |
Returns the set of phase factors for a YQSP protocol producing the given definite-parity polynomial. See here for an overview of the QSP variants. |
Source code in nlft_qsp/qsp.py
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 366 367 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 | |
from_nlfs(F: NonLinearFourierSequence) -> PhaseFactors
classmethod
¶
Computes the YQSP phase factors for a given real NLFT sequence. If \(\mathrm{NLFT}(F) = (a, b)\), then the returned phase factors will implement \((z^n a, b)\) in the analytic picture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
NonLinearFourierSequence
|
The real sequence to be converted to phase factors. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if \(F\) is not real. |
Note
The support start of \(F\) is ignored, so the support of \(b\) is assumed to start at \(0\).
Source code in nlft_qsp/qsp.py
solve(P: Polynomial, convention='qsp') -> YQSPPhaseFactors
classmethod
¶
Returns the set of phase factors for a YQSP protocol producing the given polynomial. See here for an overview of the QSP variants. A complementary \(Q\) will be computed with Weiss' algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convention
|
str
|
Whether the phase factors should produce \((P, Q)\) ( |
'qsp'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If \(P\) does not lie in the YQSP subalgebra. |
Note
The sup norm of \(P\) should be bounded by \(1 - \eta < 1\). The time required by the algorithm to compute the phase factors will scale with \(1/\eta\).
The support_start of \(P\) will be ignored. This is a solver for analytic QSP. In order to obtain phase factors for Laurent YQSP, use YQSPPhaseFactors.solve_laurent().
Source code in nlft_qsp/qsp.py
solve_laurent(P: Polynomial, convention='qsp') -> YQSPPhaseFactors
classmethod
¶
Returns the set of phase factors for a YQSP protocol producing the given definite-parity polynomial. See here for an overview of the QSP variants. A complementary \(Q\) will be computed with Weiss' algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convention
|
str
|
Whether the phase factors should produce \((P, Q)\) ( |
'qsp'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If \(P\) does not lie in the YQSP subalgebra or \(P\) has not definite-parity. |
Note
The sup norm of \(P\) should be bounded by \(1 - \eta < 1\). The time required by the algorithm to compute the phase factors will scale with \(1/\eta\).
Source code in nlft_qsp/qsp.py
chebqsp_approximate(f, deg: int) -> ChebyshevQSPPhaseFactors
¶
chebqsp_solve(T: list[complex_type] | ChebyshevTExpansion) -> ChebyshevQSPPhaseFactors
¶
chebyshev_approximate(f: Callable, N: int) -> ChebyshevTExpansion
¶
Computes the Chebyshev expansion up to \(N\) for a complex-valued function \(f : [-1, 1] \rightarrow \mathbb{C}\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable
|
complex-valued function f(x) |
required |
N
|
int
|
degree of Chebyshev approximation |
required |
Source code in nlft_qsp/approximate.py
fourier_approximate(f: Callable, N: int) -> Polynomial
¶
Computes the Fourier series of the given function \(f(z)\), \(z = e^{i\theta}\) being a complex number of unit modulus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Callable
|
a function taking a complex number \(z\) and returning a complex number. |
required |
N
|
int
|
The degree of approximation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Polynomial |
Polynomial
|
A Laurent polynomial of degrees in \(\{-N, N+1, \ldots, N-1\}\) approximating \(f\) |
Source code in nlft_qsp/approximate.py
gqsp_solve(P: Polynomial, mode='qsp') -> GQSPPhaseFactors
¶
plot_chebyshev(funcs: dict, num_points: int = 1000)
¶
Plots the real part of each object in funcs over the interval \([-1, 1]\).
These can be Python functions, Polynomial objects, ChebyshevTExpansion objects, or
any callable object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
funcs
|
dict
|
a dictionary where each key is the name appearing in the legend of the corresponding function plot. |
required |
num_points
|
int
|
number of sampling points. |
1000
|
Source code in nlft_qsp/plot.py
plot_fourier(funcs: dict, num_points: int = 1000)
¶
Plots the absolute value of each object in funcs over the unit circle, i.e., plugging \(z = e^{it}\) for \(t \in [-\pi, \pi]\).
These can be Python functions, Polynomial objects, or any callable object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
funcs
|
dict
|
a dictionary where each key is the name appearing in the legend of the corresponding function plot. |
required |
num_points
|
int
|
number of sampling points. |
1000
|