This repository implements a continuous-variable (CV) quantum neural network realizing a Fock-space classifier, inspired by
M. Schuld et al., Quantum machine learning in feature Hilbert space.
The model embeds classical data into an infinite-dimensional (truncated) Fock space and performs linear classification in feature space using a non-Gaussian CV quantum circuit.
This project only works with specific pinned versions. Do not upgrade packages.
Tested on:
- Ubuntu 22.04
- Python 3.10
schuld_qml/
├── .venv/ # Python virtual environment (NOT committed)
├── qm_neural_net.py # Full Fock-space classifier (training + plots)
├── test_00.py # Backend sanity check (must return 0.0)
├── requirements.txt # Fully pinned dependency versions
└── README.mdcd schuld_qml
python3 -m venv .venv
source .venv/bin/activateYou must see:
(.venv)
pip install --upgrade pip
pip install -r requirements.txtRun:
python test_00.pyExpected output:
0.0
If and only if this prints 0.0, the environment is correct.
python qm_neural_net.pyThis will:
-
generate a two-moons dataset,
-
train a 2-mode Fock-space classifier using stochastic gradient descent,
-
plot:
- training loss vs optimization steps,
- decision regions showing ( p(y=1) ).
-
Feature map Classical input ( x \in \mathbb{R}^2 ) is encoded via displacement operators into a truncated 2-mode Fock space.
-
Feature space Infinite-dimensional bosonic Hilbert space, truncated numerically.
-
Variational circuit Repeated gate blocks consisting of:
- Beamsplitter (BS)
- Displacement (D)
- Quadratic phase (P)
- Cubic phase (C)
-
Measurement Photon number expectation value.
-
Loss Square loss with gentle ( \ell_2 ) regularization.
The classifier is:
- linear in Fock space,
- nonlinear in input space,
- non-Gaussian, due to cubic phase gates.
The program is guaranteed to work only with:
PennyLane==0.29.1
PennyLane-SF==0.20.1
strawberryfields==0.23.0
thewalrus==0.19.0
autoray==0.6.12
numpy==1.23.5
scipy==1.10.1
These versions are pinned in requirements.txt.
-
strawberryfields.fockdevice not found → EnsurePennyLane-SF==0.20.1is installed. -
SciPy import errors → Ensure
scipy==1.10.1. -
Autoray errors → Ensure
autoray==0.6.12.
If anything breaks, delete .venv/ and repeat the setup exactly.
If it runs once, freeze the environment and never upgrade dependencies.