Git Product home page Git Product logo

dlyongemallo / qiskit-zx-transpiler Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 803 KB

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

License: Apache License 2.0

Python 86.82% Jupyter Notebook 12.65% Shell 0.53%
circuit-optimization qiskit quantum-circuit-synthesis quantum-compiler zx-calculus quantum-circuit-optimization quantum-transpiler

qiskit-zx-transpiler's Introduction

Qiskit ZX Transpiler

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

License PyPI - Python Version PyPI - Package Version CI Status

Example usage

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

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

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)

pass_manager = PassManager(ZXPass(my_optimize))
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.

qiskit-zx-transpiler's People

Contributors

dlyongemallo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

qiskit-zx-transpiler's Issues

use the "ground" operation in PyZX to handle hybrid quantum-classical circuits

Right now, the transpiler separates operations natively supported in PyZX from those which aren't, optimises the subset which is supported, and then splices everything back together. In particular, this is a common pattern: circuit = [A, measure, B, conditional subcircuit], where only A and B are optimised.

It might be possible to handle the measure and conditional subcircuit parts using the "ground" operation in PyZX.

See this paper for details: https://arxiv.org/abs/2109.06071

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.