Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d1d6690

Browse files
committedDec 10, 2021
reworked yield_plot to be more readable
1 parent 11a2def commit d1d6690

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed
 

‎dwave_networkx/drawing/chimera_layout.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,13 @@ def draw_chimera_yield(G, **kwargs):
314314
If unused_color is None, these nodes and edges will not be shown at all.
315315
316316
fault_color : tuple or color string (optional, default (1.0,0.0,0.0,1.0))
317-
A color to represent nodes absent from the graph G. Colors should be
317+
A color to represent nodes absent from the graph G.
318+
319+
incident_fault_color : tuple or color string (optional, default (1.0,0.8,0.8,1.0))
320+
A color to represent edges incident to faulty nodes. Colors should be
318321
length-4 tuples of floats between 0 and 1 inclusive.
319322
320-
fault_shape : string, optional (default='x')
323+
fault_shape : string, optional (default='o')
321324
The shape of the fault nodes. Specification is as matplotlib.scatter
322325
marker, one of 'so^>v<dph8'.
323326
@@ -343,4 +346,3 @@ def draw_chimera_yield(G, **kwargs):
343346
perfect_graph = chimera_graph(m,n,t, coordinates=coordinates)
344347
layout = chimera_layout(perfect_graph, normalize_kwargs = kwargs)
345348
draw_yield(G, layout, perfect_graph, **kwargs)
346-

‎dwave_networkx/drawing/pegasus_layout.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,13 @@ def draw_pegasus_yield(G, crosses=False, **kwargs):
299299
If unused_color is None, these nodes and edges will not be shown at all.
300300
301301
fault_color : tuple or color string (optional, default (1.0,0.0,0.0,1.0))
302-
A color to represent nodes absent from the graph G. Colors should be
302+
A color to represent nodes absent from the graph G.
303+
304+
incident_fault_color : tuple or color string (optional, default (1.0,0.8,0.8,1.0))
305+
A color to represent edges incident to faulty nodes. Colors should be
303306
length-4 tuples of floats between 0 and 1 inclusive.
304307
305-
fault_shape : string, optional (default='x')
308+
fault_shape : string, optional (default='o')
306309
The shape of the fault nodes. Specification is as matplotlib.scatter
307310
marker, one of 'so^>v<dph8'.
308311

‎dwave_networkx/drawing/qubit_layout.py

+26-27
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ def unoverlapped_embedding(G, emb, interaction_edges):
424424

425425

426426
def draw_yield(G, layout, perfect_graph, unused_color=(0.9,0.9,0.9,1.0),
427-
fault_color=(1.0,0.0,0.0,1.0), fault_shape='x',
428-
fault_style='dashed', **kwargs):
429-
427+
fault_color=(1.0,0.0,0.0,1.0), fault_shape='o',
428+
fault_style='dashed', incident_fault_color=(1.0,0.8,0.8,1.0),
429+
**kwargs):
430430
"""Draws the given graph G with highlighted faults, according to layout.
431431
432432
Parameters
@@ -442,16 +442,19 @@ def draw_yield(G, layout, perfect_graph, unused_color=(0.9,0.9,0.9,1.0),
442442
perfect_graph : NetworkX graph
443443
The graph to be drawn with highlighted faults
444444
445-
446445
unused_color : tuple or color string (optional, default (0.9,0.9,0.9,1.0))
447446
The color to use for nodes and edges of G which are not faults.
448447
If unused_color is None, these nodes and edges will not be shown at all.
449448
450449
fault_color : tuple or color string (optional, default (1.0,0.0,0.0,1.0))
451-
A color to represent nodes absent from the graph G. Colors should be
450+
A color to represent nodes absent from the graph G, and edges absent
451+
from the graph G which are not incident to faulty nodes.
452+
453+
incident_fault_color : tuple or color string (optional, default (1.0,0.8,0.8,1.0))
454+
A color to represent edges incident to faulty nodes. Colors should be
452455
length-4 tuples of floats between 0 and 1 inclusive.
453456
454-
fault_shape : string, optional (default='x')
457+
fault_shape : string, optional (default='o')
455458
The shape of the fault nodes. Specification is as matplotlib.scatter
456459
marker, one of 'so^>v<dph8'.
457460
@@ -468,37 +471,33 @@ def draw_yield(G, layout, perfect_graph, unused_color=(0.9,0.9,0.9,1.0),
468471
import matplotlib.pyplot as plt
469472
import matplotlib as mpl
470473
except ImportError:
471-
raise ImportError("Matplotlib and numpy required for draw_chimera()")
474+
raise ImportError("Matplotlib and numpy required for draw_yield()")
472475

476+
edgeset = lambda E: set(map(lambda e: tuple(sorted(e)), E))
473477
nodelist = G.nodes()
474478
edgelist = G.edges()
479+
475480
faults_nodelist = perfect_graph.nodes() - nodelist
476-
faults_edgelist = perfect_graph.edges() - edgelist
481+
incident_edgelist = edgeset(perfect_graph.edges) - edgeset(perfect_graph.subgraph(nodelist).edges)
482+
faults_edgelist = edgeset(perfect_graph.subgraph(nodelist).edges) - edgeset(G.edges)
477483

478-
# To avoid matplotlib.pyplot.scatter warnings for single tuples, create
479-
# lists of colors from given colors.
480484
faults_node_color = [fault_color for v in faults_nodelist]
481-
faults_edge_color = [fault_color for v in faults_edgelist]
485+
faults_edge_color = [fault_color for e in faults_edgelist]
486+
incident_edge_color = [incident_fault_color for e in incident_edgelist]
482487

483-
# Draw faults with different style and shape
484-
draw(perfect_graph, layout, nodelist=faults_nodelist, edgelist=faults_edgelist,
485-
node_color=faults_node_color, edge_color=faults_edge_color,
486-
style=fault_style, node_shape=fault_shape,
487-
**kwargs )
488-
489-
# Draw rest of graph
488+
# Draw edges first, in the order (unused, incident, faults)
490489
if unused_color is not None:
491-
if nodelist is None:
492-
nodelist = G.nodes() - faults_nodelist
493-
if edgelist is None:
494-
edgelist = G.edges() - faults_edgelist
490+
unused_edge_color = [unused_color for e in G.edges()]
491+
nx.draw_networkx_edges(G, layout, edge_color=unused_edge_color, **kwargs)
492+
nx.draw_networkx_edges(perfect_graph, layout, incident_edgelist, style=fault_style, edge_color=incident_edge_color, **kwargs)
493+
nx.draw_networkx_edges(perfect_graph, layout, faults_edgelist, style=fault_style, edge_color=faults_edge_color, **kwargs)
495494

496-
unused_node_color = [unused_color for v in nodelist]
497-
unused_edge_color = [unused_color for v in edgelist]
495+
# Draw nodes second, in the order (unused, faults)
496+
if unused_color is not None:
497+
unused_node_color = [unused_color for e in G]
498+
nx.draw_networkx_nodes(G, layout, node_color = unused_node_color, **kwargs)
499+
nx.draw_networkx_nodes(perfect_graph, layout, faults_nodelist, node_shape=fault_shape, node_color=faults_node_color, **kwargs)
498500

499-
draw(perfect_graph, layout, nodelist=nodelist, edgelist=edgelist,
500-
node_color=unused_node_color, edge_color=unused_edge_color,
501-
**kwargs)
502501

503502
def normalize_size_and_aspect(scale, node_scale, kwargs):
504503
ax = kwargs.get('ax')

‎dwave_networkx/drawing/zephyr_layout.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,13 @@ def draw_zephyr_yield(G, **kwargs):
265265
If unused_color is None, these nodes and edges will not be shown at all.
266266
267267
fault_color : tuple or color string (optional, default (1.0,0.0,0.0,1.0))
268-
A color to represent nodes absent from the graph G. Colors should be
268+
A color to represent nodes absent from the graph G.
269+
270+
incident_fault_color : tuple or color string (optional, default (1.0,0.5,0.5,1.0))
271+
A color to represent edges incident to faulty nodes. Colors should be
269272
length-4 tuples of floats between 0 and 1 inclusive.
270273
271-
fault_shape : string, optional (default='x')
274+
fault_shape : string, optional (default='o')
272275
The shape of the fault nodes. Specification is as matplotlib.scatter
273276
marker, one of 'so^>v<dph8'.
274277

0 commit comments

Comments
 (0)
Please sign in to comment.