cirq-ionq
raw JSON → 1.6.1 verified Mon Apr 27 auth: no python
A Cirq package to simulate and connect to IonQ quantum computers. Version 1.6.1, released as part of Cirq v1.6.1. Supports Python >=3.11.0. Releases follow Cirq's release cadence, approximately quarterly.
pip install cirq-ionq Common errors
error ModuleNotFoundError: No module named 'cirq_ionq' ↓
cause cirq-ionq not installed or imported incorrectly (e.g., `cirq.ionq`).
fix
Run
pip install cirq-ionq and import as from cirq_ionq import IonQDevice. error ionq_rest: (403) Forbidden ↓
cause Invalid or missing API key. The IonQ API key is not set or is incorrect.
fix
Set the
IONQ_API_KEY environment variable to a valid IonQ API key. error google.api_core.exceptions.PermissionDenied: 403 The request is missing a valid API key. ↓
cause Similar to above; API key not provided.
fix
Provide API key via environment variable or constructor argument.
Warnings
breaking Python 3.11 minimum: From version 1.6.0, cirq-ionq requires Python >=3.11.0. Older Python versions will fail to install. ↓
fix Upgrade Python to 3.11 or later.
gotcha Import from cirq_ionq not cirq.ionq: The correct import path is `from cirq_ionq import ...`. Using `cirq.ionq` will raise ImportError. ↓
fix Use `from cirq_ionq import IonQSimulator`.
deprecated API key via environment variable: The IonQ API key must be set via the `IONQ_API_KEY` environment variable or passed to the sampler constructor. Passing via `cirq_ionq.Service` constructor is deprecated. ↓
fix Set `IONQ_API_KEY` env var or use `IonQSimulator(api_key=...)` as documented.
Imports
- IonQDevice wrong
from cirq.ionq import IonQDevicecorrectfrom cirq_ionq import IonQDevice - IonQSimulator wrong
from cirq.ionq import IonQSimulatorcorrectfrom cirq_ionq import IonQSimulator
Quickstart
import cirq
from cirq_ionq import IonQSimulator
# Get API key from environment (set IONQ_API_KEY)
import os
api_key = os.environ.get('IONQ_API_KEY', '')
if not api_key:
print('Set IONQ_API_KEY environment variable')
exit(1)
simulator = IonQSimulator(api_key=api_key)
q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1))
result = simulator.run(circuit, repetitions=100)
print(result.histogram(key='0,1'))