-
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
Open
enavarro51
wants to merge
21
commits into
Qiskit:main
Choose a base branch
from
enavarro51:fix6050_2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f114213
Fixed symmetrical gates bug in latex drawer
jsistos c1d97ad
Merge branch 'master' of https://github.com/Qiskit/qiskit-terra into …
jsistos 485120b
fixed tests with symmetrical gates
jsistos 9727a5a
Merge branch 'master' into fix6050
jsistos 1c1f580
Added variable hspace to latex output
jsistos 440f190
Merge branch 'master' of https://github.com/Qiskit/qiskit-terra into …
jsistos ed9b4ba
Merge branch 'fix6050' of https://github.com/jsistos/qiskit-terra int…
jsistos cf58afd
fixed lint
jsistos 7b98474
Updated number of symgate columns to 5
jsistos 43fcbed
Merge branch 'master' into fix6050
jsistos 2d95216
Merge branch 'master' into fix6050
jsistos 359ebb7
Merge branch 'master' into fix6050
jsistos e16ef50
Merge branch 'master' into fix6050
jsistos 795491a
Merge branch 'master' into fix6050
jsistos 32b5bca
Fix pull conflicts
enavarro51 8cb5d83
Fix ref images
enavarro51 207bc43
Lint
enavarro51 d1b8026
Fix latex merge conflicts
enavarro51 8172c4a
Lint
enavarro51 5e7d0df
Fix merge conflict
enavarro51 831921c
Merge branch 'main' into fix6050_2
1ucian0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,8 @@ def latex(self): | |
\usepackage{graphicx} | ||
|
||
\begin{document} | ||
% Delete the command below if there are no CP, CU1, RZZ in the circuit. | ||
\newlength{\glen} | ||
""" | ||
header_scale = "\\scalebox{{{}}}".format(self.scale) + "{" | ||
|
||
|
@@ -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 | ||
max_column_widths.append(current_max) | ||
columns += column_width | ||
|
||
|
@@ -527,8 +529,12 @@ def _build_symmetric_gate(self, op, gate_text, wire_list, col): | |
) | ||
self._latex[wire_last][col] = "\\control \\qw" | ||
# Put side text to the right between bottom wire in wire_list and the one above it | ||
self._latex[wire_max - 1][col + 1] = "\\dstick{\\hspace{2.0em}%s} \\qw" % gate_text | ||
return 4 # num_cols for side text gates | ||
# \settowidth allows redefining \glen to the width of the gate. This avoids overlapping. | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. As far as I could check, I think 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. |
||
return 5 # num_cols for side text gates | ||
|
||
def _build_measure(self, node, col): | ||
"""Build a meter and the lines to the creg""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
test/python/visualization/references/test_latex_boolean_negation.tex
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 thegate_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.