Skip to content

Commit 9288684

Browse files
committed
added line_plot option
1 parent 6a7e608 commit 9288684

File tree

4 files changed

+384
-45
lines changed

4 files changed

+384
-45
lines changed

dwave_networkx/drawing/chimera_layout.py

+41-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import networkx as nx
2121
from networkx import draw
2222

23-
from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect
23+
from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect, draw_lineplot
2424
from dwave_networkx.generators.chimera import chimera_graph, find_chimera_indices, chimera_coordinates
2525

2626

@@ -151,7 +151,10 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2, normalize_kwar
151151
"""
152152
import numpy as np
153153

154-
center_pad = 1
154+
line_plot = False if normalize_kwargs is None else normalize_kwargs.get('line_plot')
155+
156+
center_pad = 0 if line_plot else 1
157+
155158
tile_center = t // 2
156159
tile_length = t + 2 + center_pad # 2 for spacing between tiles
157160

@@ -203,7 +206,18 @@ def _xy_coords(i, j, u, k):
203206
# convention for Chimera-lattice pictures is to invert the y-axis
204207
return np.hstack((xy * scale, paddims)) + center
205208

206-
return _xy_coords
209+
if line_plot:
210+
qubit_dx = np.hstack(([(t + 1)/2, 0], paddims)) * scale
211+
qubit_dy = np.hstack(([0, (t + 1)/2], paddims)) * scale
212+
def _line_coords(i, j, u, k):
213+
xy = _xy_coords(i, j, u, k)
214+
if u:
215+
return np.vstack((xy - qubit_dx, xy + qubit_dx))
216+
else:
217+
return np.vstack((xy - qubit_dy, xy + qubit_dy))
218+
return _line_coords
219+
else:
220+
return _xy_coords
207221

208222

209223
def draw_chimera(G, **kwargs):
@@ -226,6 +240,14 @@ def draw_chimera(G, **kwargs):
226240
form {edge: bias, ...}. Each bias should be numeric. Self-loop
227241
edges (i.e., :math:`i=j`) are treated as linear biases.
228242
243+
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+
229251
kwargs : optional keywords
230252
See networkx.draw_networkx() for a description of optional keywords,
231253
with the exception of the `pos` parameter which is not used by this
@@ -291,6 +313,14 @@ def draw_chimera_embedding(G, *args, **kwargs):
291313
the same vertices in G), and the drawing will display these overlaps as
292314
concentric circles.
293315
316+
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+
294324
kwargs : optional keywords
295325
See networkx.draw_networkx() for a description of optional keywords,
296326
with the exception of the `pos` parameter which is not used by this
@@ -327,6 +357,14 @@ def draw_chimera_yield(G, **kwargs):
327357
fault_style : string, optional (default='dashed')
328358
Edge fault line style (solid|dashed|dotted|dashdot)
329359
360+
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+
330368
kwargs : optional keywords
331369
See networkx.draw_networkx() for a description of optional keywords,
332370
with the exception of the `pos` parameter which is not used by this

dwave_networkx/drawing/pegasus_layout.py

+48-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import networkx as nx
2020
from networkx import draw
2121

22-
from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect
22+
from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect, draw_lineplot
2323
from dwave_networkx.generators.pegasus import pegasus_graph, pegasus_coordinates
2424
from dwave_networkx.drawing.chimera_layout import chimera_node_placer_2d
2525

@@ -133,6 +133,11 @@ def pegasus_node_placer_2d(G, scale=1., center=None, dim=2, crosses=False, norma
133133
"""
134134
import numpy as np
135135

136+
line_plot = False if normalize_kwargs is None else normalize_kwargs.get('line_plot')
137+
138+
if line_plot:
139+
crosses = False
140+
136141
m = G.graph['rows']
137142
h_offsets = G.graph["horizontal_offsets"]
138143
v_offsets = G.graph["vertical_offsets"]
@@ -180,7 +185,19 @@ def _xy_coords(u, w, k, z):
180185
# convention for Pegasus-lattice pictures is to invert the y-axis
181186
return np.hstack((xy * scale, paddims)) + center
182187

183-
return _xy_coords
188+
189+
if line_plot:
190+
qubit_dx = np.hstack(([5.75, 0], paddims)) * scale
191+
qubit_dy = np.hstack(([0, 5.75], paddims)) * scale
192+
def _line_coords(u, w, k, z):
193+
xy = _xy_coords(u, w, k, z)
194+
if u:
195+
return np.vstack((xy - qubit_dx, xy + qubit_dx))
196+
else:
197+
return np.vstack((xy - qubit_dy, xy + qubit_dy))
198+
return _line_coords
199+
else:
200+
return _xy_coords
184201

185202

186203
def draw_pegasus(G, crosses=False, **kwargs):
@@ -207,7 +224,16 @@ def draw_pegasus(G, crosses=False, **kwargs):
207224
crosses: boolean (optional, default False)
208225
If True, :math:`K_{4,4}` subgraphs are shown in a cross
209226
rather than L configuration. Ignored if G is defined with
210-
``nice_coordinates=True``.
227+
``nice_coordinates=True`` or ``line_plot=True``.
228+
229+
line_plot : boolean (optional, default False)
230+
If line_plot is True, then qubits are drawn as line segments, and edges
231+
are drawn either as line segments between qubits, or as circles where
232+
two qubits overlap. In this drawing style, the interpretation the width
233+
and node_size parameters (provided in kwargs) determines the area of the
234+
circles, and line widths, respectively. For more information, see
235+
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
236+
211237
212238
kwargs : optional keywords
213239
See networkx.draw_networkx() for a description of optional keywords,
@@ -277,6 +303,15 @@ def draw_pegasus_embedding(G, *args, crosses=False, **kwargs):
277303
If True, chains in ``emb`` may overlap (contain the same vertices
278304
in G), and these overlaps are displayed as concentric circles.
279305
306+
line_plot : boolean (optional, default False)
307+
If line_plot is True, then qubits are drawn as line segments, and edges
308+
are drawn either as line segments between qubits, or as circles where
309+
two qubits overlap. In this drawing style, the interpretation the width
310+
and node_size parameters (provided in kwargs) determines the area of the
311+
circles, and line widths, respectively. For more information, see
312+
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
313+
314+
280315
kwargs : optional keywords
281316
See networkx.draw_networkx() for a description of optional keywords,
282317
with the exception of the ``pos`` parameter, which is not used by this
@@ -315,7 +350,16 @@ def draw_pegasus_yield(G, crosses=False, **kwargs):
315350
crosses: boolean (optional, default False)
316351
If True, :math:`K_{4,4}` subgraphs are shown in a cross
317352
rather than L configuration. Ignored if G is defined with
318-
``nice_coordinates=True``.
353+
``nice_coordinates=True`` or ``line_plot=True``.
354+
355+
line_plot : boolean (optional, default False)
356+
If line_plot is True, then qubits are drawn as line segments, and edges
357+
are drawn either as line segments between qubits, or as circles where
358+
two qubits overlap. In this drawing style, the interpretation the width
359+
and node_size parameters (provided in kwargs) determines the area of the
360+
circles, and line widths, respectively. For more information, see
361+
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
362+
319363
320364
kwargs : optional keywords
321365
See networkx.draw_networkx() for a description of optional keywords,

0 commit comments

Comments
 (0)