How to use IonQ native gates with ionq.simulator

Here’s a minimal working example of some code that tries to create a PyTorch layer using the native gateset provided by the pennylane-ionq simulator:

import pennylane as qml
from pennylane_ionq import ops

# quantum circuit setup
nqbits = 1
device = qml.device('ionq.simulator', wires=nqbits)

@qml.qnode(device=device, interface='torch', diff_method='best')
def circuit(inputs):
    # feature encoding layer
    ops.GPI2(inputs[0], wires=0)
    return [qml.expval(qml.PauliZ(0))]

circuit([1.0])

Unfortunately it returns the following error, which seems odd, as one would think the IonQ simulator would support its own native gateset

pennylane._device.DeviceError: Gate GPI2 not supported on device ionq.simulator

Can anyone help shed some light on this issue?

Hey @Wilfrid_Somogyi! Welcome to the forum :rocket:!

All you need to do is specify gateset="native" in your device definition and that will unlock GPI2 :slight_smile:.

import pennylane as qml
from pennylane_ionq import ops

# quantum circuit setup
nqbits = 1
device = qml.device('ionq.simulator', wires=nqbits, gateset="native")

@qml.qnode(device=device)
def circuit(inputs):
    # feature encoding layer
    ops.GPI2(inputs[0], wires=0)
    return [qml.expval(qml.PauliZ(0))]

Note that you need an API key to execute this now :grin:

1 Like

Thanks Isaac, I have the API key, seems be working!

Awesome! Glad to hear. I made an issue on the plugin repo since the docs aren’t very clear here :sweat_smile:. Glad everything is working!