QSVT 标准变换

oracq.algorithms.common.qsvt

Standard transformation library for quantum singular value transformation, QSVT (Gilyén et al. 2019, arXiv:1806.01838).

Conventions, aligned step by step with transforms.qsvt_sequence and verified pointwise against the reference simulator: on the two-dimensional invariant subspace of a singular value x, qsvt_sequence(a, Φ) realizes

p(x) = [S(φ_0) W(x) S(φ_1) W(x) … W(x) S(φ_d)]_00, W(x) = [[x, s], [s, -x]], s = √(1 − x²), S(φ) = diag(e^{iφ}, e^{−iφ}),

with the phases ordered in time, φ_0 acting first, for d block-encoding calls and d+1 phases in total. The pair, P and Q, is realizable if and only if deg P ≤ d, deg Q ≤ d−1, the parity of P equals d mod 2, the parity of Q equals (d−1) mod 2, and the polynomial identity P P̄ + (1−x²) Q Q̄ ≡ 1 holds; in particular |P(±1)| = 1 must hold, the endpoint saturation.

Phase synthesis follows the Gilyén paper's complementary-polynomial root finding plus layer stripping: given a real target f and an optional imaginary completion h, both real-coefficient polynomials, set P = f + i·h, construct Q from the roots of R = (1 − f² − h²)/(1−x²), then recover the phases by backward recursion. Real targets that do not saturate at the endpoints, such as truncated approximations of 1/x, must use a nonzero imaginary completion; the real part is then extracted by the LCU combination of (U_Φ + U_{−Φ})/2, where −Φ realizes exactly P̄, and the block encoding equals f(A/α).

Numerical boundaries: root finding uses pure-Python Durand–Kerner iteration and stripping uses double-precision complex arithmetic; the synthesis degree is capped at 40, and every synthesis is followed by a round-trip self-check with qsp_response that raises ValidationError beyond the limits. For degrees within a few tens and well-separated complementary-polynomial roots, the round-trip error is typically on the order of 1e-9.

The synthesis step is a replaceable component: qsp_phases and its upstream consumers accept an optional PhaseSynthesizer. The bundled route above remains the default and keeps its degree guard; a replacement synthesizer is not degree-guarded, but its output is held to the same convention by the round-trip self-check — exactly against P = f + i·h when an imaginary completion is pinned, and against Re p = f with a free completion otherwise.

class oracq.algorithms.common.qsvt.PhaseSynthesizer(*args, **kwargs)[源代码]

基类:Protocol

Callable contract for a replaceable QSP phase synthesis component.

A synthesizer receives the ascending real coefficients of the real target f (constant term first) and, when the imaginary completion is pinned, the ascending real coefficients of h; it returns the phase sequence in time order (first element acting first), with length d + 1 for a degree-d target, in the reflection convention of qsp_response.

Two conformance modes are distinguished by the imag argument:

  • Pinned completion (imag given): the realized top-left block must equal P = f + i·h exactly. The bundled root-finding route supports this mode; a synthesizer that cannot honor a pinned completion must raise ValidationError instead of returning an approximate answer.

  • Free completion (imag=None): only the real part is pinned, Re p = f; the synthesizer is free to choose any complementary imaginary part that keeps the pair realizable. This is the mode the library's consumers rely on, since the real-part extraction LCU makes the complementary part irrelevant to them.

Regardless of mode, qsp_phases validates the returned sequence against the required target on a Chebyshev grid before returning it.

oracq.algorithms.common.qsvt.eigenstate_filter(a, gap, degree, *, center=0.0, synthesizer=None)[源代码]

Eigenstate filtering: a peaked polynomial block encoding that suppresses the block below 1/T_d(r) outside |x−center| ≤ gap.

The target is the Lin–Tong filter polynomial f(x) = T_d(g(x²))/T_d(r), with g(y) = 2(y−Δ²)/(1−Δ²) − 1 and r = (1+Δ²)/(1−Δ²); f saturates at x=0, |f(0)|=1, and on |x| ≥ Δ it obeys |f| ≤ 1/T_d(r). A nonzero center first shifts the spectrum via a block-encoding linear combination.

参数:
  • a -- Block encoding of the input operator.

  • gap -- Filter half-width Δ, in (0,1); spectral components within Δ of the center are kept.

  • degree -- Chebyshev filter degree, a positive integer; the actual synthesis degree is twice it.

  • center -- Spectral position of the filter center, in (−1,1); 0 shifts no spectrum.

  • synthesizer -- Optional replacement for the bundled QSP phase synthesis route; when given, the bundled route's degree limit does not apply.

返回:

Peaked filter block encoding, with the suppression attribute 1/T_d(r).

返回类型:

BlockEncoding

QSVT assembly for fixed-point amplitude amplification: applies the phase sequence from fixed_point_search_phases to a block encoding.

The zero-signal block is the complex polynomial P(A/α), whose success probability |P(x)|² satisfies the YLC fixed-point guarantee; the threshold attribute gives the amplification threshold √(1−1/c²).

参数:
  • a -- The block encoding to amplify.

  • delta -- Failure probability bound δ, in (0,1).

  • degree -- Amplification degree, the number of block-encoding calls, a positive odd integer.

  • synthesizer -- Optional replacement for the bundled QSP phase synthesis route.

返回:

Fixed-point amplification block encoding whose zero-signal block is P(A/α).

返回类型:

BlockEncoding

oracq.algorithms.common.qsvt.fixed_point_search_phases(delta, degree, *, synthesizer=None)[源代码]

Phase sequence for Yoder–Low–Chuang fixed-point amplitude amplification, in time order with length degree+1.

The construction follows the closed-form YLC complementary polynomial: let L = degree, the number of block-encoding calls, which must be odd, and c = T_{1/L}(1/δ); then Q(x) = δc·R(c²(1−x²)) where R(u) = T_L(√u)/√u is an analytic polynomial, and P is obtained from the root-based spectral decomposition of 1 − (1−x²)Q². The realized success probability is exactly P_S(x) = 1 − δ² T_L²(c√(1−x²)): whenever |x| ≥ √(1−1/c²) we have P_S ≥ 1 − δ², and the threshold decreases monotonically in L toward 0, the fixed-point property.

With a replacement synthesizer the closed-form stripping is skipped; the synthesizer receives the real and imaginary parts of P separately (pinned-completion mode) and must reproduce P exactly, so the realized success probability remains exactly P_S.

参数:
  • delta -- Failure probability bound δ, in (0,1).

  • degree -- Amplification degree L, the number of block-encoding calls, a positive odd integer; the bundled route limits it to half the synthesis limit.

  • synthesizer -- Optional replacement for the bundled synthesis route; when given, the bundled route's degree limit does not apply.

返回:

Phase sequence in time order, with length degree+1.

返回类型:

tuple[float, ...]

oracq.algorithms.common.qsvt.qsp_phases(coeffs, imag=None, *, synthesizer=None)[源代码]

Synthesize a QSP phase sequence from a real-coefficient target polynomial, in time order with length d+1.

coeffs holds ascending real coefficients with the constant term first; the target is P = f when imag is None, or P = f + i·h when imag holds the ascending real coefficients of h. The realizability conditions are: f and h both have parity d mod 2; f² + h² ≤ 1 on [−1,1]; endpoint saturation f(±1)² + h(±1)² = 1; and R = (1 − f² − h²)/(1−x²) is nonnegative and satisfies the root multiplicity conditions of a spectral decomposition. Omitting imag means a purely real target, which then requires |f(±1)| = 1.

By default the bundled route — complementary-polynomial root finding plus layer stripping, guarded by the degree limit _MAX_DEGREE — produces the phases. A replacement synthesizer following the PhaseSynthesizer contract is not degree-guarded; its output is validated against the target by the same round-trip self-check. With a synthesizer and imag=None the completion is free: the endpoint-saturation and complementary-polynomial checks do not apply, and the self-check pins only the real part, Re p = f.

参数:
  • coeffs -- Ascending real coefficients of the target real part f, constant term first.

  • imag -- Ascending real coefficients of the imaginary completion h; omit for a purely real target.

  • synthesizer -- Optional replacement for the bundled synthesis route.

返回:

QSP phase sequence in time order, with length equal to the target degree plus one.

返回类型:

tuple[float, ...]

oracq.algorithms.common.qsvt.qsp_response(x, phases)[源代码]

Top-left block p(x) realized by the phase sequence Φ in the reflection convention, for x ∈ [−1, 1].

参数:
  • x -- Evaluation point, a real number in [−1, 1].

  • phases -- QSP phase sequence Φ, in radians.

返回:

Value of the response polynomial p(x) realized by the phase sequence.

返回类型:

complex

oracq.algorithms.common.qsvt.qsvt_hamiltonian_simulation(a, t, *, error=0.01, synthesizer=None)[源代码]

QSVT block encoding of e^{itA/α}: the Jacobi–Anger even and odd branches are synthesized separately and then combined by an LCU.

The even branch approximates cos(tx) and the odd branch approximates sin(tx); a common scale s leaves headroom for the imaginary completion of both branches. Each branch extracts the real part via (U_Φ + U_{−Φ})/2, and the two are finally combined by an LCU with weights 1 and i. The zero-signal block of the returned block encoding approximates e^{itA/α}/sim_scale, with sim_scale = 2s.

参数:
  • a -- Block encoding of the evolution generator A.

  • t -- Evolution time, a nonzero finite real number.

  • error -- Jacobi–Anger truncation and synthesis error, in (0,1).

  • synthesizer -- Optional replacement for the bundled QSP phase synthesis route; when given, the bundled route's truncation degree cap does not apply.

返回:

Block encoding whose zero-signal block approximates e^{itA/α}/sim_scale.

返回类型:

BlockEncoding

oracq.algorithms.common.qsvt.qsvt_matrix_inversion(a, kappa, *, error=0.05, synthesizer=None)[源代码]

QSVT block encoding approximating A⁻¹, a scaling of the odd extension polynomial J_b(x) = (1−(1−x²)^b)/x.

The target polynomial is f(x) = c·J_b(x), with ascending coefficients (−1)^m C(b, m+1) given analytically; it approximates c/x on |x| ≥ 1/κ with relative error at most error, and ||f||∞ ≤ 1/3. The zero-signal block of the returned block encoding approximates inverse_scale · A⁻¹, with inverse_scale = c·α.

参数:
  • a -- Block encoding of the matrix A to invert.

  • kappa -- Condition number κ, a finite number not less than 1.

  • error -- Relative approximation error, in (0,1).

  • synthesizer -- Optional replacement for the bundled QSP phase synthesis route; when given, the bundled route's degree limit does not apply.

返回:

Matrix inversion block encoding whose zero-signal block approximates inverse_scale·A⁻¹.

返回类型:

BlockEncoding