qujax

qujax: Simulating quantum circuits with JAX - Published in JOSS (2023)

https://github.com/cqcl/qujax

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

jax python quantum

Keywords from Contributors

mesh

Scientific Fields

Engineering Computer Science - 32% confidence
Last synced: 4 months ago · JSON representation ·

Repository

Simulating quantum circuits with JAX

Basic Info
Statistics
  • Stars: 71
  • Watchers: 5
  • Forks: 13
  • Open Issues: 10
  • Releases: 13
Topics
jax python quantum
Created over 3 years ago · Last pushed 4 months ago
Metadata Files
Readme License Citation

README.md

qujax

PyPI - Version DOI

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:

  1. First fork the repo and create your branch from develop.
  2. Commit your code and tests.
  3. Update the documentation, if required.
  4. Check the code lints (run black . --check and pylint */).
  5. Issue a pull request into the develop branch.

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

Quantum Software and Technologies

JOSS Publication

qujax: Simulating quantum circuits with JAX
Published
September 12, 2023
Volume 8, Issue 89, Page 5504
Authors
Samuel Duffield ORCID
Quantinuum
Gabriel Matos ORCID
Quantinuum, University of Leeds
Melf Johannsen
Quantinuum
Editor
Lucy Whalley ORCID
Tags
JAX quantum computation

Citation (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

All Time
  • Total Commits: 205
  • Total Committers: 6
  • Avg Commits per committer: 34.167
  • Development Distribution Score (DDS): 0.268
Past Year
  • Commits: 2
  • Committers: 2
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.5
Top Committers
Name Email 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
good first issue (9) enhancement (7) documentation (7) bug (1)
Pull Request Labels
dependencies (14)

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

  • Versions: 27
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 2,252 Last month
Rankings
Dependent packages count: 4.7%
Stargazers count: 10.2%
Downloads: 10.4%
Average: 11.9%
Forks count: 12.6%
Dependent repos count: 21.8%
Maintainers (1)
Last synced: 4 months ago

Dependencies

.github/workflows/docs/requirements.txt pypi
  • sphinx *
  • sphinx_rtd_theme *
docs/requirements.txt pypi
  • jax *
  • jaxlib *
  • sphinx >=3
  • sphinx-autodoc-typehints *
  • sphinx-rtd-theme >=1.0.0
setup.py pypi
  • jax *
.github/workflows/build_and_test.yml actions
  • 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
.github/workflows/docs.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-pages-artifact v1 composite
.github/workflows/lint.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite