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

Improvements to matplotlib drawing style and functionality #1931

Merged
merged 13 commits into from
Dec 1, 2021

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Nov 23, 2021

This minor PR accomplishes:

  • makes fontsize a documented public attribute
  • tape_mpl and draw_mpl accept fontsize as a keyword argument
  • adds a control_values keyword to the CNOT method. This will allow easy support for arbitrary MultiControlledX gates.
  • for control circles, both the face color and edge color are set to plt.rcParams['lines.color']
  • Substitues mpl.patches.FancyBboxPatch for plt.Rectangle. It looks better.

This PR will not add active wire notches. That will take enough design work that it will occupy it's own PR.

@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.

@codecov
Copy link

codecov bot commented Nov 26, 2021

Codecov Report

Merging #1931 (4a454e3) into master (da80317) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1931   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files         225      225           
  Lines       17175    17187   +12     
=======================================
+ Hits        16971    16983   +12     
  Misses        204      204           
Impacted Files Coverage Δ
pennylane/transforms/draw.py 100.00% <ø> (ø)
pennylane/drawer/mpldrawer.py 98.46% <100.00%> (+0.08%) ⬆️
pennylane/drawer/tape_mpl.py 100.00% <100.00%> (ø)

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 da80317...4a454e3. Read the comment docs.

@albi3ro albi3ro requested a review from rmoyard November 29, 2021 18:01
Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @albi3ro, should I check that every png image corresponds to actual circuit?


@fontsize.setter
def fontsize(self, value):
self._fontsize = value
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add a small docstring here.

@@ -562,11 +578,13 @@ def _ctrlo_circ(self, layer, wires, options=None):

self._ax.add_patch(circ_ctrlo)

def CNOT(self, layer, wires, options=None):
def CNOT(self, layer, wires, control_values=None, options=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Great addition 👍

@@ -162,6 +162,7 @@ def draw_mpl(qnode, wire_order=None, show_all_wires=False, decimals=None, **kwar
show_all_wires (bool): If True, all wires, including empty wires, are printed.
decimals (int): How many decimal points to include when formatting operation parameters.
Default ``None`` will omit parameters from operation labels.
fontsize (float or str): fontsize for text
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give example of what string we can pass as argument?

@albi3ro
Copy link
Contributor Author

albi3ro commented Nov 30, 2021

@rmoyard I've double-checked the documentation looks fine, and as long as they look good there, the images are good.

Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

Thanks @albi3ro it looks good to me 💯

@albi3ro albi3ro merged commit 42482b1 into master Dec 1, 2021
@albi3ro albi3ro deleted the mpldrawer_improvements branch December 1, 2021 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants