Skip to main content

A platform for performing efficient simulations of nonlinear quantum photonic circuits.

Project description

quotonic

python license build tests docs wheels commits pre-commit black mypy coverage flake8

qpnn visualization

quotonic is a package created for studying nonlinear quantum photonic circuits, including yet not limited to, quantum photonic neural networks (QPNNs). It is designed to accommodate new circuit models that explore unknown capabilities, teaching all of us what can be accomplished when a handful of photons are combined with strong few-photon optical nonlinearities. We hope that you will use this package as a platform to begin answering pertinent research questions around nonlinear quantum photonic circuits like QPNNs. If you are able to do so, and would like to make additions here, please let us know! We would love for this package to grow, including many different models that can be explored in tandem.

When it comes to simulating quantum dynamics using classical computational resources, there is often a need to closely consider performance. Here, we write circuit models to be compatible with jax and thus owe a massive thank you to the developers at Google DeepMind. It is also necessary to mention and thank similar packages, each of which have inspired some of the code within quotonic.

The documentation for quotonic is live at jewaniuk.github.io/quotonic. It was prepared using mkdocstrings with mkdocs-material.

Installation

You can install the latest release of quotonic from PyPI as

pip install quotonic

or install the latest development version from GitHub

pip install git+https://github.com/jewaniuk/quotonic.git

Getting Started

quotonic.qpnn contains a variety of models of QPNNs, the simplest of which is IdealQPNN, which follows their original proposal. Each model is accompanied by a trainer from quotonic.trainer, and can be trained to perform some task defined by a training set from quotonic.training_sets. In this example, we will train a two-layer, four-mode QPNN to act as a deterministic two-photon CNOT gate.

>>> from quotonic.qpnn import IdealQPNN
>>> from quotonic.trainer import IdealTrainer
>>> from quotonic.training_sets import CNOT

>>> n = 2  # number of photons
>>> m = 4  # number of optical modes
>>> L = 2  # number of network layers

We'll choose to perform one optimization trial that proceeds through 100 epochs.

>>> num_trials = 1  # number of optimization trials to perform
>>> num_epochs = 100  # number of epochs to train for per trial

Now, we simply prepare the training set, instantiate a QPNN followed by a trainer, then train!

>>> training_set = CNOT()
>>> qpnn = IdealQPNN(n, m, L, training_set=training_set)
>>> trainer = IdealTrainer(qpnn, num_trials, num_epochs)

>>> results = trainer.train()
Trial: 1
Epoch: 0 	 Cost: 9.3885e-01 	 Fidelity: 0.06115
Epoch: 10 	 Cost: 7.1853e-01 	 Fidelity: 0.2815
Epoch: 20 	 Cost: 6.6739e-01 	 Fidelity: 0.3326
Epoch: 30 	 Cost: 5.4786e-01 	 Fidelity: 0.4521
Epoch: 40 	 Cost: 4.2395e-01 	 Fidelity: 0.576
Epoch: 50 	 Cost: 3.0212e-01 	 Fidelity: 0.6979
Epoch: 60 	 Cost: 1.6486e-01 	 Fidelity: 0.8351
Epoch: 70 	 Cost: 7.8349e-02 	 Fidelity: 0.9217
Epoch: 80 	 Cost: 3.2369e-02 	 Fidelity: 0.9676
Epoch: 90 	 Cost: 1.2706e-02 	 Fidelity: 0.9873
Epoch: 100 	 Cost: 5.2117e-03 	 Fidelity: 0.9948
Epoch: 110 	 Cost: 2.0834e-03 	 Fidelity: 0.9979
Epoch: 120 	 Cost: 8.6629e-04 	 Fidelity: 0.9991
Epoch: 130 	 Cost: 3.8522e-04 	 Fidelity: 0.9996
Epoch: 140 	 Cost: 1.8960e-04 	 Fidelity: 0.9998
COMPLETE! 	 Cost: 1.1343e-04 	 Fidelity: 0.9999

This particular trial was able to tune the network parameters to achieve a fidelity of ~99.99%. The optimized parameters are passed back in results, so we can calculate the fidelity directly using them to check.

>>> qpnn.calc_fidelity(results["phi"][0], results["theta"][0], results["delta"][0])
Array(0.99989176, dtype=float32)

Example Usage

Here, we provide example scripts that illustrate the methodology used in our previous research on QPNNs.

Imperfect Quantum Photonic Neural Networks

import os

os.environ["XLA_FLAGS"] = "--xla_force_host_platform_device_count=8"

import numpy as np
from jax import config

config.update("jax_enable_x64", True)

from quotonic.qpnn import ImperfectQPNN
from quotonic.trainer import ImperfectTrainer
from quotonic.training_sets import BSA

n = 2
m = 4
L = 2
varphi = np.pi / 2

ell_mzi = (0.00861, 0.00057)  # (0.00861 +/- 0.00057) dB loss per MZI, sota model
ell_ps = (0.0015, 0.0001)  # (0.0015 +/- 0.0001) dB loss per phase shifter, sota model
t_dc = (0.5000, 0.0508)  # (50.00 +/- 5.08) % T:R directional coupler splitting ratio

num_trials = 200
num_epochs = 1000
print_every = 100

tset = BSA()
qpnn = ImperfectQPNN(n, m, L, varphi=varphi, ell_mzi=ell_mzi, ell_ps=ell_ps, t_dc=t_dc, training_set=tset)
trainer = ImperfectTrainer(qpnn, num_trials, num_epochs, print_every=print_every)

results = trainer.train()

Large-Scale Tree-Type Photonic Cluster State Generation with Recurrent Quantum Photonic Neural Networks

import os

os.environ["XLA_FLAGS"] = "--xla_force_host_platform_device_count=8"

import numpy as np
from jax import config

config.update("jax_enable_x64", True)

from quotonic.qpnn import TreeQPNN
from quotonic.trainer import TreeTrainer
from quotonic.training_sets import Tree

b = 2
n = b + 1
m = 2 * n
L = 2
varphi = (0.0, np.pi)

ell_mzi = (0.0210, 0.0016)  # (0.0210 +/- 0.0016) dB loss per MZI, multi model
ell_ps = (0.0100, 0.0006)  # (0.0100 +/- 0.0006) dB loss per phase shifter, multi model
t_dc = (0.50, 0.005)  # (50 +/- 0.5) % T:R directional coupler splitting ratio

num_trials = 200
num_epochs = 1000
print_every = 100

tset = Tree(b)
qpnn = TreeQPNN(b, L, varphi=varphi, ell_mzi=ell_mzi, ell_ps=ell_ps, t_dc=t_dc, training_set=tset)
trainer = TreeTrainer(qpnn, num_trials, num_epochs, print_every=print_every)

results = trainer.train()

Citing

Rather than citing the package directly, please cite the following works that it was developed for:

@article{Ewaniuk:23,
title   = {{Imperfect Quantum Photonic Neural Networks}},
author  = {Jacob Ewaniuk and Jacques Carolan and Bhavin J. Shastri and Nir Rotenberg},
journal = {Advanced Quantum Technologies},
volume  = {6},
pages   = {2200125},
year    = {2023},
doi     = {https://doi.org/10.1002/qute.202200125},
}
@misc{Ewaniuk:25,
title   = {{Large-Scale Tree-Type Photonic Cluster State Generation with Recurrent Quantum Photonic Neural Networks}},
author  = {Jacob Ewaniuk and Bhavin J. Shastri and Nir Rotenberg},
year    = {2025},
howpublished = {Preprint at https://arxiv.org/abs/2505.14628},
}

Authors

quotonic was initially created by Jacob Ewaniuk as part of his doctoral studies at Queen's University, working with the Quantum Nanophotonics Lab and Shastri Lab. Currently, it is in active use as a research tool by a number of graduate students in each of these research groups. As further contributions are made, additional authors will be listed here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quotonic-1.0.1.tar.gz (48.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quotonic-1.0.1-py3-none-any.whl (50.4 kB view details)

Uploaded Python 3

File details

Details for the file quotonic-1.0.1.tar.gz.

File metadata

  • Download URL: quotonic-1.0.1.tar.gz
  • Upload date:
  • Size: 48.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quotonic-1.0.1.tar.gz
Algorithm Hash digest
SHA256 edab1743d08aebce45f5a14427ff386e888222f6967479fab466bee6a6c1f230
MD5 ccaf3f5f3cec28fbdc6c37545640973e
BLAKE2b-256 df6e6ef835a5856c34071f047fe8d8c0c5f8c39bc2827ccd73f656ae14701b48

See more details on using hashes here.

Provenance

The following attestation bundles were made for quotonic-1.0.1.tar.gz:

Publisher: release.yml on jewaniuk/quotonic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quotonic-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: quotonic-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 50.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quotonic-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 798a8bf785cb44a2b21deccff565a3a7075ac1fa54b5dccd14369cd1ba225544
MD5 ff9a42959342a174cf06c80e0468ca3f
BLAKE2b-256 4bf46cb9dccfc99913a9ade62f7b825d303c9128cdf95f1e3286293d44fbf521

See more details on using hashes here.

Provenance

The following attestation bundles were made for quotonic-1.0.1-py3-none-any.whl:

Publisher: release.yml on jewaniuk/quotonic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page