goodchemistryco / Tangelo

A python package for exploring end-to-end chemistry workflows on quantum computers and simulators.
https://goodchemistryco.github.io/Tangelo/
Other
99 stars 27 forks source link

[BUG] `Circuit.draw()` returns an error when gate parameter is a string #388

Closed ValentinS4t1qbit closed 1 month ago

ValentinS4t1qbit commented 1 month ago

Issue: Bug Report

We wanted to provide a default draw method on the Circuit class in Tangelo for convenience, and decided that cirq 's would do: when we call draw() we implicitly ask cirq to draw it for us (Thanks cirq ❤️ )

Tangelo circuits can take almost anything as a value for gate.parameter, including a string. cirq is however not happy with that:

circuit = Circuit([Gate('H', 0), Gate('CNOT', 1, 0), Gate('RY', 1, parameter='theta')])
circuit.draw()
Screenshot 2024-05-28 at 2 48 15 PM

Can you help us ensure draw() works for strings as parameters ?

How to win

It turns out cirq is happy if we define a sympy symbol. Then we observe that both draw and print in Tangelo work just fine:

Screenshot 2024-05-28 at 3 08 03 PM

Which means one could ask draw to make a copy of the circuit on-the-fly (we don't want the method to modify the object itself) that replaces string values for parameters by equivalent sympy symbols.

Validation

anushkrishnav commented 1 month ago

Hey, I saw this issue on Unitary hacks , I think I can get it done, I will take this issue , Thanks for the how to win seems like a straight forward task if I have more questions will reach out

alexfleury-sb commented 1 month ago

Thank you for looking into this! We will look forward updates, and provide additional info if needed.

anushkrishnav commented 1 month ago

Hopefully, with my PR, This issue has been completed. !! Kindly assign me the issue

ValentinS4t1qbit commented 1 month ago

Solved by @anushkrishnav in #391