Skip to content

Topology utils#275

Open
mahdiehmalekian wants to merge 1 commit into
dwavesystems:mainfrom
mahdiehmalekian:topology_utils
Open

Topology utils#275
mahdiehmalekian wants to merge 1 commit 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.

Fix import

Fix syntax
@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.

@@ -0,0 +1,20 @@
# Copyright 2016 D-Wave Systems Inc.

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.

Suggested change
# Copyright 2016 D-Wave Systems Inc.
# Copyright 2026 D-Wave Systems Inc.

# See the License for the specific language governing permissions and
# limitations under the License.
#
# ================================================================================================

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.

Suggested change
# ================================================================================================

# See the License for the specific language governing permissions and
# limitations under the License.
#
# ================================================================================================

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.

Suggested change
# ================================================================================================

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.

Here and elsewhere!

return self._edge[index]

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

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.

Suggested change
if not type(self) is type(other):
if type(self) is not type(other):


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

def neighbors(
self,
nbr_kind: EdgeKind | Iterable[EdgeKind] | None = None,
where: Callable[[Coord], bool] = lambda coord: True,

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.

I believe the mutable default argument value gotcha applies to function objects as well.

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.

Here and elsewhere!

associated_edgekind: EdgeKind


class HasInternalNeighborsMixin(NeighborContributorMixin):

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.

I'd drop the Has prefix.

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.

Here and elsewhere.

Returns:
TopologyShape: The shape converted to its corresponding quotient shape.
"""
@abstractmethod

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.

Suggested change
@abstractmethod
@abstractmethod

Comment on lines +524 to 529
source_to_inner = _chimera_coordinates_cache[m_s,
n_s, t_t].linear_to_chimera
else:
raise ValueError(f"Chimera node labeling {labels_s} not recognized")
raise ValueError(
f"Chimera node labeling {labels_s} not recognized")

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.

Not sure if this was automatically reformatted, or you did it manually, but indentation should be at least locally consistent!

Comment on lines +538 to +539
source_to_inner = _zephyr_coordinates_cache[m_s,
t].linear_to_zephyr

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.

This is arguably less readable to save 4-5 characters in a line.

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.

2 participants