## PyZX
[![Unitary Fund](https://img.shields.io/badge/Supported%20By-UNITARY%20FUND-brightgreen.svg?style=for-the-badge)](http://unitary.fund)
[![CQC Support](https://github.com/Quantomatic/pyzx/raw/master/images/cqc-banner-small.png)](https://cambridgequantum.com/)
[![PyPI version](https://badge.fury.io/py/pyzx.svg)](https://badge.fury.io/py/pyzx)
PyZX (pronounce as *Pisics*) is a **Py**thon tool implementing the theory of **ZX**-calculus for the creation, visualisation, and automated rewriting of large-scale quantum circuits. Please watch [this 2-minute video](https://www.youtube.com/watch?v=iC-KVdB8pf0) for a short introduction.
PyZX currently allows you to:
* Read in quantum circuits in the file format of [QASM](https://en.wikipedia.org/wiki/OpenQASM), [Quipper](https://www.mathstat.dal.ca/~selinger/quipper/doc/) or [Quantomatic](https://quantomatic.github.io/).
* Rewrite circuits into a pseudo-normal form using the ZX-calculus.
* Extract new simplified circuits from these reduced graphs.
* Visualise the ZX-graphs and rewrites using either [Matplotlib](https://matplotlib.org/), Quantomatic or as a TikZ file for use in LaTeX documents.
* Output the optimised circuits in QASM, QC or QUIPPER format.
You can try out the in-browser demo which shows some of these features [here](http://zxcalculus.com/pyzx.html).
## About the ZX-calculus
ZX-diagrams are a type of tensor network built out of combinations of linear maps known as *spiders*. There are 2 types of spiders: the Z-spiders (represented as green dots in PyZX) and the X-spiders (represented as red dots). Every linear map between some set of qubits can be represented by a ZX-diagram.
The ZX-calculus is a set of rewrite rules for ZX-diagrams. There are various extensive set of rewrite rules. PyZX however, uses only rewrite rules concerning the Clifford fragment of the ZX-calculus. Importantly, this set of rewrite rules is *complete* for Clifford diagrams, meaning that two representations of a Clifford map can be rewritten into one another if and only if the two linear maps they represent are equal.
[Here](http://zxcalculus.com) is a website with resources and information about the ZX-calculus. For a short introduction to the ZX-calculus see [this paper](https://arxiv.org/abs/1602.04744) while for a complete overview we recommend [this book](https://www.amazon.com/Picturing-Quantum-Processes-Diagrammatic-Reasoning/dp/110710422X). PyZX extensively uses two derived rewrite rules known as *local complementation* and *pivoting*. More information about these operations can be found in [this paper](https://arxiv.org/abs/1307.7048).
## Installation
If you wish to use PyZX as a Python module for use in other projects, we recommend installing via pip:
```
pip install pyzx
```
If you want to use the demos or the benchmark circuits you should install PyZX from source by cloning the git repository.
PyZX has no strict dependencies, although some functionality requires numpy. PyZX is built to interact well with Jupyter, so we additionally recommend you have Jupyter and matplotlib installed.
## Usage
See the [Documentation](https://pyzx.readthedocs.io/en/latest/) for a full overview of the features of PyZX.
If you have [Jupyter](https://jupyter.org/) installed you can use one of the demonstration notebooks in the demos folder for an illustration of what PyZX can do.
This is some example Python code for generating a random circuit, optimizing it, and finally displaying it:
```python
import pyzx as zx
qubit_amount = 5
gate_count = 80
#Generate random circuit of Clifford gates
circuit = zx.generate.cliffordT(qubit_amount, gate_count)
#If running in Jupyter, draw the circuit
zx.draw(circuit)
#Use one of the built-in rewriting strategies to simplify the circuit
zx.simplify.full_reduce(circuit)
#See the result
zx.draw(circuit)
```
PyZX can also be run from the commandline. To optimise a circuit you can for instance run
```python -m pyzx opt input_circuit.qasm```
## Attribution
If you wish to cite PyZX in an academic work, please cite the [accompanying paper](https://arxiv.org/abs/1904.04735):
<pre>
@inproceedings{kissinger2020Pyzx,
author = {Kissinger, Aleks and van de Wetering, John},
title = {{PyZX: Large Scale Automated Diagrammatic Reasoning}},
year = {2020},
booktitle = {{\rm Proceedings 16th International Conference on} Quantum Physics and Logic, {\rm Chapman University, Orange, CA, USA., 10-14 June 2019}},
editor = {Coecke, Bob and Leifer, Matthew},
series = {Electronic Proceedings in Theoretical Computer Science},
volume = {318},
pages = {229-241},
publisher = {Open Publishing Association},
doi = {10.4204/EPTCS.318.14}
}
</pre>
Here's a plane that says PYZX:
![PYZX](https://github.com/Quantomatic/pyzx/raw/master/images/F-PYZX.jpg)
Raw data
{
"_id": null,
"home_page": "https://github.com/Quantomatic/pyzx.git",
"name": "pyzx",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Quantomatic",
"author_email": "john@vdwetering.name",
"download_url": "https://files.pythonhosted.org/packages/93/b2/f040a8f6043ec574e38ef23c333506f9e5ae9c54701c4bed58551fb81c96/pyzx-0.8.0.tar.gz",
"platform": null,
"description": "## PyZX\r\n\r\n[![Unitary Fund](https://img.shields.io/badge/Supported%20By-UNITARY%20FUND-brightgreen.svg?style=for-the-badge)](http://unitary.fund)\r\n[![CQC Support](https://github.com/Quantomatic/pyzx/raw/master/images/cqc-banner-small.png)](https://cambridgequantum.com/)\r\n[![PyPI version](https://badge.fury.io/py/pyzx.svg)](https://badge.fury.io/py/pyzx)\r\n\r\nPyZX (pronounce as *Pisics*) is a **Py**thon tool implementing the theory of **ZX**-calculus for the creation, visualisation, and automated rewriting of large-scale quantum circuits. Please watch [this 2-minute video](https://www.youtube.com/watch?v=iC-KVdB8pf0) for a short introduction.\r\n\r\nPyZX currently allows you to:\r\n\r\n* Read in quantum circuits in the file format of [QASM](https://en.wikipedia.org/wiki/OpenQASM), [Quipper](https://www.mathstat.dal.ca/~selinger/quipper/doc/) or [Quantomatic](https://quantomatic.github.io/).\r\n* Rewrite circuits into a pseudo-normal form using the ZX-calculus.\r\n* Extract new simplified circuits from these reduced graphs.\r\n* Visualise the ZX-graphs and rewrites using either [Matplotlib](https://matplotlib.org/), Quantomatic or as a TikZ file for use in LaTeX documents.\r\n* Output the optimised circuits in QASM, QC or QUIPPER format.\r\n\r\nYou can try out the in-browser demo which shows some of these features [here](http://zxcalculus.com/pyzx.html).\r\n\r\n## About the ZX-calculus\r\n\r\nZX-diagrams are a type of tensor network built out of combinations of linear maps known as *spiders*. There are 2 types of spiders: the Z-spiders (represented as green dots in PyZX) and the X-spiders (represented as red dots). Every linear map between some set of qubits can be represented by a ZX-diagram.\r\nThe ZX-calculus is a set of rewrite rules for ZX-diagrams. There are various extensive set of rewrite rules. PyZX however, uses only rewrite rules concerning the Clifford fragment of the ZX-calculus. Importantly, this set of rewrite rules is *complete* for Clifford diagrams, meaning that two representations of a Clifford map can be rewritten into one another if and only if the two linear maps they represent are equal.\r\n\r\n[Here](http://zxcalculus.com) is a website with resources and information about the ZX-calculus. For a short introduction to the ZX-calculus see [this paper](https://arxiv.org/abs/1602.04744) while for a complete overview we recommend [this book](https://www.amazon.com/Picturing-Quantum-Processes-Diagrammatic-Reasoning/dp/110710422X). PyZX extensively uses two derived rewrite rules known as *local complementation* and *pivoting*. More information about these operations can be found in [this paper](https://arxiv.org/abs/1307.7048).\r\n\r\n\r\n## Installation\r\n\r\nIf you wish to use PyZX as a Python module for use in other projects, we recommend installing via pip:\r\n```\r\n pip install pyzx\r\n```\r\n\r\nIf you want to use the demos or the benchmark circuits you should install PyZX from source by cloning the git repository.\r\n\r\nPyZX has no strict dependencies, although some functionality requires numpy. PyZX is built to interact well with Jupyter, so we additionally recommend you have Jupyter and matplotlib installed.\r\n\r\n## Usage\r\n\r\nSee the [Documentation](https://pyzx.readthedocs.io/en/latest/) for a full overview of the features of PyZX.\r\n\r\nIf you have [Jupyter](https://jupyter.org/) installed you can use one of the demonstration notebooks in the demos folder for an illustration of what PyZX can do.\r\n\r\nThis is some example Python code for generating a random circuit, optimizing it, and finally displaying it:\r\n\r\n```python\r\nimport pyzx as zx\r\nqubit_amount = 5\r\ngate_count = 80\r\n#Generate random circuit of Clifford gates\r\ncircuit = zx.generate.cliffordT(qubit_amount, gate_count)\r\n#If running in Jupyter, draw the circuit\r\nzx.draw(circuit)\r\n#Use one of the built-in rewriting strategies to simplify the circuit\r\nzx.simplify.full_reduce(circuit)\r\n#See the result\r\nzx.draw(circuit)\r\n```\r\n\r\nPyZX can also be run from the commandline. To optimise a circuit you can for instance run\r\n```python -m pyzx opt input_circuit.qasm```\r\n\r\n## Attribution\r\n\r\nIf you wish to cite PyZX in an academic work, please cite the [accompanying paper](https://arxiv.org/abs/1904.04735):\r\n<pre>\r\n @inproceedings{kissinger2020Pyzx,\r\n author = {Kissinger, Aleks and van de Wetering, John},\r\n title = {{PyZX: Large Scale Automated Diagrammatic Reasoning}},\r\n year = {2020},\r\n booktitle = {{\\rm Proceedings 16th International Conference on} Quantum Physics and Logic, {\\rm Chapman University, Orange, CA, USA., 10-14 June 2019}},\r\n editor = {Coecke, Bob and Leifer, Matthew},\r\n series = {Electronic Proceedings in Theoretical Computer Science},\r\n volume = {318},\r\n pages = {229-241},\r\n publisher = {Open Publishing Association},\r\n doi = {10.4204/EPTCS.318.14}\r\n}\r\n</pre>\r\n\r\nHere's a plane that says PYZX:\r\n![PYZX](https://github.com/Quantomatic/pyzx/raw/master/images/F-PYZX.jpg)\r\n",
"bugtrack_url": null,
"license": "Apache2",
"summary": "Library for quantum circuit rewriting and optimisation using the ZX-calculus",
"version": "0.8.0",
"project_urls": {
"Homepage": "https://github.com/Quantomatic/pyzx.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f43732c79aa44a89eb1ea8d82fdb7710ad2ac7cbbd044e81c9b0502758dbeacd",
"md5": "7410861eaa3277289ba489a2c51b15f0",
"sha256": "0cfa2204fc96a06ede5efb5dd3931acf3b65c16a379fb75a7367864f89fc50f5"
},
"downloads": -1,
"filename": "pyzx-0.8.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7410861eaa3277289ba489a2c51b15f0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 345359,
"upload_time": "2024-02-14T16:50:41",
"upload_time_iso_8601": "2024-02-14T16:50:41.036254Z",
"url": "https://files.pythonhosted.org/packages/f4/37/32c79aa44a89eb1ea8d82fdb7710ad2ac7cbbd044e81c9b0502758dbeacd/pyzx-0.8.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "93b2f040a8f6043ec574e38ef23c333506f9e5ae9c54701c4bed58551fb81c96",
"md5": "407c8e5aefda27698e42dc47cd5c9ebb",
"sha256": "491bf1d652a356bfde75dae70f88a59c393e4da77700d941736059e82ef844c7"
},
"downloads": -1,
"filename": "pyzx-0.8.0.tar.gz",
"has_sig": false,
"md5_digest": "407c8e5aefda27698e42dc47cd5c9ebb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 311971,
"upload_time": "2024-02-14T16:50:42",
"upload_time_iso_8601": "2024-02-14T16:50:42.946179Z",
"url": "https://files.pythonhosted.org/packages/93/b2/f040a8f6043ec574e38ef23c333506f9e5ae9c54701c4bed58551fb81c96/pyzx-0.8.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-14 16:50:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Quantomatic",
"github_project": "pyzx",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "typing-extensions",
"specs": [
[
">=",
"3.7.4"
]
]
},
{
"name": "numpy",
"specs": [
[
">=",
"1.14"
]
]
},
{
"name": "matplotlib",
"specs": [
[
">=",
"2.2"
]
]
},
{
"name": "ipywidgets",
"specs": [
[
"<",
"8"
],
[
">=",
"7.5"
]
]
},
{
"name": "pyperclip",
"specs": [
[
">=",
"1.8.1"
]
]
},
{
"name": "sphinx",
"specs": [
[
">=",
"2.3"
],
[
"<",
"7"
]
]
},
{
"name": "sphinx_autodoc_typehints",
"specs": [
[
">=",
"1.10"
]
]
},
{
"name": "sphinx_rtd_theme",
"specs": [
[
">=",
"0.4"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.56.0"
]
]
},
{
"name": "types-tqdm",
"specs": [
[
"~=",
"4.66"
]
]
},
{
"name": "mypy",
"specs": [
[
">=",
"0.990"
]
]
},
{
"name": "nbsphinx",
"specs": [
[
"~=",
"0.9.3"
]
]
},
{
"name": "sphinxcontrib-svg2pdfconverter",
"specs": [
[
">=",
"1.2.2"
]
]
},
{
"name": "lark",
"specs": [
[
"~=",
"1.1.7"
]
]
}
],
"lcname": "pyzx"
}