-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Latex drawer extended for drawing circuits with single classical bit conditioning #6248
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
Conversation
qiskit/visualization/latex.py
Outdated
cond_is_bit = isinstance(op.condition[0], Clbit) | ||
if cond_is_bit: | ||
cond_reg = self.bit_locations[op.condition[0]]["register"] | ||
else: | ||
cond_reg = op.condition[0] | ||
creg_size = self.cregs[cond_reg] | ||
if cond_is_bit: | ||
if_value = op.condition[1] | ||
else: | ||
if_value = format(op.condition[1], "b").zfill(creg_size) | ||
if not cond_is_bit: | ||
if not self.reverse_bits: | ||
if_value = if_value[::-1] |
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.
cond_is_bit = isinstance(op.condition[0], Clbit)
creg_size = self.cregs[cond_reg]
if cond_is_bit:
cond_reg = self.bit_locations[op.condition[0]]["register"]
if_value = op.condition[1]
else:
cond_reg = op.condition[0]
if_value = format(op.condition[1], "b").zfill(creg_size)
if not self.reverse_bits:
if_value = if_value[::-1]
This might be a bit more compact.
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.
There is a failing test. The rest, looks good to me. Thanks!
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.
Awesome!
Add the assertion that the generated file is equal to the reference, and correct the reference file, from its inclusion in Qiskit#6248. The extra spacing added in the identifiers is consistent with a similar fix made to `test_latex_cif_single_bit.tex` within that PR, and the inclusion of the additional `\mathrm` macros appears to be a deliberate choice for bundles specifically (in `qiskit/visualization/latex.py`, current lines 247--248).
Add the assertion that the generated file is equal to the reference, and correct the reference file, from its inclusion in #6248. The extra spacing added in the identifiers is consistent with a similar fix made to `test_latex_cif_single_bit.tex` within that PR, and the inclusion of the additional `\mathrm` macros appears to be a deliberate choice for bundles specifically (in `qiskit/visualization/latex.py`, current lines 247--248). Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
Fixes part of #6475 . This PR extends the current latex drawer to draw circuits that contain gates or instructions that are conditioned on a single classical bit.
Details and comments
This PR is a follow up of #6018 . The current latex drawer raises error when trying to draw a circuit that contains single bit conditioned gates. This PR tries to fix this error. A test has also been added. Examples of latex drawing are as below.