Skip to main content

qsvt_phases

qsvt_phases(
poly_coeffs: np.ndarray,
cheb_basis: bool = True,
tol: float = 1e-12
) -> np.ndarray
Get QSVT phases that will generate the given Chebyshev polynomial. The phases are ready to be used in qsvt and qsvt_lcu functions in the classiq library. The convention is the reflection signal operator, and the measurement basis is the hadamard basis (see https://arxiv.org/abs/2105.02859 APPENDIX A.). The current implementation is using the pyqsp package, based on techniques in https://arxiv.org/abs/2003.02831. Parameters:
NameTypeDescriptionDefault
poly_coeffsnp.ndarrayArray of polynomial coefficients (Chebyshev\Monomial, depending on cheb_basis).required
cheb_basisboolWhether the poly coefficients are given in Chebyshev (True) or Monomial(False). Defaults to Chebyshev.True
tolfloatError tolerance for the phases.1e-12

qsp_approximate

qsp_approximate(
f_target: Callable[[float], complex],
degree: int,
parity: int | None = None,
interval: tuple[float, float] = (-1, 1),
bound: float = 0.99,
num_grid_points: int | None = None,
plot: bool = False
) -> tuple[np.ndarray, float]
Approximate the target function on the given (sub-)interval of [-1,1], using QSP-compatible chebyshev polynomials. The approximating polynomial is enforced to |P(x)| <= bound on all of [-1,1]. Note: scaling f_target by a factor < 1 might help the convergence and also a later qsp phase factor finiding. Parameters:
NameTypeDescriptionDefault
f_targetCallable[[float], complex]Real function to approximate within the given interval. Should be bounded by [-1, 1] in the given interval.required
degreeintApproximating polynomial degree.required
parityint | NoneNone - full polynomial, 0 - restrict to even polynomial, 1 - odd polynomial.None
intervaltuple[float, float]sub interval of [-1, 1] to approximate the function within.(-1, 1)
boundfloatglobal polynomial bound on [-1,1] (defaults to 0.99).0.99
num_grid_pointsint | Nonesets the number of grid points used for the polynomial approximation (defaults to max(2 * degree, 1000)).None
plotboolA flag for plotting the resulting approximation vs the target function.False
Returns:
  • Type: tuple[np.ndarray, float]
  • Array of Chebyshev coefficients. In case of definite parity, still a full coefficients array is returned.
  • (Approximated) maximum error between the target function and the approximating polynomial within the interval.

gqsp_phases

gqsp_phases(
poly_coeffs: np.ndarray,
cheb_basis: bool = False
) -> list[tuple[float, float, float]]
Compute GQSP phases for a polynomial in the monomial (power) basis. The returned phases are compatible with Classiq’s gqsp function and use the Wz signal operator convention. The current implementation is using the nlft-qsp package, based on techniques in https://arxiv.org/abs/2503.03026. Notes:
  • The polynomial must be bounded on the unit circle: P(e{itheta})|P(e^\{i*theta\})| <= 1 for all theta in [0,2pi)[0, 2*pi).
  • Laurent polynomials are supported by degree shifting. If P(z)=sum{k=m}nckzkwithm<0,thephasescorrespondtotheP(z) = sum_\{k=m\}^n c_k * z^k with m < 0, the phases correspond to the degree-shifted polynomial z{m}P(z)z^\{-m\} * P(z) (so the minimal degree is zero).
  • The phase finiding works in the monomial basis. If a Chebyshev basis polynomial is provided, it will be converted to the monomial basis (and introduce an additional overhead).
Parameters:
NameTypeDescriptionDefault
poly_coeffsnp.ndarrayrequired
cheb_basisboolWhether the poly coefficients are given in Chebyshev (True) or Monomial(False). Defaults to Monomial.False
Returns:
  • Type: list[tuple[float, float, float]]
  • list of (theta, phi, lambda) tuples of length d+1, ready to use with gqsp.

poly_jacobi_anger_cos

poly_jacobi_anger_cos(
degree: int,
t: float
) -> np.ndarray
Gets the Chebyshev polynomial coefficients approximating cos(t*x) using the Jacobi-Anger expansion. cos(xt)=J0(t)+2{k=1}{d/2}(1)kJ{2k}(t)T{2k}(x)\cos(xt) = J_0(t) + 2\sum_\{k=1\}^\{d/2\} (-1)^k J_\{2k\}(t)\, T_\{2k\}(x) Parameters:
NameTypeDescriptionDefault
degreeintthe degree of the approximating polynomial.required
tfloatthe parameter in cos(t*x). Can be negative.required

poly_jacobi_anger_sin

poly_jacobi_anger_sin(
degree: int,
t: float
) -> np.ndarray
Gets the Chebyshev polynomial coefficients approximating sin(t*x) using the Jacobi-Anger expansion. sin(xt)=2{k=0}{d/2}(1)kJ{2k+1}(t)T{2k+1}(x)\sin(xt) = 2\sum_\{k=0\}^\{d/2\} (-1)^k J_\{2k+1\}(t)\, T_\{2k+1\}(x) Parameters:
NameTypeDescriptionDefault
degreeintthe degree of the approximating polynomial.required
tfloatthe parameter in sin(t*x).required

poly_jacobi_anger_exp_sin

poly_jacobi_anger_exp_sin(
degree: int,
t: float
) -> np.ndarray
Gets the Chebyshev polynomial coefficients approximating exp(itsin(x)) using the Jacobi-Anger expansion: e{itsin(x)}={k=d}{d}J{k}(t)e{ikx}e^\{it\sin(x)\} = \sum_\{k=-d\}^\{d\} J_\{k\}(t) e^\{ikx\} Parameters:
NameTypeDescriptionDefault
degreeintthe maximum degree of the approximating polynomial (negative and positive).required
tfloatthe parameter in exp(itsin(x)).required

poly_jacobi_anger_exp_cos

poly_jacobi_anger_exp_cos(
degree: int,
t: float
) -> np.ndarray
Gets the Chebyshev polynomial coefficients approximating exp(itcos(x)) using the Jacobi-Anger expansion: e{itcos(x)}={k=d}{d}ikJ{k}(t)e{ikx}e^\{it\cos(x)\} = \sum_\{k=-d\}^\{d\} i^k J_\{k\}(t) e^\{ikx\} Parameters:
NameTypeDescriptionDefault
degreeintthe maximum degree of the approximating polynomial (negative and positive).required
tfloatthe parameter in exp(itcos(x)).required

poly_inversion

poly_inversion(
degree: int,
kappa: float,
error_type: str | ErrorType = ErrorType.RELATIVE
) -> tuple[np.ndarray, float]
Gets the Chebyshev odd polynomial p(x) coefficients approximating 1/x on [1/kappa, 1]. Based on the papers: https://dl.acm.org/doi/pdf/10.1145/3649320 - for optimal polynomial that minimizes the relative error |xp(x)-1| for x in [1/kappa,1]; and https://arxiv.org/pdf/2507.15537- for optimal polynomial that minimizes the uniform error |p(x)-1/x| for x in [1/kappa,1]. The relative error refers to |xp(x)-1|, whereas the uniform error refers to |p(x)-1/x|, both for x in [1/kappa,1]. Parameters:
NameTypeDescriptionDefault
degreeintThe degree of the approximating polynomial.required
kappafloatThe number defining the interval [1/kappa, 1], usually represents the condition number in the setting of matrix inversion.required
error_typestr | ErrorTypeA string specifying the error type to minimize, can be either “relative” (default) or “uniform”.ErrorType.RELATIVE
Returns:
  • Type: tuple[np.ndarray, float]
  • The Chebyshev polynomial coefficients approximating 1/x on [1/kappa, 1] using the optimal polynomial of given degree.
  • An upper bound on the maximum absolute value of the polynomial on [-1, 1]. The value can be used to scale down the polynomial for the usage within QSVT.