3
$\begingroup$

I have a certain quantum circuit (qc) in qiskit. My goal is to see it transpiled in IonQ Native Gates, to see the qc that is effectively run on the hardware.

However, the Ionq basis gate set which I see by using qiskit is the following:

['ccx', 'ch', 'cnot', 'cp', 'crx', 'cry', 'crz', 'csx', 'cx', 'cy', 'cz', 'h', 'i', 'id', 'mcp', 'mcphase', 'mct', 'mcx', 'mcx_gray', 'measure', 'p', 'rx', 'rxx', 'ry', 'ryy', 'rz', 'rzz', 's', 'sdg', 'swap', 'sx', 'sxdg', 't', 'tdg', 'toffoli', 'x', 'y', 'z']

While reading the IonQ guides I see that their native gates are GPi, GPi2 and MS gates.

If I specify this as basis_gate in the transpile function of qiskit I get errors:

qiskit.transpiler.exceptions.TranspilerError: "Unable to map source basis {('x', 1), ('reset', 1), ('ccx', 3), ('measure', 1), ('cx', 2), ('ry', 1), ('barrier', 5)} to target basis {'reset', 'delay', 'gpi', 'snapshot', 'gpi2', 'ms', 'barrier', 'measure'} over library <qiskit.circuit.equivalence.EquivalenceLibrary object at 0x7f9f030ea580>."

Also, looking at the IonQ guide about their Native Gates (https://ionq.com/docs/getting-started-with-native-gates), they introduce the general algorithm they use to compile the qc in terms of IonQ Native Gates: it should work as follows:

  1. Decompose the gates used in the circuit so that each gate involves at most two qubits.
  2. Convert all easy-to-convert gates into RX, RY, RZ, and CNOT gates.
  3. Convert CNOT gates into XX gates using the decomposition described here and at the bottom of this section.
  4. For hard-to-convert gates, first calculate the matrix representation of the unitary, then use either KAK decomposition or the method introduced in this Phys, Rev. A. 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.quantum_info.TwoQubitBasisDecomposer.
  5. Write RX, RY, RZ and XX into GPi, GPi2 and MS gates as documented above.

However also if I try to specify the set ['rx', 'ry', 'rz', 'xx'] as basis gate in the transpile I get:

qiskit.transpiler.exceptions.TranspilerError: "Unable to map source basis {('reset', 1), ('measure', 1), ('ry', 1), ('cx', 2), ('ccx', 3), ('barrier', 5), ('x', 1)} to target basis {'delay', 'reset', 'xx', 'barrier', 'rx', 'ry', 'snapshot', 'measure', 'rz'} over library <qiskit.circuit.equivalence.EquivalenceLibrary object at 0x7fa8b8ab14f0>."

Any hint about this? How can I see the quantum circuit as close as possible to what is run on an IonQ machine ?

$\endgroup$
1

3 Answers 3

3
$\begingroup$

I had a try implementing the general algorithm you posted as it is proposed on the IonQ Native Gates guide. Since 1-qubit rotation gates $R_x$, $R_y$, $R_z$ together with the 2-qubits $CNOT$ form a universal set of gates for quantum computation, step 1 and 2 can be easily accomplished for any given circuit.

Morever, in the paper arXiv:1603.07678, they show that the $CNOT$ operation can be implemented, up to a global phase, by the following sequence of gates (setting $v=s=1$):

enter image description here

In Qiskit, the XX interaction is implemented by the RXX gate. So, to complete step 3 of the algorithm, you can simply use the Qiskit transpile function as follows:

from qiskit.circuit.random import random_circuit
from qiskit import transpile

qc = random_circuit(3, 1, seed=5)
tqc = transpile(qc, basis_gates=['rx', 'ry', 'rz', 'rxx', 'id'])
tqc.draw(output='mpl')

enter image description here

Finally, to compile the circuit by using IonQ native gates only (namely MS, GPi, GPi2), you should take a look to the GMS class in Qiskit documentation and remember the simple relations: $$ \mathrm{GPi}(\phi) = -i R_z(2\phi) R_x(\pi) $$ $$ \mathrm{GPi}2(\phi) = R_z(\phi) R_x(\pi/2) R_z(-\phi) $$

$\endgroup$
1
$\begingroup$

Maybe this doesn't address your question directly but it should be possible to automatically compile your circuit to the IONQ gateset with the pytket-ionq extension.

github -> https://github.com/CQCL/pytket-ionq

API reference -> https://cqcl.github.io/pytket-ionq/api/api.html

I think you can do the following...

from pytket.extensions.ionq import IonQBackend
from pytket.circuit.display import render_circuit_jupyter

backend = IONQBackend(...)
compiled_circ = backend.get_compiled_circuit(qc, optimisation_level=2)
render_circuit_jupyter(compiled_circ) # Draw circuit

If you're working with qiskit you will need to use pytket-qiskit to convert your circuit to a pytket Circuit first.

$\endgroup$
1
  • $\begingroup$ Thanks for sharing this. I'm currently using Azure Quantum to run experiments on IonQ Machines. Do you know how can I retrieve the ion-q API key? $\endgroup$ Commented Feb 20, 2023 at 15:32
0
$\begingroup$

I found a guide specific to Qiskit linked by the Native Gate Guide you provided. In the section “Transpilation to Native Gates in Qiskit”, it states that transpiler a circuit into a native gate set is not supported at the moment.

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks for your reply. Yes, I saw it. But is it possible that there is no way to know what is running on the ionq machine? I was hoping that from the ionq side, there is something or somewhere to look to have knowledge about the final quantum circuit to run. $\endgroup$ Commented Feb 20, 2023 at 14:00
  • 1
    $\begingroup$ There might be API available on the IonQ side to extract the circuit after transpilation on their end but I am not familiar with that. If this is your end goal then going that route is better because even if you find a way to transpile using Qiskit to the native gates of IonQ devices, the resulting circuit will probably be different because of the difference in transpilation methods. $\endgroup$ Commented Feb 20, 2023 at 14:05
  • $\begingroup$ quantumcomputing.stackexchange.com/questions/17860/… this answer gives some hints about how to transpile into custom gate sets using Qiskit. In a nutshell you need to write new equivalence rules into Equivalence Library in Qiskit transpiler to achieve that. $\endgroup$ Commented Feb 20, 2023 at 14:07
  • $\begingroup$ I noticed adding support to native gate set is an open issue for the qiskit-ionq provider: github.com/Qiskit-Partners/qiskit-ionq/issues/92 There you can find a link to Qiskit documentation about how to define a backend with custom gate set and add equivalence rules which may be useful for you. qiskit.org/documentation/apidoc/… $\endgroup$ Commented Feb 20, 2023 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.