Learn how to use the Cirq SDK to submit quantum circuits to IonQ’s simulators and quantum computers.
cirq-ionq
module provides support for IonQ’s trapped-ion systems. This means that you can write quantum circuits and run them on IonQ’s simulators and trapped-ion quantum computers, all from within the Cirq framework.
python --version
from your command line if you aren’t sure which version
you have running.cirq-ionq
from the Python Package Index (PyPI) using pip
:
cirq
. For more details and advanced features, we recommend following the complete Cirq installation guide.
IONQ_API_KEY
when setting up the cirq_ionq.Service()
. If you need to pass in your API key directly, you can instead use:
cirq.LineQubit
with a unique integer identifier. While we use LineQubit
objects to represent the chain of trapped-ion qubits in an IonQ system, the qubit identifier does not indicate the position of a particular qubit in the chain. Also note that all IonQ systems have all-to-all connectivity, so two-qubit gates can be performed directly on any pair of qubits, whether or not their LineQubit
identifiers are adjacent.
repetitions
to request 1000 shots and name
to give the circuit a name that will show up in the IonQ Cloud Console.
cirq.Result
object shows 502 counts for the 0 state (00
) and 498 for the 3 state (11
).
service.run()
, we’ll use the extra_query_params
to add {"noise": {"model": "aria-1"}}
for the Aria 1 noise model.
The available noise models are harmony
(legacy), aria-1
, aria-2
, and forte-1
. You can read more about these noise models here.
service.create_job()
instead of service.run()
. This will submit the job, but won’t wait for it to finish, so our code won’t be blocked waiting for the result to return. In most cases, a QPU job will wait in the queue for some time before running.
The available QPU targets may include qpu.aria-1
, qpu.aria-2
, qpu.forte-1
and qpu.forte-enterprise-1
. You can view which of these systems you can access in the /v0.3/backends resource in the API or on the “Backends” tab of the IonQ Cloud Console.
'ready'
. If the job is finished, this will print 'completed'
.
You can also print and record the job’s unique ID, which can be used to retrieve the job (including its status and results) at a later time.
cirq.XPowGate
, cirq.YPowGate
, cirq.ZPowGate
cirq.rx
, cirq.ry
, and cirq.rz
and Pauli gates cirq.X
, cirq.Y
, and cirq.Z
.cirq.H
cirq.XXPowGate
, cirq.YYPowGate
, cirq.ZZPowGate
cirq.CNOT
, cirq.SWAP
cirq.MeasurementGate
: usually via cirq.measure
circuit2
using service.run()
or service.create_job()
as shown in the previous examples.
Note that prior to cirq-ionq
v0.15, this step was performed using cirq_ionq.decompose_to_device(qc)
instead.
IonQ’s native gates (GPi, GPi2, and MS) are also supported in Cirq. See our native gates introduction and guide to using native gates in Cirq for more details and examples.