Skip to content
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

Add active wire notches to matplotlib drawings #1954

Merged
merged 17 commits into from
Dec 3, 2021
Merged

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Nov 30, 2021

Currently for multiwire gates, qml.drawer.MPLDrawer draws a box covering everything from the minimum wire to the maximum wire. This makes it impossible to tell which gates are actually used by the gate and which ones just happen to be placed between active wires.

This PR adds fancy boxes (rounded edges) at the edge of the gate box on the active wires. If all the "covered" wires are active, then no notches are drawn. Notches on active wires are only drawn if inactive wires exist.

image

It can be turned off via the keyword argument active_wire_notches = False to qml.draw_mpl, qml.drawer.tape_mpl, and qml.drawer.MPLDrawer.box_gate.

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@albi3ro albi3ro added the review-ready 👌 PRs which are ready for review by someone from the core team. label Dec 1, 2021
@codecov
Copy link

codecov bot commented Dec 1, 2021

Codecov Report

Merging #1954 (decb9cf) into master (911b2d3) will increase coverage by 1.94%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1954      +/-   ##
==========================================
+ Coverage   96.86%   98.80%   +1.94%     
==========================================
  Files         225      225              
  Lines       17123    17144      +21     
==========================================
+ Hits        16586    16939     +353     
+ Misses        537      205     -332     
Impacted Files Coverage Δ
pennylane/transforms/draw.py 100.00% <ø> (ø)
pennylane/drawer/mpldrawer.py 98.66% <100.00%> (+0.13%) ⬆️
pennylane/drawer/tape_mpl.py 100.00% <100.00%> (ø)
pennylane/interfaces/batch/__init__.py 100.00% <0.00%> (+0.89%) ⬆️
pennylane/interfaces/batch/tensorflow_autograph.py 100.00% <0.00%> (+1.17%) ⬆️
pennylane/beta/devices/default_tensor.py 96.94% <0.00%> (+1.69%) ⬆️
pennylane/interfaces/batch/tensorflow.py 100.00% <0.00%> (+2.04%) ⬆️
pennylane/beta/devices/default_tensor_tf.py 90.62% <0.00%> (+3.12%) ⬆️
pennylane/interfaces/batch/torch.py 100.00% <0.00%> (+3.27%) ⬆️
pennylane/devices/default_qubit_tf.py 90.00% <0.00%> (+3.33%) ⬆️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 911b2d3...decb9cf. Read the comment docs.

@albi3ro albi3ro requested a review from rmoyard December 1, 2021 20:44
@albi3ro albi3ro removed the request for review from rmoyard December 2, 2021 12:22
@KetpuntoG KetpuntoG self-requested a review December 3, 2021 08:34
def test_decimals():
"""Test decimals changes operation labelling"""
def test_decimals(self):
"""Test decimals changes operation labelling"""

Copy link
Contributor

Choose a reason for hiding this comment

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

From this test I understand that if I have RX(2), in the final drawing I should see RX(2), however, when I run it I only see RX.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Just a question, I didn't want to modify the code.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

f you want RX(2), you should use the decimals=0 keyword. decimals=None is the default and doesn't include any parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the documentation:

        decimals (int): How many decimal points to include when formatting operation parameters.
            Default ``None`` will omit parameters from operation labels.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, I was waiting by default to see it, but you're right 👍🙂

Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

I love the way it looks! 😍I just left a small comment to make sure.
I think it's very cool! 🚀

@albi3ro albi3ro merged commit 65332db into master Dec 3, 2021
@albi3ro albi3ro deleted the drawer_notches branch December 3, 2021 14:56
@antalszava
Copy link
Contributor

[sc-12054]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants