A PennyLane QML Community Demo that demonstrates how Quantum Signal Processing (QSP) phase angles can be trained from random initialization using JAX automatic differentiation and Optax's Adam optimizer — no analytic angle solver required.
Quantum Signal Processing encodes polynomial transformations of a signal into a quantum circuit via a sequence of phase-shifted oracle calls. The standard approach computes the required phase angles analytically given a target polynomial. This demo takes the opposite route: it starts from random phase angles and trains them using gradient-based optimization (JAX + Optax) to recover a target polynomial transformation.
The result is a working recipe for practitioners who need to optimize QSP angles for novel polynomials where no analytic solver exists or where the polynomial is implicitly defined by a loss function.
git clone https://github.com/rosspeili/qsp-pennylane-demo
cd qsp-pennylane-demo
pip install -r requirements.txtjupyter notebook demo.ipynbOr run the tests:
pytest tests/ -vqsp-pennylane-demo/
├── demo.ipynb # Main community demo notebook
├── qsp_jax/
│ ├── __init__.py
│ └── circuit.py # Circuit construction and loss function
├── tests/
│ └── test_circuit.py # Unit tests
├── requirements.txt
├── LICENSE # Apache 2.0
└── README.md
- Signal oracle:
W(x) = H @ RZ(-2*arccos(x)) @ H, encoding signalx ∈ (-1, 1)in the top-left matrix element - QSP sequence: Flat alternating circuit — one phase rotation
RZ(-2*phi_k)per signal queryW(x) - Polynomial encoding: The expectation value
<X>encodes a degree-d polynomial inxdetermined by the phase angles - Training: Adam optimizer (Optax) minimizes MSE between circuit output and target polynomial via
jax.grad - Note: The circuit is implemented as inline
qp.RZ+qp.Hadamardgates, notqp.QSVT, to preserve JAX traceability
The default target is a degree-5 Chebyshev approximation of sin(x) on [-1, 1] — an odd polynomial bounded in [-1, 1], consistent with QSP conventions for odd-degree transformations. It has a maximum deviation of ~0.174 from the true sin(x).
After 500 Adam steps (lr=0.05, 64-point signal grid), the trained phase angles reproduce the target polynomial with:
- Final MSE: 4.82×10⁻⁴
- Max pointwise error: 9.83×10⁻²
Loss drops from ~1.44 (random initialization) to ~6.4×10⁻⁴, converging quickly within the first 100 steps.
- Martyn et al., A Grand Unification of Quantum Algorithms, PRX Quantum 2021
- Gilyen et al., Quantum singular value transformation, STOC 2019
Apache 2.0. See LICENSE.

