tket icon indicating copy to clipboard operation
tket copied to clipboard

Circuit renderer displays the wrong angle value after conversion to qiskit and back

Open CalMacCQ opened this issue 2 years ago • 2 comments

Small bug pointed out by @alessum.

@DNA386

Using pytket v1.11.1

from pytket import Circuit
from pytket.circuit.display import render_circuit_jupyter
from pytket.extensions.qiskit import qiskit_to_tk, tk_to_qiskit

circ1 = Circuit(2).CX(0, 1).Rz(0.2, 1).CX(0, 1)
render_circuit_jupyter(circ1)

The circuit diagram looks as expected

Screenshot 2023-03-02 at 10 35 06

However if we convert to qiskit and then back the diagram shows the angle (0.2*pi). It seems to be picking up an extra factor of pi due to the different angle conventions of qiskit and pytket.

circ2 = qiskit_to_tk(tk_to_qiskit(circ1))
render_circuit_jupyter(circ2)
Screenshot 2023-03-02 at 10 39 26

However the underlying pytket Circuit has the expected angle of 0.2.

print(circ2.get_commands())
Screenshot 2023-03-02 at 10 41 37

CalMacCQ avatar Mar 02 '23 10:03 CalMacCQ

This is very weird, since the circuits circ1 and circ2 are identical (except for the names).

cqc-alec avatar Mar 06 '23 13:03 cqc-alec

This was caused by the renderer not fully displaying the decimal expansion with a symbolic factor of pi. The entire expansion looks like Rz(0.62831.../pi) but the factor of pi wasn't apparent in the display.

In the pytket 1.13.2 release the renderer has a [crop long parameters] button (on by default). If you turn this off the user can view the full expansion.

Maybe we should look into the qiskit_to_tk evaluating the factor of pi numerically after the conversion as the default display still looks a little confusing in case where you are converting back and forth.

CalMacCQ avatar Mar 31 '23 12:03 CalMacCQ

This issue has been automatically marked as stale.

github-actions[bot] avatar Jun 13 '24 05:06 github-actions[bot]