Introducing IonQ Forte, The First Software-Configurable Quantum Computer

Learn more about our latest system

Using Native Gates with PennyLane

We’ve expanded access to IonQ’s hardware-native gate set ─ previously only available to select research partners and customers ─ to anyone using the IonQ Quantum Cloud via an IonQ-provided API token, including those who access IonQ hardware through Google Cloud Marketplace. To allow users to build confidence and understanding in this new interface before they run jobs on QPUs, we’ve also expanded our quantum simulator service to enable simulations using the same native gate set.

As a part of this expanded access, we’ve also updated many of our supported open-source quantum SDKs, including PennyLane, with native gates support. This guide explains how to use native gates with PennyLane with a basic example.

Please read the main Getting Started with Native Gates guide before getting started with PennyLane — it contains critical context for getting the most out of the native gates interface.

WARNING: This is an advanced-level feature. Using the hardware-native gate interface without a thorough understanding of quantum circuits is likely to result in less-optimal circuit structure and worse algorithmic performance overall than using our abstract gate interface.

Native Gates in PennyLane

Note that as of May 2022, native gate support is in PennyLane-IonQ’s main branch, but not yet in a stable release.

You can install directly from main by running

pip install git+https://github.com/pennylaneai/[email protected]

The gates themselves are provided as part of the pennylane_ionq package. To use them, just import them:

#import pennylane and utils
import collections
import pennylane as qml
from pennylane_ionq import ops

#import gates
from pennylane_ionq.ops import GPI, GPI2, MS

with qml.tape.QuantumTape() as tape:
    GPI(0.5, wires=[0])
    GPI2(0, wires=[1])
    MS(0, 0.5, wires=[1, 2])

Running on The IonQDevice

To run using native gates, instantiate the IonQDevice with gateset="native":

dev = IonQDevice(wires=(0,1,2), gateset="native")
dev.apply(tape.operations)

# or alternatively
@qml.qnode(dev, parallel=True)
def circuit():
    qml.apply(GPI(0.5, wires=[0]))
    qml.apply(GPI2(0, wires=[1]))
    qml.apply(MS(0, 0.5, wires=[1, 2]))
    return qml.probs(wires=[0, 1, 2])

And submit as normal:

results = collections.Counter(dict(enumerate(circuit().tolist())))
print(results)
Counter({5: 0.252, 7: 0.250, 6: 0.249, 4: 0.249})

Additional Resources

Be sure to read our main Getting Started with Native Gates guide for more context on the hardware-native interface and how it differs from our abstract gates interface.

Native gates are also available in other open source tools, including Qiskit and Cirq — see Using Native Gates With Qiskit and Using Native Gates With Cirq for more.