3
$\begingroup$

Suppose you are given the following quantum circuit in Qiskit:

from numpy import pi
from qiskit import QuantumCircuit

angle = pi / 3

qc = QuantumCircuit(1)
qc.ry(angle, 0)
qc.ry(-angle, 0)

qc.draw('mpl')

enter image description here

The circuit simply performs two rotations around the $y$-axis with angle $\theta = \pi/3$ and then $-\theta$. These operations should be resolved in a simple identity because $I = R_y(-\theta) R_y(\theta)$. However, the Qiskit transpile function seems not to do the job as expected in this case:

from qiskit import transpile

tqc = transpile(qc, optimization_level=3)
tqc.draw('mpl')

enter image description here

Moreover, trying exactly the same thing with $R_x$ (qc.rx) or $R_z$ (qc.rz) rotations, the transpilation runs perfectly returning an empty circuit. Is this a bug in Qiskit? Or maybe I'm missing something?

$\endgroup$
2
  • 2
    $\begingroup$ It was a bug. Please, try qiskit 0.40.0. With this version, it works. $\endgroup$ Jan 27 at 14:16
  • $\begingroup$ @MicheleAmoretti This should be an answer. Ideally, it would include a reference to the bug, release notes etc. $\endgroup$ Jan 27 at 21:24

1 Answer 1

4
$\begingroup$

It was a bug, now fixed in release 0.40.0.

In the release notes, you can read:

Fixed an issue with the transpile() function when run with optimization_level=3 and no backend, basis_gates, or target argument specified. If the input circuit contained any 2 qubit blocks which were equivalent to an identity matrix the output circuit would not be as optimized as possible and and would still contain that identity block. This could have been corrected previously by specifying either the backend, basis_gates, or target arguments on the transpile() call, but now the output will be as simplified as it can be without knowing the target gates allowed. Fixed #9217

$\endgroup$

Your Answer

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

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