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 .
{
"format": "ionq.circuit.v0",
"gateset": "qis",
// The fields above are optional, as they are the default.
"qubits": 2,
"circuit": [
{
"gate": "h",
"target": 0
},
{
"gate": "cnot",
"target": 1,
"control": 0
}
]
}
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.
{
"qubits": 4,
"circuit": [
{
"gate": "h",
"target": 0
},
{
"gate": "cnot",
"control": 0,
"target": 1
},
{
"gate": "cnot",
"control": 0,
"target": 2
},
{
"gate": "cnot",
"control": 0,
"target": 3
}
]
}
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.
{
"qubits": 3,
"circuit": [
{
"gate": "cnot",
"target": 0,
"controls": [1, 2]
}
]
}
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
You can access native gates by setting the gateset
parameter in the job input to "native"
.
The angle
and phase
parameters for native gates use values expressed in turns, not radians, where 1 turn = radians.
Some considerations when submitting in this format:
- The
ms
andzz
gates requirephases
andtargets
, both with two elements. - Optionally,
ms
accepts anangle
for entanglement, ranging from 0 to 0.25. - The
zz
gate also allows an optionalangle
between -0.25 and 0.25. - For
gpi
andgpi2
gates, use argumentsphase
andtarget
.
Native Gates
Gate | Description |
---|---|
ms | Mølmer–Sørensen gate |
gpi | GPI gate |
gpi2 | GPI2 gate |
zz | ZZ gate (only supported on qpu.forte-1 ) |
For a more in-depth discussion of our native operations, see our Native Gates Guide for details and recommendations.
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
{
"format": "openqasm",
"data": "string"
}
QASM
{
"format": "qasm",
"data": "string"
}
Quipper
{
"format": "quipper",
"data": "string"
}
Is there a language format you’d like to see supported? Drop us a line and let us know.
Was this page helpful?