# Qiskit transpile with different set of basis gates

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()


• If you created a custom backend with the basis gate it would still have the same current limitations. transpile() will just pull the value for basis_gates it passes to the transpiler passes from the backend instead of the kwarg, otherwise it works the same. Commented Oct 9, 2020 at 11:42
• Yeah, the transpile() call is what does hardware embedding and optimization, basically all the circuit transforms. The lack of 1q optimization for other basis sets is definitely a major limitation with qiskit today. .That being said your specific example here is actually a worst case for the current transpiler though, since it's all 1q. If you had a couple of 2q gates in there the transpiler can use unitary decomposition today to optimize things better (it might need the optimization_level=3 kwarg). Commented Oct 14, 2020 at 14:23