-
Notifications
You must be signed in to change notification settings - Fork 57
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
+109
−64
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,24 +102,6 @@ def draw_qubit_graph(G, layout, linear_biases={}, quadratic_biases={}, | |
if edgelist is None: | ||
edgelist = G.edges() | ||
|
||
# since we're applying the colormap here, matplotlib throws warnings if | ||
# we provide these arguments and it doesn't use them. | ||
if linear_biases: | ||
cmap = kwargs.pop('cmap', None) | ||
vmin = kwargs.pop('vmin', None) | ||
vmax = kwargs.pop('vmax', None) | ||
|
||
if quadratic_biases: | ||
edge_cmap = kwargs.pop('edge_cmap', None) | ||
edge_vmin = kwargs.pop('edge_vmin', None) | ||
edge_vmax = kwargs.pop('edge_vmax', None) | ||
|
||
if cmap is None: | ||
cmap = plt.get_cmap('coolwarm') | ||
|
||
if edge_cmap is None: | ||
edge_cmap = plt.get_cmap('coolwarm') | ||
|
||
# any edges or nodes with an unspecified bias default to 0 | ||
def edge_color(u, v): | ||
c = 0. | ||
|
@@ -143,17 +125,16 @@ def node_color(v): | |
# the range of the color map is shared for nodes/edges and is symmetric | ||
# around 0. | ||
vmag = max(max(abs(c) for c in node_color), max(abs(c) for c in edge_color)) | ||
if vmin is None: | ||
vmin = -1 * vmag | ||
|
||
if vmax is None: | ||
vmax = vmag | ||
|
||
if edge_vmin is None: | ||
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')) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the same question applies to all of these. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if linear_biases and quadratic_biases: | ||
global_vmin = min(edge_vmin, vmin) | ||
|
@@ -189,6 +170,14 @@ def node_color(v): | |
if ax is None: | ||
ax = fig.add_axes([0.01, 0.01, 0.98, 0.98]) | ||
|
||
if linear_biases and not quadratic_biases: | ||
kwargs['edge_vmin'] = edge_vmin | ||
kwargs['edge_vmax'] = edge_vmax | ||
kwargs['edge_cmap'] = edge_cmap | ||
if quadratic_biases and not linear_biases: | ||
kwargs['vmin'] = vmin | ||
kwargs['vmax'] = vmax | ||
kwargs['cmap'] = cmap | ||
draw(G, layout, ax=ax, nodelist=nodelist, edgelist=edgelist, **kwargs) | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is a change in semantics intended here? Consider the case when user supplies
cmap=None
.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.
The semantics should be the same. In the previous commit, we have
which would have the same behaviour. The issue is if
linear_biases
was never supplied, then the second conditional throws an error ascmap
is undefined.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.
No, previously if the function was called with
cmap=None
(explicitly set), you would end up withcmap = plt.get_cmap('coolwarm')
(assuming it doesn't fail).Now, if user explicitly sets
cmap=None
, the final value will becmap = None
.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, OK I misunderstood.