-
Notifications
You must be signed in to change notification settings - Fork 57
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
add topology enums and dispatch decorator #248
Open
boothby
wants to merge
8
commits into
dwavesystems:main
Choose a base branch
from
boothby:topo-enum
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e9f9aa
add topology enums and dispatch decorator
boothby 7701adb
better approach for decorators and dispatching
boothby 5b7d20d
improve test coverage; remove unused function
boothby 569df4e
added tests for defect_free functions
boothby 5fcbcb5
corrected failing tests
boothby 8f26d6a
fixed failing tests using old networkx
boothby b60e4de
tests for ImplementationHook
boothby e8bd004
review comments
boothby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,7 +26,8 @@ | |||||
|
||||||
from itertools import product | ||||||
|
||||||
from .common import _add_compatible_nodes, _add_compatible_edges, _add_compatible_terms | ||||||
from dwave_networkx.generators.common import _add_compatible_nodes, _add_compatible_edges, _add_compatible_terms | ||||||
from dwave_networkx.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
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: | ||||||
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. | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should be compared by identity since both are enum members, right?
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.
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.
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.
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).
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.
These changes should preferably be tracked in a changelog, possibly under breaking.