-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix latex drawer symmetrical gates display #6877
base: main
Are you sure you want to change the base?
Conversation
@TharrmashasthaPV I was wondering if you could have a look at this PR. It was started by @jsistos and I'm finishing it off. It accomplishes the goal, but you commented we are trying to eliminate adding header info in latex source. So is there a way to accomplish the same thing without the added |
Hello, |
@jsistos Glad to see you back. I've basically just cleared up the merge conflicts from #6061 and I believe everything is running properly. The one remaining issue is what I mentioned in my comment to @TharrmashasthaPV above. There was a major cleanup of the header code for the latex drawer in #6483 related to issue #6447. So I think we are trying to keep anything out of the header other than the If it's a simple fix, just let me know and I can finish it off here, or you can take it from here. Once it's finished, I'll let @javabster know and we'll see if we can get a quick approval. Thanks a lot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TharrmashasthaPV I was wondering if you could have a look at this PR. It was started by @jsistos and I'm finishing it off. It accomplishes the goal, but you commented we are trying to eliminate adding header info in latex source. So is there a way to accomplish the same thing without the added
\newlength
? Thanks.
@enavarro51 I think we might have a hack for that.
qiskit/visualization/latex.py
Outdated
self._latex[wire_max][col] += ( | ||
" \\cds{-1}{\\settowidth{\\glen}{\\ensuremath{%s}}" | ||
" \\hspace{0.5em}\\hspace{\\glen}\\ensuremath{%s}}" % (gate_text, gate_text) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I could check, I think \hphantom
latex command also creates empty space as required. So I think on replacing lines 533-536 by
self._latex[wire_max][col] += (
" \\cds{-1}{\hspace{0.5em}\hphantom{\\ensuremath{%s}}"
"\\ensuremath{%s}}" % (gate_text, gate_text)
)
we should still get the required spacing correctly.
@@ -328,7 +330,7 @@ def _get_image_depth(self): | |||
# which take 4 columns | |||
base_type = None if not hasattr(op, "base_gate") else op.base_gate | |||
if isinstance(op, RZZGate) or isinstance(base_type, (U1Gate, PhaseGate, RZZGate)): | |||
column_width = 4 | |||
column_width = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying out some gates. I feel in the below circuit the gap between the first and the second layer of gates is large. I think this trouble arises whenever there is a large gate in the same layer as that of the symmetric gate.
from math import pi
qc = QuantumCircuit(4)
qc.u3(0.23123414,0.1223412343,0.3412342345,0)
qc.cu1(0.123456,1,2)
qc.rzz(pi,3,1)
qc.cp(pi/3,0,1)
qc.swap(0,1)
qc.draw('latex)
Do you think we can we do something about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could go back to 4 columns, but then the ZZ gate may overlap with the next layer of gates in case there aren't wider gates giving some extra space. (I'm not entirely sure, but I think ZZ is the only gate with such issue).
As @enavarro51 said in #6061, changing the number of columns based on the gate text may add unnecessary complexness. My take had been trying to use a smaller font for the labels, but I was unable to figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, if only RZZ allows for the overlap to happen, then maybe we could just split the column counts (5 for RZZ, 4 otherwise). The issue would still remain for RZZ gates in the same layer as other (large enough) gates, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a bit of a messy problem. I agree with @TharrmashasthaPV that the spacing is too wide. The problem is that qcircuit
takes care of spacing for gates, but doesn't know what to do with this arbitrary side text, so it deals with it as if it is just the 2 bullets and a vertical line in terms of horizontal space.
There's a simple (kind of) solution which is just to restrict the floats to 1 decimal and lower case ZZ (which is what it used to be), then set cols to increment by 3 instead of 5. Not perfect, but maybe acceptable?
But then you run into this.
Ultimately this should work the same as gates, where the sidetext is a special gate that expands the space to the next column based on the width of the text. Maybe need a \newcommand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe \phantom
could help to normalize the space?
Forcing the amount of decimals sounds like a too drastic solution to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about this issue a fair bit, tried using \phantom
but that didn't seem to resolve much. I think we need a way to dynamically change the number of columns depending on the length of the gate_text
. When the actual gate is drawn, is it always placed in the centre of the columns? If yes then as we increase the number of columns we will also inadvertently be increasing the space on the left of the gate. Maybe another solution would be to have gates with side text not placed in the centre of the columns but on the left hand side.
Hmm... this one got too deep in my todo-list. Does anybody now the situation here? |
Hey, @1ucian0. I believe it is as it appears to be - stuck. Everybody is in agreement on what the problem is, but so far none of the solutions works for all cases -
Maybe there's a LaTex whiz out there who has some new ideas. |
Pull Request Test Coverage Report for Build 1774968902
💛 - Coveralls |
Thanks for the update! The use of |
This is rather old sorry, and I'm obviously missing the full context, but in general I would expect the |
Summary
Fixes #6050
Continuation of #6061
Details and comments
This PR is a continuation of #6061 and resolves several merge conflicts with that PR. It corrects the spacing of the names for symmetrical gates in the latex drawer.