Skip to content

Commit

Permalink
added line_plot option
Browse files Browse the repository at this point in the history
  • Loading branch information
boothby committed Dec 8, 2021
1 parent 6a7e608 commit 9288684
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 45 deletions.
44 changes: 41 additions & 3 deletions dwave_networkx/drawing/chimera_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import networkx as nx
from networkx import draw

from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect
from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect, draw_lineplot
from dwave_networkx.generators.chimera import chimera_graph, find_chimera_indices, chimera_coordinates


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

center_pad = 1
line_plot = False if normalize_kwargs is None else normalize_kwargs.get('line_plot')

center_pad = 0 if line_plot else 1

tile_center = t // 2
tile_length = t + 2 + center_pad # 2 for spacing between tiles

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

return _xy_coords
if line_plot:
qubit_dx = np.hstack(([(t + 1)/2, 0], paddims)) * scale
qubit_dy = np.hstack(([0, (t + 1)/2], paddims)) * scale
def _line_coords(i, j, u, k):
xy = _xy_coords(i, j, u, k)
if u:
return np.vstack((xy - qubit_dx, xy + qubit_dx))
else:
return np.vstack((xy - qubit_dy, xy + qubit_dy))
return _line_coords
else:
return _xy_coords


def draw_chimera(G, **kwargs):
Expand All @@ -226,6 +240,14 @@ def draw_chimera(G, **kwargs):
form {edge: bias, ...}. Each bias should be numeric. Self-loop
edges (i.e., :math:`i=j`) are treated as linear biases.
line_plot : boolean (optional, default False)
If line_plot is True, then qubits are drawn as line segments, and edges
are drawn either as line segments between qubits, or as circles where
two qubits overlap. In this drawing style, the interpretation the width
and node_size parameters (provided in kwargs) determines the area of the
circles, and line widths, respectively. For more information, see
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
kwargs : optional keywords
See networkx.draw_networkx() for a description of optional keywords,
with the exception of the `pos` parameter which is not used by this
Expand Down Expand Up @@ -291,6 +313,14 @@ def draw_chimera_embedding(G, *args, **kwargs):
the same vertices in G), and the drawing will display these overlaps as
concentric circles.
line_plot : boolean (optional, default False)
If line_plot is True, then qubits are drawn as line segments, and edges
are drawn either as line segments between qubits, or as circles where
two qubits overlap. In this drawing style, the interpretation the width
and node_size parameters (provided in kwargs) determines the area of the
circles, and line widths, respectively. For more information, see
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
kwargs : optional keywords
See networkx.draw_networkx() for a description of optional keywords,
with the exception of the `pos` parameter which is not used by this
Expand Down Expand Up @@ -327,6 +357,14 @@ def draw_chimera_yield(G, **kwargs):
fault_style : string, optional (default='dashed')
Edge fault line style (solid|dashed|dotted|dashdot)
line_plot : boolean (optional, default False)
If line_plot is True, then qubits are drawn as line segments, and edges
are drawn either as line segments between qubits, or as circles where
two qubits overlap. In this drawing style, the interpretation the width
and node_size parameters (provided in kwargs) determines the area of the
circles, and line widths, respectively. For more information, see
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
kwargs : optional keywords
See networkx.draw_networkx() for a description of optional keywords,
with the exception of the `pos` parameter which is not used by this
Expand Down
52 changes: 48 additions & 4 deletions dwave_networkx/drawing/pegasus_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import networkx as nx
from networkx import draw

from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect
from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield, normalize_size_and_aspect, draw_lineplot
from dwave_networkx.generators.pegasus import pegasus_graph, pegasus_coordinates
from dwave_networkx.drawing.chimera_layout import chimera_node_placer_2d

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

line_plot = False if normalize_kwargs is None else normalize_kwargs.get('line_plot')

if line_plot:
crosses = False

m = G.graph['rows']
h_offsets = G.graph["horizontal_offsets"]
v_offsets = G.graph["vertical_offsets"]
Expand Down Expand Up @@ -180,7 +185,19 @@ def _xy_coords(u, w, k, z):
# convention for Pegasus-lattice pictures is to invert the y-axis
return np.hstack((xy * scale, paddims)) + center

return _xy_coords

if line_plot:
qubit_dx = np.hstack(([5.75, 0], paddims)) * scale
qubit_dy = np.hstack(([0, 5.75], paddims)) * scale
def _line_coords(u, w, k, z):
xy = _xy_coords(u, w, k, z)
if u:
return np.vstack((xy - qubit_dx, xy + qubit_dx))
else:
return np.vstack((xy - qubit_dy, xy + qubit_dy))
return _line_coords
else:
return _xy_coords


def draw_pegasus(G, crosses=False, **kwargs):
Expand All @@ -207,7 +224,16 @@ def draw_pegasus(G, crosses=False, **kwargs):
crosses: boolean (optional, default False)
If True, :math:`K_{4,4}` subgraphs are shown in a cross
rather than L configuration. Ignored if G is defined with
``nice_coordinates=True``.
``nice_coordinates=True`` or ``line_plot=True``.
line_plot : boolean (optional, default False)
If line_plot is True, then qubits are drawn as line segments, and edges
are drawn either as line segments between qubits, or as circles where
two qubits overlap. In this drawing style, the interpretation the width
and node_size parameters (provided in kwargs) determines the area of the
circles, and line widths, respectively. For more information, see
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
kwargs : optional keywords
See networkx.draw_networkx() for a description of optional keywords,
Expand Down Expand Up @@ -277,6 +303,15 @@ def draw_pegasus_embedding(G, *args, crosses=False, **kwargs):
If True, chains in ``emb`` may overlap (contain the same vertices
in G), and these overlaps are displayed as concentric circles.
line_plot : boolean (optional, default False)
If line_plot is True, then qubits are drawn as line segments, and edges
are drawn either as line segments between qubits, or as circles where
two qubits overlap. In this drawing style, the interpretation the width
and node_size parameters (provided in kwargs) determines the area of the
circles, and line widths, respectively. For more information, see
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
kwargs : optional keywords
See networkx.draw_networkx() for a description of optional keywords,
with the exception of the ``pos`` parameter, which is not used by this
Expand Down Expand Up @@ -315,7 +350,16 @@ def draw_pegasus_yield(G, crosses=False, **kwargs):
crosses: boolean (optional, default False)
If True, :math:`K_{4,4}` subgraphs are shown in a cross
rather than L configuration. Ignored if G is defined with
``nice_coordinates=True``.
``nice_coordinates=True`` or ``line_plot=True``.
line_plot : boolean (optional, default False)
If line_plot is True, then qubits are drawn as line segments, and edges
are drawn either as line segments between qubits, or as circles where
two qubits overlap. In this drawing style, the interpretation the width
and node_size parameters (provided in kwargs) determines the area of the
circles, and line widths, respectively. For more information, see
:func:`dwave_networkx.qubit_layout.draw_lineplot`.
kwargs : optional keywords
See networkx.draw_networkx() for a description of optional keywords,
Expand Down
Loading

0 comments on commit 9288684

Please sign in to comment.