-
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
MPL drawer extended for drawing circuits with single classical bit conditioning #6259
Conversation
51c4b89
to
9108351
Compare
qiskit/visualization/matplotlib.py
Outdated
if cond_is_bit and self._cregbundle: | ||
cond_reg = self._bit_locations[op.condition[0]]["register"] | ||
ctrl_bit = self._bit_locations[op.condition[0]]["index"] | ||
label = "%s_%s=%s" % (cond_reg.name, ctrl_bit, hex(val)) |
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.
Does it make sense to do this in math notation "$%s_%s$=%s"
so that is comes out a subscript instead of an underscore?
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 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.
Agreed it is small. Since it should be zoomable on most devices, I'm ok with it. Probably one for final reviewer to decide.
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 better to leave it with the underscore so it is more accessible for users with limited eyesight, devices without zoom capabilities, screenshots etc.
qiskit/visualization/matplotlib.py
Outdated
for index, cbit in enumerate(self._clbit): | ||
if self._bit_locations[cbit]["register"] == node.op.condition[0]: | ||
mask |= 1 << index | ||
if cond_is_bit: | ||
for index, cbit in enumerate(self._clbit): | ||
if cbit == node.op.condition[0]: |
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 you have an extra for
loop at line 869.
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.
Ah. Thanks for pointing to out. Fixed it in 1d9c58f .
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.
LGTM. Thanks for the changes.
hey @TharrmashasthaPV when I run the binder tests at https://mybinder.org/v2/gh/TharrmashasthaPV/qiskit-terra/issue1160mpl?urlpath=apps/test/ipynb/mpl_tester.ipynb i see a few failures that should be fixed before this gets merged in 😄 |
Oh. Sorry for that. I have replaced the incorrect reference image with the right ones in 7dc2d59. I also made a small change to have hex under the control bit even for single bit conditions when cregbundle=False (This was not there in the previous commit ) like below: and brought back the underscore. |
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.
LGTM and snapshots now pass 👏
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.
Thanks!
Summary
Fixes part of #6475 . This PR extends the ability of the current mpl drawer to draw circuits that contain gates or instructions that are conditioned on a single classical bit.
Details and comments
This PR follows #6018 . #6018 breaks the mpl drawer when drawing circuits that contain instructions with single bit conditioning. This is an attempt at fixing this error. Two tests have been added. Examples of the mpl drawing are as below.
With cregbundle=True:
With cregbundle=False: