3

It's well known that the single-qubit rotation gate $U(\theta, \phi, \lambda)$ and the controlled-not gate $CX_{i,j}$ form one of the universal set of gates for quantum computation. So here's my question: is the Qiskit transpile function able to compile any given quantum circuit by using u and cx gates only?

In particular, I would assume that the following code will always work with no errors:

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

qc = random_circuit(num_qubits=5, depth=10) tqc = transpile(qc, basis_gates=['u', 'cx'])

Unfortunately, it would seem not to be so and I was wondering why. I also noticed that, if I add the identity gate id in the list of basis_gates, the transpilation looks to always run successfully and I'm not sure about the reason for this.

The error produced by qiskit is:

QiskitError: "Cannot unroll the circuit to the given basis, ['u', 'cx'].
Instruction id not found in equivalence library and no rule found to expand."
MonteNero
  • 3,394
  • 8
  • 25
SimoneGasperini
  • 1,644
  • 1
  • 3
  • 18

1 Answers1

1

The basis gates u, cx are universal. This error is an artifact of the Qiskit transpiler. Change your transpiler call line to this:

tqc = transpile(qc, basis_gates=['u', 'cx', 'id'])

And the error should be fixed.

The reason this error occurs is because the identity gate (called id) can be used as a sort of timing enforcement gate for when the circuit is executing/or compiling. But, of course it is not actually needed in order to completely specify any intended quantum circuit. I assume in future versions of Qiskit this may be changed somehow so that users can be more selective for when they want to strictly include id gates or not.

By the way, this may actually be a bug in some cases (you should check this for your test cases), for example if id is not ever used by the transpiler for an example random circuit. In this case you should report this as a bug in the Qiskit Github.

Elijah Pelofske
  • 746
  • 4
  • 10