Learn how to use NVIDIA’s CUDA Quantum to submit quantum circuits to IonQ’s simulators and quantum computers.
cudaq
Python package directly with pip
, or you might use a Docker container provided by NVIDIA.
CUDA-Q can also be used in hosted environments like Google Colab or QBraid Lab, which offer easier setup and may provide access to GPU resources.
If you’re using a hosted notebook in an environment where CUDA-Q isn’t already installed, start by installing it via pip
:
IONQ_API_KEY
, rather than passing it into a function in your Python code. If you’re running on your local machine or in another environment that you can manage directly, you can set this up persistently using the steps for your operating system in our guide to API keys.
Otherwise, you can set the environment variable from within a Python script or notebook using:
@cudaq.kernel
decorator) and use cudaq.set_target('ionq')
before sampling the kernel.
cudaq.set_target('ionq')
will target IonQ’s ideal cloud simulator. Jobs run after setting this target in your code will be sent to the ideal simulator. (If we hadn’t set any target at all, the circuit would run locally using CUDA-Q’s default simulator for your system and environment.)
For IonQ ideal simulations using CUDA-Q, results are retrieved by multiplying the calculated probabilities by the shot count (which defaults to 1000 if unspecified, as in this example). As a result, this Bell state example ends up with exactly 500 shots for the 00
state and 500 shots for the 11
state.
For circuits run using CUDA-Q with other simulation backends (and for IonQ ideal simulations using different SDKs or settings), ideal simulation results may be returned by sampling from the calculated probabilities instead, which may be preferable depending on your objectives.
Finally, note that the name of the CUDA-Q kernel function (hello_world
in this case) is also used as the name of the IonQ job, which you should see on the “My Jobs” page in the IonQ Cloud Console.
noise
argument when setting the target, like: cudaq.set_target('ionq', noise='aria-1')
. The available noise models are harmony
(legacy), aria-1
, aria-2
, and forte-1
. You can read more about these noise models here.
aria-1
noise model, specifies the number of shots to be simulated, and changes the name of the job. As expected, the result is similar but there were a few instances of the 01
and 10
states recorded.
cudaq.set_target('ionq', qpu='qpu.aria-1')
or specify another backend name. Available QPU backend options may include ionq_qpu.aria-1
, ionq_qpu.aria-2
, ionq_qpu.forte-1
, or ionq_qpu.forte-enterprise-1
. You can view which of these systems you can access in the /v0.3/backends resource in the API and on the “Backends” tab of the IonQ Cloud Console.
Using CUDA-Q’s sample_async
method rather than sample
is also recommended, in order to submit a job and return to retrieve its results later.