-
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #248 +/- ##
==========================================
+ Coverage 75.05% 76.68% +1.62%
==========================================
Files 31 32 +1
Lines 2213 2290 +77
==========================================
+ Hits 1661 1756 +95
+ Misses 552 534 -18 ☔ View full report in Codecov by Sentry. |
After some thought, I wasn't a fan of my first approach; it was a bit too kludgy. Re-reading the comments of dwavesystems/minorminer#210, @pau557 had given me a better suggestion for notation which I hadn't followed in the above. My revised approach collects generic methods into the enumeration members. Here, I avoid circular imports through the use of an With this new approach, I don't need to add generic functions to multiple files; instead, I collect their names into @CHIMERA.defect_free_graph.implementation
def defect_free_chimera(G):
... After making this change, my choice to use |
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.
Did a pass for code. Needs to ruminate on the design a bit. Will try to do another pass later today or tomorrow.
@@ -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: |
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?
if G.graph.get("family") == CHIMERA: | |
if G.graph.get("family") is 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.
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.
"""Construct a defect-free Chimera graph based on the properties of G.""" | ||
attrib = G.graph | ||
family = attrib.get('family') | ||
if 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.
if family != CHIMERA: | |
if family is not CHIMERA: |
Similarly in other files.
def defect_free_chimera(G): | ||
"""Construct a defect-free Chimera graph based on the properties of G.""" |
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.
Missing Parameters and Returns.
This is a preliminary patch to address #210 -- we add a
topology
enum todnx.topology
, and a decoratortopology_dispatch
.The topology enum is pretty simple, except that I want the machinery of py3.11's StrEnum (that is,
CHIMERA == 'chimera'
), so I fair-use'd barebones implementations of StrEnum and global_enum from the CPython3.11 library.The
topology_dispatch
decorator can be used to define a generic function in one file, and then in other files, define specializations based on the topology family. For example, I've added adefect_free
generic function indnx.generators.common
and then added specializations for each ofCHIMERA
,PEGASUS
,ZEPHYR
. Thus, to get a defect-free version of any qubit topology, one can simply calldnx.generators.common.defect_free(G)
.