Git Product home page Git Product logo

ionizer's Introduction

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

Requirements:

  • PennyLane >= 0.33

The Ionizer is not currently available via a package manager. To install, clone the repository and run

python -m pip install .

or

python setup.py install

If you need to run Ionizer with a version of PennyLane between 0.29 and 0.32, please use version 0.1.2 of the package.

Examples

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 decorator performs the following steps:

  • Decomposes all operations into Paulis/Pauli rotations, Hadamard, and CNOT
  • Merges all single-qubit rotations
  • Converts everything except RZ to GPI/GPI2/MS gates (@ionizer.transforms.convert_to_gpi)
  • Virtually applies all RZ gates (@ionizer.transforms.virtualize_rz_gates)
  • Repeatedly applies gate fusion and commutation through MS gates which performs simplification based on some circuit identities (@ionizer.transforms.single_qubit_fusion_gpi and @ionizer.transforms.commute_through_ms_gates)
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)─┤

Note that while this comes packaged together as the @ionize transform, the individual transforms can also be accessed and used independently.

There is currently not direct support for other frameworks. However, if you would like to do this with a Qiskit circuit, it can be accomplished as follows through the pennylane-qiskit package.

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
  • improving the documentation and usage instructions
  • ensuring differentiability of variational parameters
  • writing more tests (compile at your own risk!)

Resources

Citing

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_10761367,
  author       = {Di Matteo, Olivia},
  title        = {The Ionizer},
  month        = mar,
  year         = 2024,
  publisher    = {Zenodo},
  version      = {0.2},
  doi          = {10.5281/zenodo.10761367},
  url          = {https://doi.org/10.5281/zenodo.10761367}
}

ionizer's People

Contributors

gabriel-bottrill avatar glassnotes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ionizer's Issues

Update README for release 0.3

Will need to update the README contents to include:

  • new installation instructions
  • new and updated dependencies
  • location of online documentation
  • instructions for contributing

Set up CI pipelines

Pipelines should:

  • automatically run the tests
  • format code with black
  • lint code with pylint
  • use caching to speed up pipelines

Add mechanism for certifying equivalence of compiled circuits

Since external researchers are actually using the library for their work, there should be a built-in method to check equivalence of the compiled circuits and alert the user if there are any issues. As a first step, unitary equivalence can be checked by passing a keyword argument, and a warning raised if they are not equivalent (or only equivalent up to global phase). For example,

@qml.qnode(dev)
@ionize(verify=True)
def circuit(x): 
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])
    qml.RX(x, wires=1)
    return qml.expval(qml.PauliZ(0))
>>> circuit(0.2)
CompilationError: transpiled circuit is not unitarily equivalent to original circuit.

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.