Writing Quantum Programs
For the best results, please submit quantum programs in the ionq.circuit.v0
format, as demonstrated below.
In the compilation and optimization process, your submitted circuit will be converted to an equivalent, optimized circuit expressed in terms of IonQ’s native gates, which may involve combining or canceling out some operations. If you wish to guarantee that the quantum computer executes the exact series of operations that you define, please bypass our compiler and submit directly to our native gate interface.
For more examples and the full API specification for defining circuits, refer to the API reference.
To write a quantum program using Qiskit or another SDK, refer to our SDK guides.
Bell State
We can create a maximally entangled Bell state by applying a Hadamard gate to a single qubit, and applying a controlled-not gate to a second qubit.
Half of the time the second qubit will be measured as , the other half will be measured as .
GHZ State
We can create a three qubit GHZ state by first applying a Hadamard gate to a single qubit, and then using it as the control qubit for a series of controlled-not gates.
Toffoli gate
The Toffoli gate, or controlled-controlled-not gate, is a universal reversible logic gate. We can simply apply a cnot to our target qubit, with two control qubits provided via array.
Supported Gates
For actual execution, gates will be compiled into optimal operations for our trapped ion hardware. For convenience, we provide a more expressive gateset for programming.
Gate | Description |
---|---|
x | Pauli X gate |
y | Pauli Y gate |
z | Pauli Z gate |
rx | X-axis rotation |
ry | Y-axis rotation |
rz | Z-axis rotation |
h | Hadamard gate |
not | Convenient alias for Pauli-X gate |
cnot | Convenient alias for controlled-not gate |
s | S gate |
si | Conjugate transpose of S gate |
t | T gate |
ti | Conjugate transpose of T gate |
v | Square root of not gate |
vi | Conjugate transpose of square-root-of-not gate |
swap | Swaps two qubits |
Each operation in a circuit specifies a gate
and a target
qubit index (or a list of multiple targets
). Rotation gates also specify a rotation
in radians.
In addition, any gate can be expressed as a controlled gate by specifying a control
qubit, or as its multi-controlled variant by specifying a list of up to seven controls
(for any gate except swap
). This can often be used to simplify the circuit’s description. In general, circuits expressed in fewer QIS gates will be further optimized for runtime, so using multi-controlled variants of gates is recommended.
Examples:
- Hadamard gate:
{"gate": "h", "target": 0}
- Controlled-not gate:
{"gate": "cnot", "target": 1, "control": 0}
- Toffoli gate (multi-controlled not gate):
{"gate": "cnot", "target": 0, "controls": [1, 2]}
- Rx gate with rotation:
{"gate": "rx", "target": 0, "rotation": 1.5708}
- Swap gate:
{"gate": "swap", "targets": [0,1]}
For more examples and the full API specification for defining circuits, refer to the API reference.
Native Specification
For information about writing quantum programs using IonQ’s hardware-native gate set, refer to our guides on getting started with native gates and using native gates with the IonQ API.
Other Formats (experimental)
Support for submitting programs in QASM/OpenQASM and Quipper is currently experimental. If you use these languages, we will compile your code to a logically-equivalent representation using our Supported Gates. (For billing purposes, we’ll calculate your program’s resource requirements after it’s been compiled this way.)
OpenQASM
QASM
Quipper
Is there a language format you’d like to see supported? Drop us a line and let us know.
Was this page helpful?