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
2020import networkx as nx
2828
2929
3030def 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
108109def 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
192192def 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
232233def 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
286285def 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