Skip to content

Conversation

TharrmashasthaPV
Copy link
Contributor

@TharrmashasthaPV TharrmashasthaPV commented Apr 16, 2021

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.

img

img1

@TharrmashasthaPV TharrmashasthaPV changed the title [WIP] Latex drawer extended for drawing circuits with single classical bit conditioning Latex drawer extended for drawing circuits with single classical bit conditioning May 27, 2021
@TharrmashasthaPV TharrmashasthaPV marked this pull request as ready for review May 27, 2021 19:53
Comment on lines 597 to 609
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]
Copy link
Contributor

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.

Copy link
Member

@1ucian0 1ucian0 left a 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!

Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@1ucian0 1ucian0 added Changelog: None Do not include in changelog automerge labels Sep 23, 2021
@mergify mergify bot merged commit 7c88153 into Qiskit:main Sep 23, 2021
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Sep 27, 2021
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).
mergify bot added a commit that referenced this pull request Sep 28, 2021
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>
@kdk kdk added this to the 0.19 milestone Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants