Skip to main content

Qiskit ZX Transpiler

A transpiler pass for Qiskit which uses ZX-Calculus for circuit optimization, implemented using PyZX.

Example usage

from qiskit.circuit import QuantumCircuit
from qiskit.transpiler import PassManager
from zxpass import ZXPass

# Create a qiskit `QuantumCircuit` here...
qc = QuantumCircuit(...)

zxpass = ZXPass()
pass_manager = PassManager(zxpass)
zx_qc = pass_manager.run(qc)

It is also possible to initialise ZXPass with a custom optimization function. (The default, if none is supplied, is to call pyzx.simplify.full_reduce on the graph of the circuit.)

import pyzx

def my_optimize(c: pyzx.Circuit) -> pyzx.Circuit:
    g = c.to_graph()
    # do stuff to simplify `g`...
    return pyzx.extract.extract_circuit(g)

zxpass = ZXPass(my_optimize)
pass_manager = PassManager(zxpass)
my_qc = pass_manager.run(qc)

The transpiler is also exposed as a pass manager stage plugin at the optimization stage.

from qiskit import transpile

zx_qc = transpile(qc, optimization_method="zxpass")

Running benchmarks

To perform some benchmarks based on the QASMBench suite, run the following:

cd benchmarking
python run_benchmarks.py

This will output some statistics and produce 2 PNG files showing the depth compression ratio between both Qiskit- and ZX-optimized circuits and the original circuits, and ratio of non-local gates beween the Qiskit- and ZX-optimized circuits.

Previous work

There have been two previous attempts to create a transpiler pass for Qiskit using PyZX which I'm aware of.

The first attempt was made in 2019 by @lia-approves, @edasgupta, and @ewinston when they were interns at IBM Quantum, as documented in this Qiskit issue. That code used qasm as an intermediate format when converting between a Qiskit DAGCircuit and a PyZX Circuit, which is undesirable for reasons noted in that issue. Furthermore, the code is out of date with subsequent changes made to both Qiskit and PyZX.

The second attempt was made by @gprs1809 et al. as a part of the Qiskit Advocate Mentorship Program (QAMP) in the fall of 2022. The code is found in this repository. This implementation converts a PyZX Circuit directly to a Qiskit QuantumCircuit, without going through qasm. However, the code is incomplete and produces the wrong output for some circuits (which may have been due to a difference between how PyZX and Qiskit implements certain gates, fixed in this PR), and (as far as I can tell) the code to convert in the other direction is not available.

Metadata

Release files for qiskit-zx-transpiler 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for qiskit-zx-transpiler 0.0.1
File Interpreter ABI Platform
qiskit_zx_transpiler-0.0.1-py3-none-any.whl Python 3 none any Details

Release files / qiskit_zx_transpiler-0.0.1-py3-none-any.whl

Download URL qiskit_zx_transpiler-0.0.1-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b58b6b1496df2c75af1ec7e31f42a20929cb909fe36783197cd661f7ac06f4b
BLAKE2b-256 checksum
How to use checksums
c70e7d438fb95f5b8823afb2f184140c28d4a5d0805909fe65bfb8ce1659dda4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page