Solver Module
The solver module provides the main functionality for solving Quantum Signal Processing (QSP) problems.
- qsppack.solver.solve(coef, parity, opts)[source]
Given coefficients of a polynomial P, yield corresponding phase factors.
The reference chose the first half of the phase factors as the optimization variables, while in the code we used the second half of the phase factors. These two formulations are equivalent.
To simplify the representation, a constant pi/4 is added to both sides of the phase factors when evaluating the objective and the gradient. In the output, the FULL phase factors with pi/4 are given.
- Parameters:
coef (array_like) – Coefficients of polynomial P under Chebyshev basis. P should be even/odd, only provide non-zero coefficients. Coefficients should be ranked from low order term to high order term.
parity (int) – Parity of polynomial P (0 – even, 1 – odd)
opts (dict, optional) –
Options dictionary with fields:
- criteriafloat
Stop criteria
- useRealbool
Use only real arithmetics if true
- targetPrebool
Want Pre to be target function if true
- method{‘LBFGS’, ‘FPI’, ‘Newton’}
Optimization method to use
- typePhi{‘full’, ‘reduced’}
Type of phase factors to return
- Returns:
phi_proc (ndarray) – Solution of optimization problem, FULL phase factors
out (dict) – Information of solving process containing:
- iterint
Number of iterations
- timefloat
Runtime in seconds
- valuefloat
Final error value
- parityint
Input parity value
- targetPrebool
Whether Pre was target function
- typePhistr
Type of phase factors returned
The solve function is the main entry point for QSP optimization. It takes a target polynomial and returns the optimized phase factors.
Example usage:
import numpy as np
from qsppack.solver import solve
# Define a target polynomial (e.g., P(x) = x)
target_poly = np.array([0, 1])
# Solve for phase factors
result = solve(target_poly, method='lbfgs')