Skip to main content

PennyLane tools for compilation into trapped-ion native gates.

Project description

The Ionizer

DOI

Transpile and optimize your PennyLane circuits into IonQ's native trapped-ion gate set (GPI, GPI2, MS) with just a single extra line of code!

from ionizer.transforms import ionize


@qml.qnode(dev)
@ionize
def circuit(x):
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.RX(x, wires=1)
    return qml.expval(qml.PauliZ(0))
>>> qml.draw(circuit)(0.3)
0: ──GPI2(0.00)─╭MS──GPI2(-1.57)─────────────────────────┤  <Z>
1: ──GPI2(3.14)─╰MS──GPI2(1.57)───GPI(-1.42)──GPI2(1.57)─┤

Installation

The Ionizer is available via PyPI:

pip install ionizer

The core requirement is PennyLane 0.37.

Python versions 3.10-3.12 are supported and tested against.

To install from source, clone this repository and use Poetry to install the dependencies listed in the pyproject.toml file.

Examples

For more detailed explanations and usage examples, please check the full online documentation.

The Ionizer is implemented using quantum function transforms, similar to PennyLane's existing compilation tools. To compile and execute the circuit using trapped ion gates, the @ionize transform will

  • Decompose all operations into Paulis/Pauli rotations, Hadamard, and CNOT
  • Cancel inverses and merge single-qubit rotations
  • Convert everything except RZ to GPI, GPI2, and MS gates
  • Virtually apply RZ gates
  • Repeatedly apply single-qubit gate fusion and commutation through MS gates, and perform simplification based on a database of circuit identities.
from ionizer.transforms import ionize


@qml.qnode(dev)
@ionize
def circuit_ionized(params):
    for idx in range(5):
        qml.Hadamard(wires=idx)

    for idx in range(4):
        qml.RY(params[idx], wires=idx)
        qml.CNOT(wires=[idx + 1, idx])

    for wire in dev.wires:
        qml.PauliX(wires=wire)

    return qml.expval(qml.PauliX(0))
>>> circuit_ionized(params)
tensor(0.99500417, requires_grad=True)
>>> qml.draw(circuit_ionized)(params)
0: ──GPI2(-1.57)──GPI(-1.52)──GPI2(-3.04)─╭MS───────────────────────────────────────────────────
1: ──GPI2(-1.92)──GPI(3.14)───GPI2(-1.22)─╰MS──GPI2(2.36)──GPI(1.67)──GPI2(0.99)─╭MS────────────
2: ──GPI2(-1.92)──GPI(3.14)───GPI2(-1.22)────────────────────────────────────────╰MS──GPI2(2.36)
3: ──GPI2(-1.92)──GPI(3.14)───GPI2(-1.22)───────────────────────────────────────────────────────
4: ──GPI2(-1.92)──GPI(3.14)───GPI2(-1.22)───────────────────────────────────────────────────────

────────────────────────────────────────────────────────────────────────────────────────────┤  <X>
────────────────────────────────────────────────────────────────────────────────────────────┤
───GPI(1.72)──GPI2(1.09)─╭MS────────────────────────────────────────────────────────────────┤
─────────────────────────╰MS──GPI2(2.36)──GPI(1.77)──GPI2(1.19)─╭MS─────────────────────────┤
────────────────────────────────────────────────────────────────╰MS──GPI2(0.00)──GPI2(1.57)─┤

The consistuent transforms can also be accessed and used independently.

There is currently not direct support for other frameworks. However, if you would like to apply the transforms to Qiskit circuits, this can be accomplished using the pennylane-qiskit package as shown belown.

qiskit_circuit = QuantumCircuit(...)

# Turns a Qiskit circuit into a PennyLane quantum function
qfunc = qml.from_qiskit(qiskit_circuit)


@qml.qnode(dev)
@ionize
def pennylane_circuit():
    qfunc()
    return qml.expval(qml.PauliX(0))

Notes

This package is a work in progress. While it has been verified to work on some fairly large circuits, we still need to work on:

  • finding circuit identities involving the 2-qubit gate
  • ensuring differentiability of variational parameters
  • writing more tests (compile at your own risk!)

Resources

Contributing

The Ionizer is available open source under the MIT License. Contributions are welcome. Please open an issue if you are interested in contributing, or if you encounter a bug.

Reference

If you use the Ionizer as part of your workflow, we would appreciate if you cite it using the BibTeX below.

@software{di_matteo_2024_13370396,
  author       = {Di Matteo, Olivia},
  title        = {The Ionizer},
  month        = aug,
  year         = 2024,
  publisher    = {Zenodo},
  version      = {0.3},
  doi          = {10.5281/zenodo.13370396},
  url          = {https://doi.org/10.5281/zenodo.13370396}
}

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

ionizer-0.3.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

ionizer-0.3.0-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file ionizer-0.3.0.tar.gz.

File metadata

  • Download URL: ionizer-0.3.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-40-generic

File hashes

Hashes for ionizer-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f4f6eb0449ed69682cfb5d0307f97c7f11b1738fcdf3605361d4b4844f85888b
MD5 3380052cbf89924a48005299d84a2853
BLAKE2b-256 a96eebb040ca32cd60b7ca18484d2d3487dbaa742db90d26e02a5b952db64393

See more details on using hashes here.

File details

Details for the file ionizer-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ionizer-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-40-generic

File hashes

Hashes for ionizer-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d78867a5209772adb8147e12bfe85d82f2c914cb1c09e080cb923f593660bd70
MD5 88c3eea97218b957f598114f3ecb30ab
BLAKE2b-256 1eb0a64a946492cc15bf0edda2f1abc9dfa7106397323b51d11d2634d6ba48a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page