qujax
qujax: Simulating quantum circuits with JAX - Published in JOSS (2023)
Science Score: 98.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 6 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Keywords from Contributors
Scientific Fields
Repository
Simulating quantum circuits with JAX
Basic Info
- Host: GitHub
- Owner: CQCL
- License: apache-2.0
- Language: Python
- Default Branch: develop
- Homepage: https://cqcl.github.io/qujax/
- Size: 4.3 MB
Statistics
- Stars: 71
- Watchers: 5
- Forks: 13
- Open Issues: 10
- Releases: 13
Topics
Metadata Files
README.md
qujax
Documentation | Installation | Quick start | Examples | Contributing | Citing qujax
qujax is a JAX-based Python library for the classical simulation of quantum circuits. It is designed to be simple, fast and flexible.
It follows a functional programming design by translating circuits into pure functions. This allows qujax to seamlessly interface with JAX, enabling direct access to its powerful automatic differentiation tools, just-in-time compiler, vectorization capabilities, GPU/TPU integration and growing ecosystem of packages.
qujax can be used both for pure and for mixed quantum state simulation. It not only supports the standard gate set, but also allows user-defined custom operations, including general quantum channels, enabling the user to e.g. model device noise and errors.
A summary of the core functionalities of qujax can be found in the Quick start section. More advanced use-cases, including the training of parameterised quantum circuits, can be found in the Examples section of the documentation.
Installation
qujax is hosted on PyPI and can be installed via the pip package manager
pip install qujax
Quick start
Important note: qujax circuit parameters are expressed in units of $\pi$ (e.g. in the range $[0,2]$ as opposed to $[0, 2\pi]$).
Start by defining the quantum gates making up the circuit, the qubits that they act on, and the indices of the parameters for each gate.
A list of all gates can be found here (custom operations can be included by passing an array or function instead of a string).
```python from jax import numpy as jnp import qujax
List of quantum gates
circuit_gates = ['H', 'Ry', 'CZ']
Indices of qubits the gates will be applied to
circuitqubitinds = [[0], [0], [0, 1]]
Indices of parameters each parameterised gate will use
circuitparamsinds = [[], [0], []]
qujax.printcircuit(circuitgates, circuitqubitinds, circuitparamsinds);
q0: -----H-----Ry[0]-----◯---
|
q1: ---------------------CZ--
```
Translate the circuit to a pure function param_to_st that takes a set of parameters and an (optional) initial quantum state as its input.
```python paramtost = qujax.getparamstostatetensorfunc(circuitgates, circuitqubitinds, circuitparams_inds)
paramtost(jnp.array([0.1]))
Array([[0.58778524+0.j, 0. +0.j],
[0.80901706+0.j, 0. +0.j]], dtype=complex64)
```
The optional initial state can be passed to param_to_st using the statetensor_in argument. When it is not provided, the initial state defaults to $\ket{0...0}$.
Map the state to an expectation value by defining an observable using lists of Pauli matrices, the qubits they act on, and the associated coefficients.
python
st_to_expectation = qujax.get_statetensor_to_expectation_func([['Z']], [[0]], [1.])
Combining param_to_st and st_to_expectation gives us a parameter to expectation function that can be automatically differentiated using JAX.
```python from jax import valueandgrad
paramtoexpectation = lambda param: sttoexpectation(paramtost(param)) expectationandgrad = valueandgrad(paramtoexpectation) expectationandgrad(jnp.array([0.1]))
(Array(-0.3090171, dtype=float32),
Array([-2.987832], dtype=float32))
```
Mixed state simulations are analogous to the above, but with calls to get_params_to_densitytensor_func and get_densitytensor_to_expectation_func instead.
A more in-depth version of the above can be found in the Getting started section of the documentation. More advanced use-cases, including the training of parameterised quantum circuits, can be found in the Examples section of the documentation.
Converting from TKET
A pytket circuit can be directly converted using the tk_to_qujax and tk_to_qujax_symbolic functions in the pytket-qujax extension. See pytket-qujax_heisenberg_vqe.ipynb for an example.
Contributing
You can open a bug report or a feature request by creating a new issue on GitHub.
Pull requests are welcome! To open a new one, please go through the following steps:
- First fork the repo and create your branch from
develop. - Commit your code and tests.
- Update the documentation, if required.
- Check the code lints (run
black . --checkandpylint */). - Issue a pull request into the
developbranch.
New commits on develop will be merged into
main in the next release.
Citing qujax
If you have used qujax in your code or research, we kindly ask that you cite it. You can use the following BibTeX entry for this:
bibtex
@article{qujax2023,
author = {Duffield, Samuel and Matos, Gabriel and Johannsen, Melf},
doi = {10.21105/joss.05504},
journal = {Journal of Open Source Software},
month = sep,
number = {89},
pages = {5504},
title = {{qujax: Simulating quantum circuits with JAX}},
url = {https://joss.theoj.org/papers/10.21105/joss.05504},
volume = {8},
year = {2023}
}
Owner
- Name: Cambridge Quantum
- Login: CQCL
- Kind: organization
- Location: Cambridge, UK
- Website: http://www.cambridgequantum.com
- Repositories: 48
- Profile: https://github.com/CQCL
Quantum Software and Technologies
JOSS Publication
qujax: Simulating quantum circuits with JAX
Authors
Quantinuum
Tags
JAX quantum computationCitation (CITATION.cff)
cff-version: "1.2.0"
authors:
- family-names: Duffield
given-names: Samuel
orcid: "https://orcid.org/0000-0002-8656-8734"
- family-names: Matos
given-names: Gabriel
orcid: "https://orcid.org/0000-0002-3373-0128"
- family-names: Johannsen
given-names: Melf
contact:
- family-names: Duffield
given-names: Samuel
orcid: "https://orcid.org/0000-0002-8656-8734"
doi: 10.5281/zenodo.8268973
message: If you use this software, please cite our article in the
Journal of Open Source Software.
preferred-citation:
authors:
- family-names: Duffield
given-names: Samuel
orcid: "https://orcid.org/0000-0002-8656-8734"
- family-names: Matos
given-names: Gabriel
orcid: "https://orcid.org/0000-0002-3373-0128"
- family-names: Johannsen
given-names: Melf
date-published: 2023-09-12
doi: 10.21105/joss.05504
issn: 2475-9066
issue: 89
journal: Journal of Open Source Software
publisher:
name: Open Journals
start: 5504
title: "qujax: Simulating quantum circuits with JAX"
type: article
url: "https://joss.theoj.org/papers/10.21105/joss.05504"
volume: 8
title: "qujax: Simulating quantum circuits with JAX"
GitHub Events
Total
- Watch event: 8
- Issue comment event: 1
- Push event: 1
- Pull request review event: 1
- Pull request event: 6
- Fork event: 3
- Create event: 4
Last Year
- Watch event: 8
- Issue comment event: 1
- Push event: 1
- Pull request review event: 1
- Pull request event: 6
- Fork event: 3
- Create event: 4
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Sam Duffield | s@m****m | 150 |
| Gabriel Matos | g****s@q****m | 28 |
| melf | c****c@m****e | 15 |
| dependabot[bot] | 4****] | 10 |
| Oliver Backhouse | o****e@g****m | 1 |
| Enrico Rinaldi | e****i@q****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 16
- Total pull requests: 109
- Average time to close issues: about 2 months
- Average time to close pull requests: 3 days
- Total issue authors: 3
- Total pull request authors: 7
- Average comments per issue: 0.94
- Average comments per pull request: 0.28
- Merged pull requests: 102
- Bot issues: 0
- Bot pull requests: 10
Past Year
- Issues: 0
- Pull requests: 3
- Average time to close issues: N/A
- Average time to close pull requests: 9 days
- Issue authors: 0
- Pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.33
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- SamDuffield (10)
- gamatos (5)
- tlaakkonen (1)
Pull Request Authors
- SamDuffield (56)
- gamatos (30)
- dependabot[bot] (14)
- cqc-melf (9)
- obackhouse (2)
- lucydot (2)
- erinaldiq (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 2,252 last-month
- Total dependent packages: 1
- Total dependent repositories: 1
- Total versions: 27
- Total maintainers: 1
pypi.org: qujax
Simulating quantum circuits with JAX
- Homepage: https://github.com/CQCL/qujax
- Documentation: https://qujax.readthedocs.io/
- License: Apache 2
-
Latest release: 1.1.0
published about 2 years ago
Rankings
Maintainers (1)
Dependencies
- sphinx *
- sphinx_rtd_theme *
- jax *
- jaxlib *
- sphinx >=3
- sphinx-autodoc-typehints *
- sphinx-rtd-theme >=1.0.0
- jax *
- actions/checkout v3 composite
- actions/download-artifact v3 composite
- actions/setup-python v4 composite
- actions/upload-artifact v3 composite
- pypa/gh-action-pypi-publish release/v1 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/upload-pages-artifact v1 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
