Skip to content

Commit 17a33a6

Browse files
authored
Merge pull request #226 from qwriter/copyedit_drawing
Fix typos and styling.
2 parents 4151e23 + f02010d commit 17a33a6

File tree

4 files changed

+226
-231
lines changed

4 files changed

+226
-231
lines changed

docs/reference/drawing.rst

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
Drawing
55
*******
66

7-
Tools to visualize topologies of D-Wave QPUs and weighted graph problems on them.
7+
Tools to visualize topologies of D-Wave QPUs and weighted :term:`graph` problems on them.
88

99
.. currentmodule:: dwave_networkx
1010

11-
.. note:: Some functionality requires `NumPy <https://scipy.org>`_ and/or
12-
`Matplotlib <https://matplotlib.org>`_\ .
13-
1411
Chimera Graph Functions
1512
-----------------------
1613

@@ -20,7 +17,10 @@ Chimera Graph Functions
2017
:toctree: generated/
2118

2219
chimera_layout
20+
chimera_node_placer_2d
2321
draw_chimera
22+
draw_chimera_embedding
23+
draw_chimera_yield
2424

2525
Example
2626
~~~~~~~
@@ -53,12 +53,13 @@ positions on a Chimera unit cell.
5353
>>> # matplotlib commands to add labels to graphic not shown
5454
5555
.. figure:: ../_images/chimera_layout_0-rightside.png
56-
:align: center
57-
:name: chimera_layout_0-rightside
58-
:scale: 60 %
59-
:alt: Graph H overlaid on a Chimera unit cell.
56+
:align: center
57+
:name: chimera_layout_0-rightside
58+
:scale: 60 %
59+
:alt: Graph H overlaid on a Chimera unit cell.
6060

61-
Graph H (blue) overlaid on a Chimera unit cell (red nodes and black edges).
61+
Graph ``H`` (blue) overlaid on a Chimera unit cell (red nodes and black edges),
62+
which is rendered in a cross layout.
6263

6364

6465
Pegasus Graph Functions
@@ -70,9 +71,10 @@ Pegasus Graph Functions
7071
:toctree: generated/
7172

7273
draw_pegasus
73-
draw_pegasus_embedding
74-
pegasus_layout
75-
pegasus_node_placer_2d
74+
draw_pegasus_embedding
75+
draw_pegasus_yield
76+
pegasus_layout
77+
pegasus_node_placer_2d
7678

7779
Example
7880
~~~~~~~
@@ -86,22 +88,23 @@ of nodes of a simple 5-node graph on a small Pegasus lattice.
8688
>>> import matplotlib.pyplot as plt
8789
>>> G = dnx.pegasus_graph(2)
8890
>>> H = dnx.pegasus_graph(2, node_list=[4, 40, 41, 42, 43],
89-
edge_list=[(4, 40), (4, 41), (4, 42), (4, 43)])
91+
edge_list=[(4, 40), (4, 41), (4, 42), (4, 43)])
9092
>>> # Show graph H on a small Pegasus lattice
9193
>>> plt.ion()
9294
>>> # Show graph H on a small Pegasus lattice
9395
>>> plt.ion()
9496
>>> dnx.draw_pegasus(G, with_labels=True, crosses=True, node_color="Yellow")
9597
>>> dnx.draw_pegasus(H, crosses=True, node_color='b', style='dashed',
96-
edge_color='b', width=3)
98+
edge_color='b', width=3)
9799
98100
.. figure:: ../_images/pegasus_layout_h_on_g.png
99-
:align: center
100-
:name: pegasus_layout_h_on_g.png
101-
:scale: 60 %
102-
:alt: Graph H overlaid on a Pegasus lattice size 2.
101+
:align: center
102+
:name: pegasus_layout_h_on_g.png
103+
:scale: 60 %
104+
:alt: Graph ``H`` overlaid on a Pegasus lattice size 2.
103105

104-
Graph H (blue) overlaid on a small Pegasus lattice(yellow nodes and black edges).
106+
Graph ``H`` (blue) overlaid on a small Pegasus lattice (yellow nodes and black edges),
107+
which is rendered in a cross layout.
105108

106109
Zephyr Graph Functions
107110
----------------------
@@ -112,9 +115,10 @@ Zephyr Graph Functions
112115
:toctree: generated/
113116

114117
draw_zephyr
115-
draw_zephyr_embedding
116-
draw_zephyr_yield
117-
zephyr_layout
118+
draw_zephyr_embedding
119+
draw_zephyr_yield
120+
zephyr_layout
121+
zephyr_node_placer_2d
118122

119123
Example
120124
~~~~~~~
@@ -135,9 +139,9 @@ of a five-node clique on a small Zephyr graph.
135139
>>> dnx.draw_zephyr_embedding(G, embedding, show_labels=True)
136140
137141
.. figure:: ../_images/zephyr_embedding_5clique.png
138-
:align: center
139-
:name: zephyr_embedding_5clique.png
140-
:scale: 60 %
141-
:alt: Five-node clique embedded in a small Zephyr graph.
142+
:align: center
143+
:name: zephyr_embedding_5clique.png
144+
:scale: 60 %
145+
:alt: Five-node clique embedded in a small Zephyr graph.
142146

143-
Five-node clique embedded in a small Zephyr graph.
147+
Five-node clique embedded in a small Zephyr graph.

dwave_networkx/drawing/chimera_layout.py

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# ================================================================================================
1616
"""
17-
Tools to visualize Chimera lattices and weighted graph problems on them.
17+
Tools to visualize :term:`Chimera` lattices and weighted :term:`graph` problems on them.
1818
"""
1919

2020
import networkx as nx
@@ -28,33 +28,34 @@
2828

2929

3030
def chimera_layout(G, scale=1., center=None, dim=2):
31-
"""Positions the nodes of graph G in a Chimera cross topology.
31+
"""Positions the nodes of graph ``G`` in a Chimera layout.
3232
33-
NumPy (https://scipy.org) is required for this function.
33+
Unit cells are rendered in a cross layout.
3434
3535
Parameters
3636
----------
3737
G : NetworkX graph
38-
Should be a Chimera graph or a subgraph of a
39-
Chimera graph. If every node in G has a `chimera_index`
40-
attribute, those are used to place the nodes. Otherwise makes
41-
a best-effort attempt to find positions.
38+
:term:`Chimera` :term:`graph` or :term:`subgraph` of a
39+
Chimera graph. If every node in ``G`` has a ``chimera_index``
40+
attribute, the node position in the ``chimera_index``
41+
attribute is used to place each node. Otherwise,
42+
a best-effort attempt is made to find the node positions.
4243
4344
scale : float (default 1.)
44-
Scale factor. When scale = 1, all positions fit within [0, 1]
45+
Scale factor. If ``scale`` = 1, all positions fit within [0, 1]
4546
on the x-axis and [-1, 0] on the y-axis.
4647
4748
center : None or array (default None)
4849
Coordinates of the top left corner.
4950
5051
dim : int (default 2)
51-
Number of dimensions. When dim > 2, all extra dimensions are
52+
Number of dimensions. If ``dim`` > 2, all extra dimensions are
5253
set to 0.
5354
5455
Returns
5556
-------
5657
pos : dict
57-
A dictionary of positions keyed by node.
58+
Dictionary of positions keyed by node.
5859
5960
Examples
6061
--------
@@ -106,13 +107,13 @@ def chimera_layout(G, scale=1., center=None, dim=2):
106107

107108

108109
def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2):
109-
"""Generates a function that converts Chimera indices to x, y
110-
coordinates for a plot.
110+
"""Generates a function that converts Chimera indices to x- and
111+
y-coordinates for a plot.
111112
112113
Parameters
113114
----------
114115
m : int
115-
Number of rows in the Chimera lattice.
116+
Number of rows in the :term:`Chimera` lattice.
116117
117118
n : int
118119
Number of columns in the Chimera lattice.
@@ -121,22 +122,21 @@ def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2):
121122
Size of the shore within each Chimera tile.
122123
123124
scale : float (default 1.)
124-
Scale factor. When scale = 1, all positions fit within [0, 1]
125+
Scale factor. If ``scale`` = 1, all positions fit within [0, 1]
125126
on the x-axis and [-1, 0] on the y-axis.
126127
127128
center : None or array (default None)
128129
Coordinates of the top left corner.
129130
130131
dim : int (default 2)
131-
Number of dimensions. When dim > 2, all extra dimensions are
132+
Number of dimensions. If ``dim`` > 2, all extra dimensions are
132133
set to 0.
133134
134135
Returns
135136
-------
136-
xy_coords : function
137-
A function that maps a Chimera index (i, j, u, k) in an
138-
(m, n, t) Chimera lattice to x,y coordinates such as
139-
used by a plot.
137+
xy_coords : Function
138+
Function that maps a Chimera index ``(i, j, u, k)`` in an
139+
``(m, n, t)`` Chimera lattice to x- and y-coordinates.
140140
141141
"""
142142
import numpy as np
@@ -190,30 +190,31 @@ def _xy_coords(i, j, u, k):
190190

191191

192192
def draw_chimera(G, **kwargs):
193-
"""Draws graph G in a Chimera cross topology.
193+
"""Draws graph ``G`` in a Chimera layout.
194194
195-
If `linear_biases` and/or `quadratic_biases` are provided, these
196-
are visualized on the plot.
195+
Unit cells are rendered in a cross layout.
197196
198197
Parameters
199198
----------
200199
G : NetworkX graph
201-
Should be a Chimera graph or a subgraph of a Chimera graph.
200+
:term:`Chimera` :term:`graph` or a :term:`subgraph` of a Chimera graph.
202201
203202
linear_biases : dict (optional, default {})
204-
A dict of biases associated with each node in G. Should be of
205-
form {node: bias, ...}. Each bias should be numeric.
203+
Linear biases for all nodes of ``G`` as a dict of
204+
the form ``{node: bias, ...}``, where each bias is numeric.
205+
If specified, the linear biases are visualized on the plot.
206206
207207
quadratic_biases : dict (optional, default {})
208-
A dict of biases associated with each edge in G. Should be of
209-
form {edge: bias, ...}. Each bias should be numeric. Self-loop
208+
Quadratic biases for all edges of ``G`` as a dict of
209+
the form ``{edge: bias, ...}``, where each bias is numeric. Self-loop
210210
edges (i.e., :math:`i=j`) are treated as linear biases.
211+
If specified, the quadratic biases are visualized on the plot.
211212
212213
kwargs : optional keywords
213-
See networkx.draw_networkx() for a description of optional keywords,
214-
with the exception of the `pos` parameter which is not used by this
215-
function. If `linear_biases` or `quadratic_biases` are provided,
216-
any provided `node_color` or `edge_color` arguments are ignored.
214+
Parameters in :func:`~networkx.drawing.nx_pylab.draw_networkx`, except for the ``pos`` parameter.
215+
If the ``linear_biases`` or ``quadratic_biases`` parameters are specified,
216+
the :func:`~networkx.drawing.nx_pylab.draw_networkx` ``node_color``
217+
or ``edge_color`` parameters are ignored.
217218
218219
Examples
219220
--------
@@ -230,87 +231,86 @@ def draw_chimera(G, **kwargs):
230231

231232

232233
def draw_chimera_embedding(G, *args, **kwargs):
233-
"""Draws an embedding onto the chimera graph G, according to layout.
234-
235-
If interaction_edges is not None, then only display the couplers in that
236-
list. If embedded_graph is not None, the only display the couplers between
237-
chains with intended couplings according to embedded_graph.
234+
"""Draws an embedding onto the Chimera graph ``G``.
238235
239236
Parameters
240237
----------
241238
G : NetworkX graph
242-
Should be a Chimera graph or a subgraph of a Chimera graph.
239+
:term:`Chimera` :term:`graph` or a :term:`subgraph` of a Chimera graph.
243240
244241
emb : dict
245-
A dict of chains associated with each node in G. Should be
246-
of the form {node: chain, ...}. Chains should be iterables
247-
of qubit labels (qubits are nodes in G).
242+
Embedding for all nodes of ``G`` as a dict of chains
243+
of the form ``{node: chain, ...}``. where chains are iterables
244+
of qubit labels. Qubits are nodes in ``G``.
248245
249246
embedded_graph : NetworkX graph (optional, default None)
250-
A graph which contains all keys of emb as nodes. If specified,
251-
edges of G will be considered interactions if and only if they
252-
exist between two chains of emb if their keys are connected by
253-
an edge in embedded_graph
247+
Graph which contains all keys of the ``emb`` parameter as nodes. If specified,
248+
the edges of ``G`` are considered to be interactions if and only if they
249+
exist between two chains of the ``emb`` parameter and if their keys are connected by
250+
an edge in the ``embedded_graph`` parameter; only the couplers for edges of ``G``
251+
that are considered to be interactions are displayed.
254252
255253
interaction_edges : list (optional, default None)
256-
A list of edges which will be used as interactions.
254+
Interactions as a list of edges.
255+
If this parameter is specified, only the couplers in the list are displayed.
257256
258257
show_labels: boolean (optional, default False)
259-
If show_labels is True, then each chain in emb is labelled with its key.
258+
If True, each chain in the ``emb`` parameter is labelled with its key.
260259
261260
chain_color : dict (optional, default None)
262-
A dict of colors associated with each key in emb. Should be
263-
of the form {node: rgba_color, ...}. Colors should be length-4
264-
tuples of floats between 0 and 1 inclusive. If chain_color is None,
265-
each chain will be assigned a different color.
261+
Chain colors associated with each key in the ``emb`` parameter as a dict
262+
of the form ``{node: rgba_color, ...}``, where colors must be length-4
263+
tuples of floats between 0 and 1, inclusive. If None,
264+
each chain is assigned a different color.
266265
267266
unused_color : tuple (optional, default (0.9,0.9,0.9,1.0))
268-
The color to use for nodes and edges of G which are not involved
269-
in chains, and edges which are neither chain edges nor interactions.
270-
If unused_color is None, these nodes and edges will not be shown at all.
267+
Color to use for graph ``G``'s nodes and edges that are not part of
268+
chains, and edges that are neither chain edges nor interactions.
269+
If None, these nodes and edges are not shown.
271270
272271
overlapped_embedding: boolean (optional, default False)
273-
If overlapped_embedding is True, then chains in emb may overlap (contain
274-
the same vertices in G), and the drawing will display these overlaps as
272+
If True, chains in the ``emb`` parameter may overlap (contain
273+
the same vertices in ``G``), and the drawing displays these overlaps as
275274
concentric circles.
276275
277276
kwargs : optional keywords
278-
See networkx.draw_networkx() for a description of optional keywords,
279-
with the exception of the `pos` parameter which is not used by this
280-
function. If `linear_biases` or `quadratic_biases` are provided,
281-
any provided `node_color` or `edge_color` arguments are ignored.
277+
Parameters in :func:`~networkx.drawing.nx_pylab.draw_networkx`, except for the ``pos`` parameter.
278+
If the ``linear_biases`` or ``quadratic_biases`` parameters are specified,
279+
the :func:`~networkx.drawing.nx_pylab.draw_networkx` ``node_color``
280+
or ``edge_color`` parameters are ignored.
282281
"""
283282
draw_embedding(G, chimera_layout(G), *args, **kwargs)
284283

285284

286285
def draw_chimera_yield(G, **kwargs):
287-
"""Draws the given graph G with highlighted faults, according to layout.
286+
"""Draws graph ``G`` with highlighted faults.
288287
289288
Parameters
290289
----------
291290
G : NetworkX graph
292-
The graph to be parsed for faults
291+
:term:`Graph` to be parsed for faults.
293292
294293
unused_color : tuple or color string (optional, default (0.9,0.9,0.9,1.0))
295-
The color to use for nodes and edges of G which are not faults.
296-
If unused_color is None, these nodes and edges will not be shown at all.
294+
Color to use for graph ``G``'s nodes and edges which are not faults.
295+
If None, these nodes and edges are not shown.
297296
298297
fault_color : tuple or color string (optional, default (1.0,0.0,0.0,1.0))
299-
A color to represent nodes absent from the graph G. Colors should be
300-
length-4 tuples of floats between 0 and 1 inclusive.
298+
Color to represent nodes that are absent from graph ``G``. Colors must be
299+
length-4 tuples of floats between 0 and 1, inclusive.
301300
302301
fault_shape : string, optional (default='x')
303-
The shape of the fault nodes. Specification is as matplotlib.scatter
304-
marker, one of 'so^>v<dph8'.
302+
Shape of the fault nodes. The shapes are the same as those specified for
303+
`Matplotlib markers <https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers>`_.
305304
306305
fault_style : string, optional (default='dashed')
307-
Edge fault line style (solid|dashed|dotted|dashdot)
306+
Line style for fault edges. The line style can be any of the following values:
307+
``'solid'``, ``'dashed'``, ``'dotted'``, ``'dashdot'``.
308308
309309
kwargs : optional keywords
310-
See networkx.draw_networkx() for a description of optional keywords,
311-
with the exception of the `pos` parameter which is not used by this
312-
function. If `linear_biases` or `quadratic_biases` are provided,
313-
any provided `node_color` or `edge_color` arguments are ignored.
310+
Parameters in :func:`~networkx.drawing.nx_pylab.draw_networkx`, except for the ``pos`` parameter.
311+
If the ``linear_biases`` or ``quadratic_biases`` parameters are specified,
312+
the :func:`~networkx.drawing.nx_pylab.draw_networkx` ``node_color``
313+
or ``edge_color`` parameters are ignored.
314314
"""
315315
try:
316316
assert(G.graph["family"] == "chimera")

0 commit comments

Comments
 (0)