Skip to content

Topology utils#275

Open
mahdiehmalekian wants to merge 13 commits into
dwavesystems:mainfrom
mahdiehmalekian:topology_utils
Open

Topology utils#275
mahdiehmalekian wants to merge 13 commits into
dwavesystems:mainfrom
mahdiehmalekian:topology_utils

Conversation

@mahdiehmalekian

Copy link
Copy Markdown

The added files in dwave/graphs/topologies/common provide blueprint classes for working with different aspects of any D-Wave topology.

  • coord.py: Coordinate systems used for node labels.
  • node_edge.py: Nodes and edges.
  • planeshift.py: Displacement of nodes in the Cartesian plane.
  • shape.py: Shape of a graph.
  • topology.py: Constructing a topology graph whose nodes and edges are equipped with all the specific-topology-relevant functionalities.

The added files in dwave/graphs/topologies/zephyr, i.e. zcoord.py, znode_edge.py, zplaneshift.py and zshape.py, contain the implementation of the corresponding objects for Zephyr topology. In zephyr.py the class Zephyr has been added that is built on Topology blueprint in dwave/graphs/topologies/common/topology.py

The test suite for these modules is added in tests.

Note: This is an evolution of previous zephyr_utils PR to minorminer.

@mahdiehmalekian

mahdiehmalekian commented Jul 17, 2026

Copy link
Copy Markdown
Author

@thisac Is this ready to be merged?

@randomir randomir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick review, it looks good, but I would like to do an in-depth review before me merge this.

The suggestions below are mostly minor, except the use of function objects as default argument values.

Comment thread dwave/graphs/topologies/common/__init__.py Outdated
Comment thread dwave/graphs/topologies/common/coord.py
Comment thread dwave/graphs/topologies/common/node_edge.py
Comment thread dwave/graphs/topologies/common/node_edge.py Outdated

def __eq__(self, other: object) -> bool:
if not type(self) is type(other):
return NotImplemented

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not:

Suggested change
return NotImplemented
return False

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rule throughout:
Type mismatch -> NotImplemented (defer to the other operand).
Same-type -> always return a real bool.
Comparing two same-type objects that happen to differ in shape/quotient-ness/etc. isn't "uncomparable," it's just unequal, so that returns False, not a defer. There were a couple of bugs before in this case, are all now fixed in 0717379

Comment thread dwave/graphs/topologies/common/node_edge.py Outdated
Comment thread dwave/graphs/topologies/common/node_edge.py Outdated
Comment thread dwave/graphs/topologies/common/shape.py
Comment thread dwave/graphs/topologies/zephyr/graphs.py Outdated
Comment thread dwave/graphs/topologies/zephyr/graphs.py Outdated
Comment thread dwave/graphs/topologies/common/__init__.py Outdated
Comment thread dwave/graphs/topologies/common/common.py Outdated
Comment thread dwave/graphs/topologies/common/coord.py
Comment thread dwave/graphs/topologies/common/coord.py Outdated

def __eq__(self, other: object) -> bool:
if (type(self) is not type(other)) or (self.is_quotient() != other.is_quotient()):
return NotImplemented

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like returning False might make more sense, no?

Suggested change
return NotImplemented
return False

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather leave this as NotImplemented and not lock in False. For now, I'm not ready to commit to that yet; might want different coordinates of the same node to be declared as equal, or perhaps a subclass to define their own equality down the line. No cost to keeping it open. Happy to change it once we've actually decided what equality means for these.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rule throughout:
Type mismatch -> NotImplemented (defer to the other operand).
Same-type -> always return a real bool.
Comparing two same-type objects that happen to differ in shape/quotient-ness/etc. isn't "uncomparable," it's just unequal, so that returns False, not a defer. There were a couple of bugs before in this case, are all now fixed in 0717379


def __eq__(self, other: object) -> bool:
if not (type(self) is type(other) and self._shape == other._shape):
return NotImplemented

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to in other places, why not return False?

@mahdiehmalekian mahdiehmalekian Jul 24, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rule throughout:
Type mismatch -> NotImplemented (defer to the other operand).
Same-type -> always return a real bool.
Comparing two same-type objects that happen to differ in shape/quotient-ness/etc. isn't "uncomparable," it's just unequal, so that returns False, not a defer. There were a couple of bugs before in this case (including in this method), are all now fixed in 0717379

Comment thread dwave/graphs/topologies/common/node_edge.py Outdated
Comment thread dwave/graphs/topologies/zephyr/node_edge.py Outdated
Comment thread dwave/graphs/topologies/zephyr/zephyr.py
Comment thread dwave/graphs/topologies/zephyr/graphs.py
…ClassVar attributes

Implement _set_edge for Edge, fix typing hints for args

add document

Make TopologyNode a properly-enforced ABC

Fix indentation

Fix comparison operands

Make NeighborContributorMixin an abstractclass and change some subclasses' methods into abstractmethods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants