-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix typos and styling. #226
Changes from all commits
fcbd1a4
1ad8d98
c164faa
373201e
54a54c0
f02010d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
# | ||
# ================================================================================================ | ||
""" | ||
Tools to visualize Chimera lattices and weighted graph problems on them. | ||
Tools to visualize :term:`Chimera` lattices and weighted :term:`graph` problems on them. | ||
""" | ||
|
||
import networkx as nx | ||
|
@@ -28,33 +28,34 @@ | |
|
||
|
||
def chimera_layout(G, scale=1., center=None, dim=2): | ||
"""Positions the nodes of graph G in a Chimera cross topology. | ||
"""Positions the nodes of graph ``G`` in a Chimera layout. | ||
|
||
NumPy (https://scipy.org) is required for this function. | ||
Unit cells are rendered in a cross layout. | ||
|
||
Parameters | ||
---------- | ||
G : NetworkX graph | ||
Should be a Chimera graph or a subgraph of a | ||
Chimera graph. If every node in G has a `chimera_index` | ||
attribute, those are used to place the nodes. Otherwise makes | ||
a best-effort attempt to find positions. | ||
:term:`Chimera` :term:`graph` or :term:`subgraph` of a | ||
Chimera graph. If every node in ``G`` has a ``chimera_index`` | ||
attribute, the node position in the ``chimera_index`` | ||
attribute is used to place each node. Otherwise, | ||
a best-effort attempt is made to find the node positions. | ||
|
||
scale : float (default 1.) | ||
Scale factor. When scale = 1, all positions fit within [0, 1] | ||
Scale factor. If ``scale`` = 1, all positions fit within [0, 1] | ||
on the x-axis and [-1, 0] on the y-axis. | ||
|
||
center : None or array (default None) | ||
Coordinates of the top left corner. | ||
|
||
dim : int (default 2) | ||
Number of dimensions. When dim > 2, all extra dimensions are | ||
Number of dimensions. If ``dim`` > 2, all extra dimensions are | ||
set to 0. | ||
|
||
Returns | ||
------- | ||
pos : dict | ||
A dictionary of positions keyed by node. | ||
Dictionary of positions keyed by node. | ||
|
||
Examples | ||
-------- | ||
|
@@ -106,13 +107,13 @@ def chimera_layout(G, scale=1., center=None, dim=2): | |
|
||
|
||
def chimera_node_placer_2d(m, n, t, scale=1., center=None, dim=2): | ||
"""Generates a function that converts Chimera indices to x, y | ||
coordinates for a plot. | ||
"""Generates a function that converts Chimera indices to x- and | ||
y-coordinates for a plot. | ||
|
||
Parameters | ||
---------- | ||
m : int | ||
Number of rows in the Chimera lattice. | ||
Number of rows in the :term:`Chimera` lattice. | ||
|
||
n : int | ||
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): | |
Size of the shore within each Chimera tile. | ||
|
||
scale : float (default 1.) | ||
Scale factor. When scale = 1, all positions fit within [0, 1] | ||
Scale factor. If ``scale`` = 1, all positions fit within [0, 1] | ||
on the x-axis and [-1, 0] on the y-axis. | ||
|
||
center : None or array (default None) | ||
Coordinates of the top left corner. | ||
|
||
dim : int (default 2) | ||
Number of dimensions. When dim > 2, all extra dimensions are | ||
Number of dimensions. If ``dim`` > 2, all extra dimensions are | ||
set to 0. | ||
|
||
Returns | ||
------- | ||
xy_coords : function | ||
A function that maps a Chimera index (i, j, u, k) in an | ||
(m, n, t) Chimera lattice to x,y coordinates such as | ||
used by a plot. | ||
xy_coords : Function | ||
Function that maps a Chimera index ``(i, j, u, k)`` in an | ||
``(m, n, t)`` Chimera lattice to x- and y-coordinates. | ||
|
||
""" | ||
import numpy as np | ||
|
@@ -190,30 +190,31 @@ def _xy_coords(i, j, u, k): | |
|
||
|
||
def draw_chimera(G, **kwargs): | ||
"""Draws graph G in a Chimera cross topology. | ||
"""Draws graph ``G`` in a Chimera layout. | ||
|
||
If `linear_biases` and/or `quadratic_biases` are provided, these | ||
are visualized on the plot. | ||
Unit cells are rendered in a cross layout. | ||
|
||
Parameters | ||
---------- | ||
G : NetworkX graph | ||
Should be a Chimera graph or a subgraph of a Chimera graph. | ||
:term:`Chimera` :term:`graph` or a :term:`subgraph` of a Chimera graph. | ||
|
||
linear_biases : dict (optional, default {}) | ||
A dict of biases associated with each node in G. Should be of | ||
form {node: bias, ...}. Each bias should be numeric. | ||
Linear biases for all nodes of ``G`` as a dict of | ||
the form ``{node: bias, ...}``, where each bias is numeric. | ||
If specified, the linear biases are visualized on the plot. | ||
|
||
quadratic_biases : dict (optional, default {}) | ||
A dict of biases associated with each edge in G. Should be of | ||
form {edge: bias, ...}. Each bias should be numeric. Self-loop | ||
Quadratic biases for all edges of ``G`` as a dict of | ||
the form ``{edge: bias, ...}``, where each bias is numeric. Self-loop | ||
edges (i.e., :math:`i=j`) are treated as linear biases. | ||
If specified, the quadratic biases are visualized on the plot. | ||
|
||
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 | ||
function. If `linear_biases` or `quadratic_biases` are provided, | ||
any provided `node_color` or `edge_color` arguments are ignored. | ||
Parameters in :func:`~networkx.drawing.nx_pylab.draw_networkx`, except for the ``pos`` parameter. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it work with the simpler path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. @JoelPasvolsky? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also don't think so, |
||
If the ``linear_biases`` or ``quadratic_biases`` parameters are specified, | ||
the :func:`~networkx.drawing.nx_pylab.draw_networkx` ``node_color`` | ||
or ``edge_color`` parameters are ignored. | ||
|
||
Examples | ||
-------- | ||
|
@@ -230,87 +231,86 @@ def draw_chimera(G, **kwargs): | |
|
||
|
||
def draw_chimera_embedding(G, *args, **kwargs): | ||
"""Draws an embedding onto the chimera graph G, according to layout. | ||
|
||
If interaction_edges is not None, then only display the couplers in that | ||
list. If embedded_graph is not None, the only display the couplers between | ||
chains with intended couplings according to embedded_graph. | ||
"""Draws an embedding onto the Chimera graph ``G``. | ||
|
||
Parameters | ||
---------- | ||
G : NetworkX graph | ||
Should be a Chimera graph or a subgraph of a Chimera graph. | ||
:term:`Chimera` :term:`graph` or a :term:`subgraph` of a Chimera graph. | ||
|
||
emb : dict | ||
A dict of chains associated with each node in G. Should be | ||
of the form {node: chain, ...}. Chains should be iterables | ||
of qubit labels (qubits are nodes in G). | ||
Embedding for all nodes of ``G`` as a dict of chains | ||
of the form ``{node: chain, ...}``. where chains are iterables | ||
of qubit labels. Qubits are nodes in ``G``. | ||
|
||
embedded_graph : NetworkX graph (optional, default None) | ||
A graph which contains all keys of emb as nodes. If specified, | ||
edges of G will be considered interactions if and only if they | ||
exist between two chains of emb if their keys are connected by | ||
an edge in embedded_graph | ||
Graph which contains all keys of the ``emb`` parameter as nodes. If specified, | ||
the edges of ``G`` are considered to be interactions if and only if they | ||
exist between two chains of the ``emb`` parameter and if their keys are connected by | ||
an edge in the ``embedded_graph`` parameter; only the couplers for edges of ``G`` | ||
that are considered to be interactions are displayed. | ||
|
||
interaction_edges : list (optional, default None) | ||
A list of edges which will be used as interactions. | ||
Interactions as a list of edges. | ||
If this parameter is specified, only the couplers in the list are displayed. | ||
|
||
show_labels: boolean (optional, default False) | ||
If show_labels is True, then each chain in emb is labelled with its key. | ||
If True, each chain in the ``emb`` parameter is labelled with its key. | ||
|
||
chain_color : dict (optional, default None) | ||
A dict of colors associated with each key in emb. Should be | ||
of the form {node: rgba_color, ...}. Colors should be length-4 | ||
tuples of floats between 0 and 1 inclusive. If chain_color is None, | ||
each chain will be assigned a different color. | ||
Chain colors associated with each key in the ``emb`` parameter as a dict | ||
of the form ``{node: rgba_color, ...}``, where colors must be length-4 | ||
tuples of floats between 0 and 1, inclusive. If None, | ||
each chain is assigned a different color. | ||
|
||
unused_color : tuple (optional, default (0.9,0.9,0.9,1.0)) | ||
The color to use for nodes and edges of G which are not involved | ||
in chains, and edges which are neither chain edges nor interactions. | ||
If unused_color is None, these nodes and edges will not be shown at all. | ||
Color to use for graph ``G``'s nodes and edges that are not part of | ||
chains, and edges that are neither chain edges nor interactions. | ||
If None, these nodes and edges are not shown. | ||
|
||
overlapped_embedding: boolean (optional, default False) | ||
If overlapped_embedding is True, then chains in emb may overlap (contain | ||
the same vertices in G), and the drawing will display these overlaps as | ||
If True, chains in the ``emb`` parameter may overlap (contain | ||
the same vertices in ``G``), and the drawing displays these overlaps as | ||
concentric circles. | ||
|
||
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 | ||
function. If `linear_biases` or `quadratic_biases` are provided, | ||
any provided `node_color` or `edge_color` arguments are ignored. | ||
Parameters in :func:`~networkx.drawing.nx_pylab.draw_networkx`, except for the ``pos`` parameter. | ||
If the ``linear_biases`` or ``quadratic_biases`` parameters are specified, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were present in the original. Perhaps they are referring to the parameters in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest leaving this bit (for all three topographies) alone in this PR because I suspect the current functionality has problems that will be fixed by this PR. Currently, it seems to me that the
returns a In any case the other PR and this change have conflicts so leaving it untouched will save Kelly work. |
||
the :func:`~networkx.drawing.nx_pylab.draw_networkx` ``node_color`` | ||
or ``edge_color`` parameters are ignored. | ||
""" | ||
draw_embedding(G, chimera_layout(G), *args, **kwargs) | ||
|
||
|
||
def draw_chimera_yield(G, **kwargs): | ||
"""Draws the given graph G with highlighted faults, according to layout. | ||
"""Draws graph ``G`` with highlighted faults. | ||
|
||
Parameters | ||
---------- | ||
G : NetworkX graph | ||
The graph to be parsed for faults | ||
:term:`Graph` to be parsed for faults. | ||
|
||
unused_color : tuple or color string (optional, default (0.9,0.9,0.9,1.0)) | ||
The color to use for nodes and edges of G which are not faults. | ||
If unused_color is None, these nodes and edges will not be shown at all. | ||
Color to use for graph ``G``'s nodes and edges which are not faults. | ||
If None, these nodes and edges are not shown. | ||
|
||
fault_color : tuple or color string (optional, default (1.0,0.0,0.0,1.0)) | ||
A color to represent nodes absent from the graph G. Colors should be | ||
length-4 tuples of floats between 0 and 1 inclusive. | ||
Color to represent nodes that are absent from graph ``G``. Colors must be | ||
length-4 tuples of floats between 0 and 1, inclusive. | ||
|
||
fault_shape : string, optional (default='x') | ||
The shape of the fault nodes. Specification is as matplotlib.scatter | ||
marker, one of 'so^>v<dph8'. | ||
Shape of the fault nodes. The shapes are the same as those specified for | ||
`Matplotlib markers <https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers>`_. | ||
|
||
fault_style : string, optional (default='dashed') | ||
Edge fault line style (solid|dashed|dotted|dashdot) | ||
Line style for fault edges. The line style can be any of the following values: | ||
``'solid'``, ``'dashed'``, ``'dotted'``, ``'dashdot'``. | ||
|
||
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 | ||
function. If `linear_biases` or `quadratic_biases` are provided, | ||
any provided `node_color` or `edge_color` arguments are ignored. | ||
Parameters in :func:`~networkx.drawing.nx_pylab.draw_networkx`, except for the ``pos`` parameter. | ||
If the ``linear_biases`` or ``quadratic_biases`` parameters are specified, | ||
the :func:`~networkx.drawing.nx_pylab.draw_networkx` ``node_color`` | ||
or ``edge_color`` parameters are ignored. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "If the |
||
""" | ||
try: | ||
assert(G.graph["family"] == "chimera") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrt this comment, could we delete the phrase "in a Chimera cross topology"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function creates a Chimera layout that can then be plotted. It could have potentially realized the layout in different ways, in particular, the cross and column layouts shown here. The modifier "in a Chimera cross topology" is saying that the function selected to implement the cross layout.
"topology" is not the best word choice because it's used for the QPU connectivity (i.e. Chimera structure). So the info is needed but needs improved phrasing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"in a Chimera cross layout"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be okay or perhaps something like, "Positions a graph's nodes in a Chimera layout with unit cells as crosses."
Kelly uses "cross configuration" in Pegasus but I'm not sure that's clear to most users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the HTML rendering, it seems to me that the modifier "with unit cells as crosses" is given too much importance at the top-level by being in the one-line descriptions. For someone looking for Chimera graph functions, what's important at the top level is that function
chimera_layout
"Positions the nodes of a graph in a Chimera layout."If we provided column-layout too, it would make sense to specify at the top level the cross/column info. We just have the one option, so I'm inclined to put that in a separate, next line.