qiskit-zx-transpiler


Nameqiskit-zx-transpiler JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummaryA transpiler pass for Qiskit which uses ZX-Calculus for circuit optimization, implemented using PyZX.
upload_time2024-04-07 17:37:34
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseApache 2.0
keywords qiskit zx-calculus quantum circuit optimization quantum computing
VCS
bugtrack_url
requirements pyzx matplotlib numpy pylatexenc pytest qiskit
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Qiskit ZX Transpiler

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

## Example usage

```python
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.)

```python
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.

```python
from qiskit import transpile

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

## Running benchmarks

To perform some benchmarks based on the [QASMBench](https://github.com/pnnl/QASMBench) suite, run the following:

```bash
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](https://github.com/lia-approves), [@edasgupta](https://github.com/edasgupta), and [@ewinston](https://github.com/ewinston)
when they were interns at IBM Quantum, as documented in [this Qiskit issue](https://github.com/Qiskit/qiskit/issues/4990).
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](https://github.com/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](https://github.com/gprs1809/ZX_to_DAG_QAMP_fall_2022).
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](https://github.com/Quantomatic/pyzx/pull/156)),
and (as far as I can tell) the code to convert in the other direction is not available.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "qiskit-zx-transpiler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "qiskit, zx-calculus, quantum circuit optimization, quantum computing",
    "author": null,
    "author_email": "David Yonge-Mallo <dlyongemallo@users.noreply.github.com>",
    "download_url": null,
    "platform": null,
    "description": "# Qiskit ZX Transpiler\n\nA transpiler pass for Qiskit which uses ZX-Calculus for circuit optimization, implemented using PyZX.\n\n## Example usage\n\n```python\nfrom qiskit.circuit import QuantumCircuit\nfrom qiskit.transpiler import PassManager\nfrom zxpass import ZXPass\n\n# Create a qiskit `QuantumCircuit` here...\nqc = QuantumCircuit(...)\n\nzxpass = ZXPass()\npass_manager = PassManager(zxpass)\nzx_qc = pass_manager.run(qc)\n```\n\nIt is also possible to initialise `ZXPass` with a custom optimization function.\n(The default, if none is supplied, is to call `pyzx.simplify.full_reduce`\non the graph of the circuit.)\n\n```python\nimport pyzx\n\ndef my_optimize(c: pyzx.Circuit) -> pyzx.Circuit:\n    g = c.to_graph()\n    # do stuff to simplify `g`...\n    return pyzx.extract.extract_circuit(g)\n\nzxpass = ZXPass(my_optimize)\npass_manager = PassManager(zxpass)\nmy_qc = pass_manager.run(qc)\n```\n\nThe transpiler is also exposed as a pass manager stage plugin at the optimization stage.\n\n```python\nfrom qiskit import transpile\n\nzx_qc = transpile(qc, optimization_method=\"zxpass\")\n```\n\n## Running benchmarks\n\nTo perform some benchmarks based on the [QASMBench](https://github.com/pnnl/QASMBench) suite, run the following:\n\n```bash\ncd benchmarking\npython run_benchmarks.py\n```\n\nThis 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.\n\n## Previous work\n\nThere have been two previous attempts to create a transpiler pass for Qiskit using PyZX which I'm aware of.\n\nThe first attempt was made in 2019 by\n[@lia-approves](https://github.com/lia-approves), [@edasgupta](https://github.com/edasgupta), and [@ewinston](https://github.com/ewinston)\nwhen they were interns at IBM Quantum, as documented in [this Qiskit issue](https://github.com/Qiskit/qiskit/issues/4990).\nThat code used qasm as an intermediate format when converting between a Qiskit `DAGCircuit` and a PyZX `Circuit`,\nwhich is undesirable for reasons noted in that issue. Furthermore, the code is out of date with subsequent changes made to both Qiskit and PyZX.\n\nThe second attempt was made by [@gprs1809](https://github.com/gprs1809) et al. as a part of the Qiskit Advocate Mentorship Program (QAMP) in the fall of 2022.\nThe code is found in [this repository](https://github.com/gprs1809/ZX_to_DAG_QAMP_fall_2022).\nThis implementation converts a PyZX `Circuit` directly to a Qiskit `QuantumCircuit`, without going through qasm.\nHowever, the code is incomplete and produces the wrong output for some circuits\n(which may have been due to a difference between how PyZX and Qiskit implements certain gates, fixed in [this PR](https://github.com/Quantomatic/pyzx/pull/156)),\nand (as far as I can tell) the code to convert in the other direction is not available.\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "A transpiler pass for Qiskit which uses ZX-Calculus for circuit optimization, implemented using PyZX.",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/dlyongemallo/qiskit-zx-transpiler",
        "Issues": "https://github.com/dlyongemallo/qiskit-zx-transpiler/issues",
        "Repository": "https://github.com/dlyongemallo/qiskit-zx-transpiler"
    },
    "split_keywords": [
        "qiskit",
        " zx-calculus",
        " quantum circuit optimization",
        " quantum computing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c70e7d438fb95f5b8823afb2f184140c28d4a5d0805909fe65bfb8ce1659dda4",
                "md5": "c01ef91ec84f35cce6dffb1cb493b14f",
                "sha256": "8b58b6b1496df2c75af1ec7e31f42a20929cb909fe36783197cd661f7ac06f4b"
            },
            "downloads": -1,
            "filename": "qiskit_zx_transpiler-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c01ef91ec84f35cce6dffb1cb493b14f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11564,
            "upload_time": "2024-04-07T17:37:34",
            "upload_time_iso_8601": "2024-04-07T17:37:34.310751Z",
            "url": "https://files.pythonhosted.org/packages/c7/0e/7d438fb95f5b8823afb2f184140c28d4a5d0805909fe65bfb8ce1659dda4/qiskit_zx_transpiler-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-07 17:37:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dlyongemallo",
    "github_project": "qiskit-zx-transpiler",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pyzx",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": [
                [
                    ">=",
                    "3.7.4"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.24.0"
                ],
                [
                    "<",
                    "2"
                ]
            ]
        },
        {
            "name": "pylatexenc",
            "specs": [
                [
                    "~=",
                    "2.10"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "~=",
                    "8.1.1"
                ]
            ]
        },
        {
            "name": "qiskit",
            "specs": [
                [
                    "~=",
                    "1.0.2"
                ]
            ]
        }
    ],
    "lcname": "qiskit-zx-transpiler"
}
        
Elapsed time: 1.94034s