add topology enums and dispatch decorator#248
add topology enums and dispatch decorator#248boothby wants to merge 8 commits intodwavesystems:mainfrom
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 |
arcondello
left a comment
There was a problem hiding this comment.
Did a pass for code. Needs to ruminate on the design a bit. Will try to do another pass later today or tomorrow.
| # 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.
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.
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.
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.
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.
| 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.
Missing Parameters and Returns.
This is a preliminary patch to address #210 -- we add a
topologyenum 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_dispatchdecorator 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_freegeneric function indnx.generators.commonand 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).