Library for quantum circuit rewriting and optimisation using the ZX-calculus
Project description
PyZX-Param
Note: This is a fork of PyZX with extensions for parameterized Pauli vertices, based on mjsutcliffe99/ParamZX. It can be installed alongside the original PyZX without conflicts.
PyZX (pronounce as Pisics) is a Python 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 for a short introduction.
PyZX currently allows you to:
- Read in quantum circuits in the file format of QASM, Quipper or Quantomatic.
- 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, 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.
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 is a website with resources and information about the ZX-calculus. For a short introduction to the ZX-calculus see this paper while for a complete overview we recommend this book. PyZX extensively uses two derived rewrite rules known as local complementation and pivoting. More information about these operations can be found in this paper.
Installation
If you wish to use PyZX-Param as a Python module for use in other projects, we recommend installing via pip:
pip install pyzx-param
This installs the module as pyzx_param, allowing it to coexist with the original pyzx:
import pyzx_param as zx # This fork
import pyzx # Original PyZX (if needed)
If you want to use the demos or the benchmark circuits you should install PyZX-Param from source by cloning the git repository.
PyZX-Param has no strict dependencies, although some functionality requires numpy. It is built to interact well with Jupyter, so we additionally recommend you have Jupyter and matplotlib installed.
Usage
See the Documentation for a full overview of the features of PyZX.
If you have Jupyter 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:
import pyzx_param 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-Param can also be run from the commandline. To optimise a circuit you can for instance run
python -m pyzx_param opt input_circuit.qasm
Attribution
This is a fork of PyZX by Aleks Kissinger and John van de Wetering. If you wish to cite PyZX in an academic work, please cite the original paper:
@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}
}
Here's a plane that says PYZX:
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyzx_param-0.9.1.tar.gz.
File metadata
- Download URL: pyzx_param-0.9.1.tar.gz
- Upload date:
- Size: 357.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d50dac3d2f1e0523573551aeb1105123952a86519b328aeee151fc8b256f4441
|
|
| MD5 |
104667dfc009b9e8a0c0604d2f073e79
|
|
| BLAKE2b-256 |
83fd7d5e164d381934fd20474ea1211784c3ad2715f53e2b3f5db534c4f71339
|
Provenance
The following attestation bundles were made for pyzx_param-0.9.1.tar.gz:
Publisher:
publish.yml on rafaelha/pyzx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyzx_param-0.9.1.tar.gz -
Subject digest:
d50dac3d2f1e0523573551aeb1105123952a86519b328aeee151fc8b256f4441 - Sigstore transparency entry: 868922847
- Sigstore integration time:
-
Permalink:
rafaelha/pyzx@aa5f4ecbacf38af2b023868f56c386e90eb39b0d -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/rafaelha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aa5f4ecbacf38af2b023868f56c386e90eb39b0d -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyzx_param-0.9.1-py3-none-any.whl.
File metadata
- Download URL: pyzx_param-0.9.1-py3-none-any.whl
- Upload date:
- Size: 393.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a90d65025f55cae6586c1cb5d3f6c17be6271e02e5ebdbb2e78117f1394ff28e
|
|
| MD5 |
bdb624fba1cdd99806906b533b0b920e
|
|
| BLAKE2b-256 |
22fe89b12a81be9c7c4c6b14776ff7414af0f53a38b77bdc7e8a5b4d9bd9a843
|
Provenance
The following attestation bundles were made for pyzx_param-0.9.1-py3-none-any.whl:
Publisher:
publish.yml on rafaelha/pyzx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyzx_param-0.9.1-py3-none-any.whl -
Subject digest:
a90d65025f55cae6586c1cb5d3f6c17be6271e02e5ebdbb2e78117f1394ff28e - Sigstore transparency entry: 868922849
- Sigstore integration time:
-
Permalink:
rafaelha/pyzx@aa5f4ecbacf38af2b023868f56c386e90eb39b0d -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/rafaelha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aa5f4ecbacf38af2b023868f56c386e90eb39b0d -
Trigger Event:
release
-
Statement type: