2727__all__ = ['chimera_layout' , 'draw_chimera' , 'draw_chimera_embedding' , 'draw_chimera_yield' ]
2828
2929
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 ):
3131 """Positions the nodes of graph G in a Chimera cross topology.
3232
3333 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):
5151 Number of dimensions. When dim > 2, all extra dimensions are
5252 set to 0.
5353
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.
5860
5961 Returns
6062 -------
@@ -80,7 +82,7 @@ def chimera_layout(G, scale=1., center=None, dim=2, normalize_kwargs = None):
8082 n = G .graph ['columns' ]
8183 t = G .graph ['tile' ]
8284 # 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 )
8486
8587 if G .graph ['labels' ] == 'coordinate' :
8688 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):
102104 m = max (idx [0 ] for idx in chimera_indices .values ()) + 1
103105 n = max (idx [1 ] for idx in chimera_indices .values ()) + 1
104106 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 )
106108
107109 # compute our coordinates
108110 pos = {v : xy_coords (i , j , u , k ) for v , (i , j , u , k ) in chimera_indices .items ()}
109111
110112 return pos
111113
112114
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 ):
114116 """Generates a function that converts Chimera indices to x, y
115117 coordinates for a plot.
116118
@@ -135,11 +137,13 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2, normalize_kwar
135137 dim : int (default 2)
136138 Number of dimensions. When dim > 2, all extra dimensions are
137139 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.
143147
144148 Returns
145149 -------
@@ -151,19 +155,20 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2, normalize_kwar
151155 """
152156 import numpy as np
153157
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' )
155159
156160 center_pad = 0 if line_plot else 1
161+ border_pad = 2
157162
158163 tile_center = t // 2
159- tile_length = t + 2 + center_pad # 2 for spacing between tiles
164+ tile_length = t + border_pad + center_pad
160165
161166 # 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
163168 scale /= fabric_scale
164169
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 )
167172
168173 grid_offsets = {}
169174
@@ -175,6 +180,7 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2, normalize_kwar
175180 if dim < 2 :
176181 raise ValueError ("layout must have at least two dimensions" )
177182
183+ # pad the dimensions beyond the second with zeros
178184 paddims = np .zeros (dim - 2 , dtype = 'float' )
179185
180186 if len (center ) != dim :
@@ -241,12 +247,12 @@ def draw_chimera(G, **kwargs):
241247 edges (i.e., :math:`i=j`) are treated as linear biases.
242248
243249 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 .
250256
251257 kwargs : optional keywords
252258 See networkx.draw_networkx() for a description of optional keywords,
@@ -265,7 +271,7 @@ def draw_chimera(G, **kwargs):
265271 >>> plt.show() # doctest: +SKIP
266272
267273 """
268- layout = chimera_layout (G , normalize_kwargs = kwargs )
274+ layout = chimera_layout (G , plot_kwargs = kwargs )
269275 draw_qubit_graph (G , layout , ** kwargs )
270276
271277def draw_chimera_embedding (G , * args , ** kwargs ):
@@ -314,20 +320,20 @@ def draw_chimera_embedding(G, *args, **kwargs):
314320 concentric circles.
315321
316322 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 .
323329
324330 kwargs : optional keywords
325331 See networkx.draw_networkx() for a description of optional keywords,
326332 with the exception of the `pos` parameter which is not used by this
327333 function. If `linear_biases` or `quadratic_biases` are provided,
328334 any provided `node_color` or `edge_color` arguments are ignored.
329335 """
330- layout = chimera_layout (G , normalize_kwargs = kwargs )
336+ layout = chimera_layout (G , plot_kwargs = kwargs )
331337 draw_embedding (G , layout , * args , ** kwargs )
332338
333339
@@ -358,12 +364,12 @@ def draw_chimera_yield(G, **kwargs):
358364 Edge fault line style (solid|dashed|dotted|dashdot)
359365
360366 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 .
367373
368374 kwargs : optional keywords
369375 See networkx.draw_networkx() for a description of optional keywords,
@@ -382,5 +388,5 @@ def draw_chimera_yield(G, **kwargs):
382388 tile, and label attributes to be able to identify faulty qubits." )
383389
384390 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 )
386392 draw_yield (G , layout , perfect_graph , ** kwargs )
0 commit comments