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

Fix undefined variables for color maps #233

Merged
merged 4 commits into from
Jan 18, 2024

Conversation

kevinchern
Copy link
Contributor

For this issue #232

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Attention: 28 lines in your changes are missing coverage. Please review.

Comparison is base (f845fc2) 75.51% compared to head (ab7c3c9) 75.92%.

Files Patch % Lines
dwave_networkx/drawing/qubit_layout.py 6.66% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #233      +/-   ##
==========================================
+ Coverage   75.51%   75.92%   +0.41%     
==========================================
  Files          31       31              
  Lines        2193     2181      -12     
==========================================
  Hits         1656     1656              
+ Misses        537      525      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@randomir randomir left a comment

Choose a reason for hiding this comment

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

Since you're already touching linear_biases/quadratic_biases here, would you mind fixing their mutable default argument?

Also, adding (at least some smoke) tests for draw_qubit_graph that verify the fix would be nice.

edge_vmin = -1 * vmag
# since we're applying the colormap here, matplotlib throws warnings if
# we provide these arguments and it doesn't use them.
cmap = kwargs.pop('cmap', plt.get_cmap('coolwarm'))
Copy link
Member

Choose a reason for hiding this comment

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

Is a change in semantics intended here? Consider the case when user supplies cmap=None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The semantics should be the same. In the previous commit, we have

if linear_biases:
    cmap = kwargs.pop('cmap', None)
...
if cmap is None:
    cmap = plt.get_cmap('coolwarm')

which would have the same behaviour. The issue is if linear_biases was never supplied, then the second conditional throws an error as cmap is undefined.

Copy link
Member

Choose a reason for hiding this comment

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

No, previously if the function was called with cmap=None (explicitly set), you would end up with cmap = plt.get_cmap('coolwarm') (assuming it doesn't fail).

Now, if user explicitly sets cmap=None, the final value will be cmap = None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AH, OK I misunderstood.

Comment on lines 132 to 137
vmin = kwargs.pop('vmin', -1 * vmag)
vmax = kwargs.pop('vmax', vmag)

if edge_vmax is None:
edge_vmax = vmag
edge_cmap = kwargs.pop('edge_cmap', plt.get_cmap('coolwarm'))
edge_vmin = kwargs.pop('edge_vmin', -1 * vmag)
edge_vmax = kwargs.pop('edge_vmax', vmag)
Copy link
Member

Choose a reason for hiding this comment

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

Actually, the same question applies to all of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kevinchern
Copy link
Contributor Author

I'll put in some tests


@unittest.skipUnless(np and plt, "No numpy or matplotlib")
class TestDrawing(unittest.TestCase):
@unittest.skipUnless(_display, " No display found")
Copy link
Member

Choose a reason for hiding this comment

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

Not sure you need this if using non-interactive matplotlib backend. Btw, which backend is used here? Hopefully not interactive..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

# since we're applying the colormap here, matplotlib throws warnings if
# we provide these arguments and it doesn't use them.
cmap = kwargs.pop('cmap', None) or plt.get_cmap('coolwarm')
vmin = kwargs.pop('vmin', None) or -1 * vmag
Copy link
Member

Choose a reason for hiding this comment

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

or might not be what you want here. E.g. if user explicitly sets vmin=0, you override it to -vmag.

Copy link
Member

Choose a reason for hiding this comment

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

When I say "here", I mean in this line, and a few other lines below.

Copy link
Member

@randomir randomir left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for all the updates, and sorry I missed your last one.

@arcondello arcondello merged commit 7c56d30 into dwavesystems:main Jan 18, 2024
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.

4 participants