-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Glitched Circuit Diagram after flatten #3196
Comments
Hi @AlkaidCheng - the result on the CLI is
I'm guessing that the angle brackets |
Yeah I just confirmed that that's the issue. In Jupyter notebooks this shows up incorrectly, but only if the object is returned as the result of the cell - if you use print, it works
Gives a workaround, but it might be a bit annoying. Not sure yet what the right solution is here. |
Right, I was using Colab notebooks and doing print will solve the problem. |
I have been using the circuit returned as the result of the cell for printing circuits because for jupyter notebooks, doing print(circuit) will mess up the diagram by introducing extra newlines if the circuit is too long. Interestingly doing print(circuit) in Colab notebooks does not have this problem. |
For someone who wants to look at this should review the possibility of replacing |
Hey! Can I contribute to this issue? |
Hi @abhik-99 - yes please, feel free to grab it! |
After a quick internal chat - consensus is on using |
I haven't been following this issue but it sounds like the angle brackets are a problem in the Jupyter scrollable view because they are interpreted as HTML tags. An easy fix for this would be to escape any special characters in the code for |
Sure @balopat! On it. Thanks. |
xref #2905 |
So hey @balopat and @cduck I tried out two possible solutions.
Solution 1 is the easiest one but solution 2 is better in preventing similar future issues. The thing is that in solution 2, as the Any suggestions? |
It would be helpful to give the code you used for those examples. I would do the second solution by changing line https://github.com/quantumlib/Cirq/blob/master/cirq/circuits/circuit.py#L378 to |
Thanks a lot @cduck ! Just did that and turns out it works great. Opening a PR on a side branch on the lint and tests pass. |
This PR fixes #3196 by using the `html` module for escaping characters when the circuit diagram is produced. The escaping allows easy and correct rendering of the diagram when it is used as a cell output of a Jupyter Notebook instead of using `print(circuit)`. Previsouly, the special characters like `< >` were not being rendered after the circuit was flattened as they were being interpreted as part of HTML tags. Using `html.escape( )` in `circuit._repr_html_(self)` prevents that from happening.
This PR fixes quantumlib#3196 by using the `html` module for escaping characters when the circuit diagram is produced. The escaping allows easy and correct rendering of the diagram when it is used as a cell output of a Jupyter Notebook instead of using `print(circuit)`. Previsouly, the special characters like `< >` were not being rendered after the circuit was flattened as they were being interpreted as part of HTML tags. Using `html.escape( )` in `circuit._repr_html_(self)` prevents that from happening.
Description of the issue
When a circuit has a parameterised gate as a product of symbols, flattening the circuit will produce a glitched circuit diagram where the parameterised expression is gone. This will further affect the circuit diagram if two qubit gates are also present in the circuit.
How to reproduce the issue
This will product circuit diagram like this
This will product circuit diagram like this
(0, 0): ─────────────────────────@───
│
(1, 0): ───Rz(pi*)───X───
Cirq version
0.8.2
The text was updated successfully, but these errors were encountered: