Skip to content

ARPAHLS/trainable-qsp-angles

 
 

Repository files navigation

Learning QSP Phase Angles via Gradient Descent

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.

License Python PennyLane JAX Optax

nbviewer Colab PennyLane Community


What This Is

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.

Setup

git clone https://github.com/rosspeili/qsp-pennylane-demo
cd qsp-pennylane-demo
pip install -r requirements.txt

Running the Demo

jupyter notebook demo.ipynb

Or run the tests:

pytest tests/ -v

Structure

qsp-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

Key Concepts

  • Signal oracle: W(x) = H @ RZ(-2*arccos(x)) @ H, encoding signal x ∈ (-1, 1) in the top-left matrix element
  • QSP sequence: Flat alternating circuit — one phase rotation RZ(-2*phi_k) per signal query W(x)
  • Polynomial encoding: The expectation value <X> encodes a degree-d polynomial in x determined 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.Hadamard gates, not qp.QSVT, to preserve JAX traceability

Target Polynomial

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).

Target polynomial vs. sin(x)

Results

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.

Training loss and learned polynomial

References

License

Apache 2.0. See LICENSE.


Press Release

📄 View the Press Release

About

Training Quantum Signal Processing phase angles from scratch using JAX gradient descent and PennyLane.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Jupyter Notebook 92.5%
  • Python 7.5%