Using native gates with Cirq
Learn how to use our hardware-native gateset to run a circuit with Cirq
Introduction
Building and submitting circuits using IonQ’s hardware-native gateset enables you to bypass our compiler and optimizer, providing more control and transparency than the default abstract gateset (though often at the cost of performance and convenience).
Before working with native gates in Cirq, we recommend reviewing our guides on Getting Started with Native Gates and Getting Started with Cirq. Native gates are also supported in the IonQ API, Qiskit, and PennyLane.
Building a circuit with native gates
IonQ’s native gates are provided as part of the cirq-ionq
package, including:
GPIGate(phi)
GPI2Gate(phi)
MSGate(phi0, phi1, theta=0.25)
for Aria systems
The ZZ two-qubit gate used on our Forte systems is currently not available in cirq-ionq
. To use this type of native gate, build and submit circuits via the IonQ API or Qiskit.
The native gates can be imported from cirq_ionq.ionq_native_gates
:
For more details about these gate definitions and parameters, refer to the native gates guide.
Native gates are used like other gates when building a circuit:
Note that Cirq also defines an MS gate in cirq.MSGate
, but this gate is not equivalent to the IonQ native gates. To build a circuit in IonQ native gates, make sure you’re using the MS gate imported from cirq_ionq
.
Submitting a circuit with native gates
No changes or special arguments are needed to submit a native gate circuit to a cirq_ionq.Service
—the gateset will be detected automatically.
Transpiling a circuit to native gates
The cirq-ionq
integration currently does not support automatic transpilation to native gates via Cirq’s compiler, but we plan to add this capability in the future. If you’d like to help, feel free to open an issue or a pull request on the cirq-ionq module.
For now, we recommend following this general procedure (also described in our main native gates guide).
-
Decompose the gates used in the circuit so that each gate involves at most two qubits.
-
Convert all easy-to-convert gates into RX, RY, RZ, and CNOT gates.
-
Convert CNOT gates into XX gates using the decomposition described here and at the bottom of this section.
-
For hard-to-convert gates, first calculate the matrix representation of the unitary, then use either KAK decomposition or the method introduced in this paper to implement the unitary using RX, RY, RZ and XX. Note that Cirq and Qiskit also have subroutines that can do this automatically, although potentially not optimally. See cirq.linag.kak_decomposition and qiskit.synthesis.TwoQubitBasisDecomposer.
-
Write RX, RY, RZ and XX into GPi, GPi2 and MS gates as documented above (making sure to convert all angles and phases from radians to turns).
CNOT to XX decomposition
A CNOT gate can be expressed in XX, RX, and RY gates which can be directly converted to IonQ’s native gates.
Final transpilation step in code
Once you’ve completed steps 1-4 and expressed your circuit in terms of RX, RY, RZ, and XX gates, this example code snippet can perform the final transpilation step. The key here is to use a qubit_phase
list to track and adjust the orientation of the Bloch sphere of each qubit as the circuit progresses.
Once the circuit is fully expressed in IonQ native gates, it can be submitted to an IonQ backend as shown above.
Additional resources
Was this page helpful?