TransWikia.com

Qiskit transpile with different set of basis gates

Quantum Computing Asked by max_keller on March 23, 2021

I want to use the Qiskit transpile function to decompose an arbitrary unitary matrix/ quantum circuit into a special kind of basis gates.
(from qiskit.compiler import transpile)

But for me it seems the only accepted basis gates are ‘u1’, ‘u2’, ‘u3’ and ‘cx’.
Is there a way to use for example ‘rx’, ‘ry’ and ‘cx’ as basis gates instead of ‘u1’, ‘u2’, ‘u3’ and ‘cx’?

The following error

Exception has occurred: QiskitError
"Cannot unroll the circuit to the given basis, [‘id’, ‘ry’, ‘rx’, ‘cx’]. No rule to expand instruction h."

for example is obtained from the code:

from qiskit.quantum_info import Operator
from qiskit.compiler import transpile
import matplotlib.pyplot as plt
from qiskit.compiler.transpile import CouplingMap

coupling_string = [[0, 1], [0,2], [1,2]]

CM = CouplingMap(coupling_string)

qc = QuantumCircuit(3)

qc.h(0)
qc.h(1)
qc.h(2)

result = transpile(qc, coupling_map=CM, basis_gates=['id', 'ry', 'rx', 'cx'], optimization_level=1, seed_transpiler=1) 
result.draw(output='mpl')
plt.show()

One Answer

Which version of Qiskit are you running? Support for arbitrary basis translation was added very recently in Qiskit 0.20.0/Qiskit-Terra 0.15.0. 1 If you're running an older version of Qiskit then the transpiler will fail like this because the unroller didn't know how to use that basis set. However, when using the latest Qiskit release it will output display a circuit image like:

enter image description here

It's worth noting that the transpilation isn't great because the 1 qubit optimization pass doesn't understand arbitrary basis sets yet and still only works for u1, u2, u3, which is why that output is so large. There is work pending on fixing this https://github.com/Qiskit/qiskit-terra/pull/3658

1 https://qiskit.org/documentation/release_notes.html#qiskit-0-20-0

Correct answer by Matthew Treinish on March 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP