cvqnn

Trains a continuous variable quantum neural network for binary classification with PyTorch.

18|3|Updated Aug 14, 2026
One-click install
npx skills add https://github.com/unitarylab/quantum-practices --skill cvqnn-unitarylab
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cvqnn
Source: https://github.com/unitarylab/quantum-practices/tree/main/algorithms/quantum-machine-learning/cvqnn
Command: npx skills add https://github.com/unitarylab/quantum-practices --skill cvqnn-unitarylab

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, torch, matplotlib, scikit-learn, unitarylab, and includes scripts (resource) components.

What problem does it solve? Implementing a Continuous Variable Quantum Neural Network (CVQNN) requires deep knowledge of CV quantum optics, truncated Fock space simulation, and gradient-based training of quantum circuit parameters. This Skill provides a complete, documented implementation of CVQNN for binary classification, covering encoding, variational layers, training, evaluation, and visualization. ## Core Features & Use Cases - End-to-End CVQNN Training: Encodes 2D features as coherent-state displacements, applies variational layers (beamsplitter, Kerr, displacement, squeezing, rotation), and trains with PyTorch Adam and MSE loss. - Fock Space Simulation: Builds CV gate unitaries (displacement, squeezing, rotation, Kerr) via torch.matrix_exp over complex128 matrices with configurable cutoff dimension. - Metrics and Visualization: Produces training loss curves, decision boundary plots, and circuit topology SVGs, returning accuracy, loss, and timing in a structured result dictionary. - Use Case: A quantum machine learning researcher wants to classify a two-moons dataset using a photonic quantum model. The Skill runs CVQNNAlgorithm with configurable layers, cutoff, epochs, and learning rate, returning final accuracy and saved plots. ## Quick Start Ask the AI to train a CVQNN classifier on a two-feature binary dataset such as sklearn's make_moons with 2 layers, cutoff 6, and 40 epochs, then report the final accuracy and loss.

Frequently Asked Questions about cvqnn

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I train a continuous variable quantum neural network for binary classification?

Use CVQNNAlgorithm.run with x_train of shape (N, 2) and binary labels, setting n_layers, cutoff, epochs, and learning rate. The model encodes features as coherent-state displacements, trains variational optical layers with PyTorch Adam and MSE loss, and returns final accuracy and loss.

What is a CVQNN in quantum machine learning?

A CVQNN is a quantum neural network built on continuous variable photonic modes rather than qubits. It encodes classical features as displacements in truncated Fock space and applies trainable layers of squeezing, displacement, rotation, Kerr nonlinearity, and beamsplitters, measuring the x-quadrature expectation as output.

Does CVQNN require PyTorch and what dependencies are needed?

Yes, PyTorch is required because all gate unitaries are computed via torch.matrix_exp over complex128 tensors and parameters are trained with autograd and Adam. The implementation also uses NumPy, matplotlib for plots, sklearn for demo datasets, and unitarylab Circuit for topology export.

Why is CVQNN training slow or running out of memory?

Two-mode operations use Kronecker products producing cutoff-squared by cutoff-squared matrices, so memory and time grow quadratically with the Fock cutoff. The default cutoff of 6 gives 36x36 matrices; raising it to 10 gives 100x100 and is roughly 7 times slower per forward pass.

What are the input limitations of the CVQNN classifier?

The classifier accepts exactly two input features because each sample is encoded as displacements on two optical modes. Datasets with more columns must be reduced, for example by passing x_train[:, :2], and labels must be binary integers 0 or 1.