-
Notifications
You must be signed in to change notification settings - Fork 58
add topology enums and dispatch decorator #248
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
5e9f9aa
7701adb
5b7d20d
569df4e
5fcbcb5
8f26d6a
b60e4de
e8bd004
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,12 +21,13 @@ | |||||
| from networkx import draw | ||||||
|
|
||||||
| from dwave_networkx.drawing.qubit_layout import draw_qubit_graph, draw_embedding, draw_yield | ||||||
| from dwave_networkx.generators.chimera import chimera_graph, find_chimera_indices, chimera_coordinates | ||||||
|
|
||||||
| from dwave_networkx.generators.chimera import find_chimera_indices, chimera_coordinates, defect_free_chimera | ||||||
| from ..topology import CHIMERA | ||||||
|
|
||||||
| __all__ = ['chimera_layout', 'draw_chimera', 'draw_chimera_embedding', 'draw_chimera_yield'] | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.layout.implementation | ||||||
| def chimera_layout(G, scale=1., center=None, dim=2): | ||||||
| """Positions the nodes of graph ``G`` in a Chimera layout. | ||||||
|
|
||||||
|
|
@@ -71,7 +72,7 @@ def chimera_layout(G, scale=1., center=None, dim=2): | |||||
|
|
||||||
| # now we get chimera coordinates for the translation | ||||||
| # first, check if we made it | ||||||
| if G.graph.get("family") == "chimera": | ||||||
| if G.graph.get("family") == CHIMERA: | ||||||
|
Contributor
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. Should be compared by identity since both are enum members, right?
Suggested change
Contributor
Author
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. My only concern with making that change is backwards-compatibilty with pickled graphs. I'm happy to make the change if you're unconcerned with that.
Contributor
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'm not particularly concerned, but I can't say that I'm aware of how much (if at all) this might disrupt some users that have old pickled instances of graphs. If so, keeping it as an eq comparison and adding a comment about it being kept for backward compatibility (potentially a deprecation note for the future).
Contributor
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 changes should preferably be tracked in a changelog, possibly under breaking. |
||||||
| m = G.graph['rows'] | ||||||
| n = G.graph['columns'] | ||||||
| t = G.graph['tile'] | ||||||
|
|
@@ -189,6 +190,7 @@ def _xy_coords(i, j, u, k): | |||||
| return _xy_coords | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.draw.implementation | ||||||
| def draw_chimera(G, **kwargs): | ||||||
| """Draws graph ``G`` in a Chimera layout. | ||||||
|
|
||||||
|
|
@@ -230,6 +232,7 @@ def draw_chimera(G, **kwargs): | |||||
| draw_qubit_graph(G, chimera_layout(G), **kwargs) | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.draw_embedding.implementation | ||||||
| def draw_chimera_embedding(G, *args, **kwargs): | ||||||
| """Draws an embedding onto the Chimera graph ``G``. | ||||||
|
|
||||||
|
|
@@ -282,6 +285,7 @@ def draw_chimera_embedding(G, *args, **kwargs): | |||||
| draw_embedding(G, chimera_layout(G), *args, **kwargs) | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.draw_yield.implementation | ||||||
| def draw_chimera_yield(G, **kwargs): | ||||||
| """Draws graph ``G`` with highlighted faults. | ||||||
|
|
||||||
|
|
@@ -312,16 +316,5 @@ def draw_chimera_yield(G, **kwargs): | |||||
| the :func:`~networkx.drawing.nx_pylab.draw_networkx` ``node_color`` | ||||||
| or ``edge_color`` parameters are ignored. | ||||||
| """ | ||||||
| try: | ||||||
| assert(G.graph["family"] == "chimera") | ||||||
| m = G.graph["rows"] | ||||||
| n = G.graph["columns"] | ||||||
| t = G.graph["tile"] | ||||||
| coordinates = G.graph["labels"] == "coordinate" | ||||||
| except: | ||||||
| raise ValueError("Target chimera graph needs to have columns, rows, \ | ||||||
| tile, and label attributes to be able to identify faulty qubits.") | ||||||
|
|
||||||
| perfect_graph = chimera_graph(m,n,t, coordinates=coordinates) | ||||||
|
|
||||||
| perfect_graph = defect_free_chimera(G) | ||||||
| draw_yield(G, chimera_layout(perfect_graph), perfect_graph, **kwargs) | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |||||
| from itertools import product | ||||||
|
|
||||||
| from .common import _add_compatible_nodes, _add_compatible_edges, _add_compatible_terms | ||||||
| from ..topology import CHIMERA | ||||||
|
|
||||||
| __all__ = ['chimera_graph', | ||||||
| 'chimera_coordinates', | ||||||
|
|
@@ -39,6 +40,7 @@ | |||||
| ] | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.generator.implementation | ||||||
| def chimera_graph(m, n=None, t=None, create_using=None, node_list=None, edge_list=None, | ||||||
| data=True, coordinates=False, check_node_list=False, check_edge_list=False): | ||||||
| """Creates a Chimera lattice of size (m, n, t). | ||||||
|
|
@@ -154,7 +156,7 @@ def chimera_graph(m, n=None, t=None, create_using=None, node_list=None, edge_lis | |||||
|
|
||||||
| G.name = "chimera_graph(%s, %s, %s)" % (m, n, t) | ||||||
|
|
||||||
| construction = (("family", "chimera"), ("rows", m), ("columns", n), | ||||||
| construction = (("family", CHIMERA), ("rows", m), ("columns", n), | ||||||
| ("tile", t), ("data", data), | ||||||
| ("labels", "coordinate" if coordinates else "int")) | ||||||
|
|
||||||
|
|
@@ -252,6 +254,18 @@ def checkadd(v, q): | |||||
| return G | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.defect_free_graph.implementation | ||||||
| def defect_free_chimera(G): | ||||||
| """Construct a defect-free Chimera graph based on the properties of G.""" | ||||||
|
Comment on lines
+258
to
+259
Contributor
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. Missing Parameters and Returns. |
||||||
| attrib = G.graph | ||||||
| family = attrib.get('family') | ||||||
| if family != CHIMERA: | ||||||
|
Contributor
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.
Suggested change
Similarly in other files. |
||||||
| raise ValueError("G must be constructed by dwave_networkx.chimera_graph") | ||||||
| args = attrib['rows'], attrib['columns'], attrib['tile'] | ||||||
| kwargs = {'coordinates': attrib['labels'] == 'coordinate'} | ||||||
| return chimera_graph(*args, **kwargs) | ||||||
|
|
||||||
|
|
||||||
| def find_chimera_indices(G): | ||||||
| """Determines the Chimera indices of the nodes in graph ``G``. | ||||||
|
|
||||||
|
|
@@ -331,6 +345,7 @@ def find_chimera_indices(G): | |||||
| raise Exception('not yet implemented for Chimera graphs with more than one tile') | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.coordinates.implementation | ||||||
| class chimera_coordinates(object): | ||||||
| """Provides coordinate converters for the chimera indexing scheme. | ||||||
|
|
||||||
|
|
@@ -681,7 +696,7 @@ def mapping(q): | |||||
|
|
||||||
| return mapping | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.sublattice_mappings.implementation | ||||||
| def chimera_sublattice_mappings(source, target, offset_list=None): | ||||||
| r"""Yields mappings from a Chimera graph into a larger Chimera graph. | ||||||
|
|
||||||
|
|
@@ -738,7 +753,7 @@ def chimera_sublattice_mappings(source, target, offset_list=None): | |||||
| into account, this function does not handle that complex task. | ||||||
|
|
||||||
| """ | ||||||
| if not (source.graph.get('family') == target.graph.get('family') == 'chimera'): | ||||||
| if not (source.graph.get('family') == target.graph.get('family') == CHIMERA): | ||||||
| raise ValueError("source and target graphs must be Chimera graphs constructed by dwave_networkx.chimera_graph") | ||||||
|
|
||||||
| t = source.graph['tile'] | ||||||
|
|
@@ -775,6 +790,8 @@ def chimera_to_target(q): | |||||
| for offset in offset_list: | ||||||
| yield _chimera_sublattice_mapping(source_to_chimera, chimera_to_target, offset) | ||||||
|
|
||||||
|
|
||||||
| @CHIMERA.torus_generator.implementation | ||||||
| def chimera_torus(m, n=None, t=None, node_list=None, edge_list=None): | ||||||
| """Creates a defect-free Chimera lattice of size :math:`(m, n, t)` | ||||||
| subject to periodic boundary conditions. | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.