27
27
__all__ = ['chimera_layout' , 'draw_chimera' , 'draw_chimera_embedding' , 'draw_chimera_yield' ]
28
28
29
29
30
- def chimera_layout (G , scale = 1. , center = None , dim = 2 , normalize_kwargs = None ):
30
+ def chimera_layout (G , scale = 1. , center = None , dim = 2 , plot_kwargs = None ):
31
31
"""Positions the nodes of graph G in a Chimera cross topology.
32
32
33
33
NumPy (https://scipy.org) is required for this function.
@@ -51,10 +51,12 @@ def chimera_layout(G, scale=1., center=None, dim=2, normalize_kwargs = None):
51
51
Number of dimensions. When dim > 2, all extra dimensions are
52
52
set to 0.
53
53
54
- normalize_kwargs : None or dict (default None)
55
- A dict of keyword arguments to be used in a plotting function. If not
56
- None, we will populate the "ax" keyword with matplotlib axes, and the
57
- "node_size" and "width" keywords with defaults if they are not set.
54
+ plot_kwargs : None or dict (default None)
55
+ A dict of keyword arguments to be used in a plotting function (see
56
+ :func:`networkx.draw` and :func:`draw_lineplot`), to scale node and edge
57
+ sizes appropriately to the graph `G`. Optional keys in ``plot_kwargs``
58
+ are set to default values by the :func:`normalize_size_and_aspect`
59
+ function. Do nothing if ``plot_kwargs`` is None.
58
60
59
61
Returns
60
62
-------
@@ -80,7 +82,7 @@ def chimera_layout(G, scale=1., center=None, dim=2, normalize_kwargs = None):
80
82
n = G .graph ['columns' ]
81
83
t = G .graph ['tile' ]
82
84
# get a node placement function
83
- xy_coords = chimera_node_placer_2d (m , n , t , scale , center , dim , normalize_kwargs = normalize_kwargs )
85
+ xy_coords = chimera_node_placer_2d (m , n , t , scale , center , dim , plot_kwargs = plot_kwargs )
84
86
85
87
if G .graph ['labels' ] == 'coordinate' :
86
88
pos = {v : xy_coords (* v ) for v in G .nodes ()}
@@ -102,15 +104,15 @@ def chimera_layout(G, scale=1., center=None, dim=2, normalize_kwargs = None):
102
104
m = max (idx [0 ] for idx in chimera_indices .values ()) + 1
103
105
n = max (idx [1 ] for idx in chimera_indices .values ()) + 1
104
106
t = max (idx [3 ] for idx in chimera_indices .values ()) + 1
105
- xy_coords = chimera_node_placer_2d (m , n , t , scale , center , dim , normalize_kwargs = normalize_kwargs )
107
+ xy_coords = chimera_node_placer_2d (m , n , t , scale , center , dim , plot_kwargs = plot_kwargs )
106
108
107
109
# compute our coordinates
108
110
pos = {v : xy_coords (i , j , u , k ) for v , (i , j , u , k ) in chimera_indices .items ()}
109
111
110
112
return pos
111
113
112
114
113
- def chimera_node_placer_2d (m , n , t , scale = 1. , center = None , dim = 2 , normalize_kwargs = None ):
115
+ def chimera_node_placer_2d (m , n , t , scale = 1. , center = None , dim = 2 , plot_kwargs = None ):
114
116
"""Generates a function that converts Chimera indices to x, y
115
117
coordinates for a plot.
116
118
@@ -135,11 +137,13 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2, normalize_kwar
135
137
dim : int (default 2)
136
138
Number of dimensions. When dim > 2, all extra dimensions are
137
139
set to 0.
138
-
139
- normalize_kwargs : None or dict (default None)
140
- A dict of keyword arguments to be used in a plotting function. If not
141
- None, we will populate the "ax" keyword with matplotlib axes, and the
142
- "node_size" and "width" keywords with defaults if they are not set.
140
+
141
+ plot_kwargs : None or dict (default None)
142
+ A dict of keyword arguments to be used in a plotting function (see
143
+ :func:`networkx.draw` and :func:`draw_lineplot`), to scale node and edge
144
+ sizes appropriately to the graph `G`. Optional keys in ``plot_kwargs``
145
+ are set to default values by the :func:`normalize_size_and_aspect`
146
+ function. Do nothing if ``plot_kwargs`` is None.
143
147
144
148
Returns
145
149
-------
@@ -151,19 +155,20 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2, normalize_kwar
151
155
"""
152
156
import numpy as np
153
157
154
- line_plot = False if normalize_kwargs is None else normalize_kwargs .get ('line_plot' )
158
+ line_plot = False if plot_kwargs is None else plot_kwargs .get ('line_plot' )
155
159
156
160
center_pad = 0 if line_plot else 1
161
+ border_pad = 2
157
162
158
163
tile_center = t // 2
159
- tile_length = t + 2 + center_pad # 2 for spacing between tiles
164
+ tile_length = t + border_pad + center_pad
160
165
161
166
# want the enter plot to fill in [0, 1] when scale=1
162
- fabric_scale = max (m , n ) * tile_length - 2 - center_pad
167
+ fabric_scale = max (m , n ) * tile_length - border_pad - center_pad
163
168
scale /= fabric_scale
164
169
165
- if normalize_kwargs is not None :
166
- normalize_size_and_aspect (fabric_scale , 200 , normalize_kwargs )
170
+ if plot_kwargs is not None :
171
+ normalize_size_and_aspect (fabric_scale , 200 , plot_kwargs )
167
172
168
173
grid_offsets = {}
169
174
@@ -175,6 +180,7 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2, normalize_kwar
175
180
if dim < 2 :
176
181
raise ValueError ("layout must have at least two dimensions" )
177
182
183
+ # pad the dimensions beyond the second with zeros
178
184
paddims = np .zeros (dim - 2 , dtype = 'float' )
179
185
180
186
if len (center ) != dim :
@@ -241,12 +247,12 @@ def draw_chimera(G, **kwargs):
241
247
edges (i.e., :math:`i=j`) are treated as linear biases.
242
248
243
249
line_plot : boolean (optional, default False)
244
- If line_plot is True, then qubits are drawn as line segments, and edges
245
- are drawn either as line segments between qubits, or as circles where
246
- two qubits overlap. In this drawing style, the interpretation the width
247
- and node_size parameters (provided in kwargs) determines the area of the
248
- circles, and line widths, respectively. For more information, see
249
- :func:`dwave_networkx.qubit_layout.draw_lineplot`.
250
+ If `` line_plot`` is True, then qubits are drawn as line segments, and
251
+ edges are drawn either as line segments between qubits, or as circles
252
+ where two qubits overlap. In this drawing style, the interpretation of
253
+ the ``width`` and `` node_size`` parameters (provided in `` kwargs``)
254
+ determine the area of the circles and line widths respectively. See
255
+ :func:`dwave_networkx.qubit_layout.draw_lineplot` for more information .
250
256
251
257
kwargs : optional keywords
252
258
See networkx.draw_networkx() for a description of optional keywords,
@@ -265,7 +271,7 @@ def draw_chimera(G, **kwargs):
265
271
>>> plt.show() # doctest: +SKIP
266
272
267
273
"""
268
- layout = chimera_layout (G , normalize_kwargs = kwargs )
274
+ layout = chimera_layout (G , plot_kwargs = kwargs )
269
275
draw_qubit_graph (G , layout , ** kwargs )
270
276
271
277
def draw_chimera_embedding (G , * args , ** kwargs ):
@@ -314,20 +320,20 @@ def draw_chimera_embedding(G, *args, **kwargs):
314
320
concentric circles.
315
321
316
322
line_plot : boolean (optional, default False)
317
- If line_plot is True, then qubits are drawn as line segments, and edges
318
- are drawn either as line segments between qubits, or as circles where
319
- two qubits overlap. In this drawing style, the interpretation the width
320
- and node_size parameters (provided in kwargs) determines the area of the
321
- circles, and line widths, respectively. For more information, see
322
- :func:`dwave_networkx.qubit_layout.draw_lineplot`.
323
+ If `` line_plot`` is True, then qubits are drawn as line segments, and
324
+ edges are drawn either as line segments between qubits, or as circles
325
+ where two qubits overlap. In this drawing style, the interpretation of
326
+ the ``width`` and `` node_size`` parameters (provided in `` kwargs``)
327
+ determine the area of the circles and line widths respectively. See
328
+ :func:`dwave_networkx.qubit_layout.draw_lineplot` for more information .
323
329
324
330
kwargs : optional keywords
325
331
See networkx.draw_networkx() for a description of optional keywords,
326
332
with the exception of the `pos` parameter which is not used by this
327
333
function. If `linear_biases` or `quadratic_biases` are provided,
328
334
any provided `node_color` or `edge_color` arguments are ignored.
329
335
"""
330
- layout = chimera_layout (G , normalize_kwargs = kwargs )
336
+ layout = chimera_layout (G , plot_kwargs = kwargs )
331
337
draw_embedding (G , layout , * args , ** kwargs )
332
338
333
339
@@ -358,12 +364,12 @@ def draw_chimera_yield(G, **kwargs):
358
364
Edge fault line style (solid|dashed|dotted|dashdot)
359
365
360
366
line_plot : boolean (optional, default False)
361
- If line_plot is True, then qubits are drawn as line segments, and edges
362
- are drawn either as line segments between qubits, or as circles where
363
- two qubits overlap. In this drawing style, the interpretation the width
364
- and node_size parameters (provided in kwargs) determines the area of the
365
- circles, and line widths, respectively. For more information, see
366
- :func:`dwave_networkx.qubit_layout.draw_lineplot`.
367
+ If `` line_plot`` is True, then qubits are drawn as line segments, and
368
+ edges are drawn either as line segments between qubits, or as circles
369
+ where two qubits overlap. In this drawing style, the interpretation of
370
+ the ``width`` and `` node_size`` parameters (provided in `` kwargs``)
371
+ determine the area of the circles and line widths respectively. See
372
+ :func:`dwave_networkx.qubit_layout.draw_lineplot` for more information .
367
373
368
374
kwargs : optional keywords
369
375
See networkx.draw_networkx() for a description of optional keywords,
@@ -382,5 +388,5 @@ def draw_chimera_yield(G, **kwargs):
382
388
tile, and label attributes to be able to identify faulty qubits." )
383
389
384
390
perfect_graph = chimera_graph (m ,n ,t , coordinates = coordinates )
385
- layout = chimera_layout (perfect_graph , normalize_kwargs = kwargs )
391
+ layout = chimera_layout (perfect_graph , plot_kwargs = kwargs )
386
392
draw_yield (G , layout , perfect_graph , ** kwargs )
0 commit comments