Skip to content
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

fix: Return in_port/out_port for order edges #84

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions guppy/hugr/hugr.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ def in_port(self, offset: PortOffset | None) -> InPortV:
"""Returns the input port at the given offset."""
assert offset is not None
assert offset < self.num_in_ports
assert offset != -1, "Cannot get the port of an order edge"
return InPortV(self, offset, self.in_port_types[offset])

def out_port(self, offset: PortOffset | None) -> OutPortV:
"""Returns the output port at the given offset."""
assert offset is not None
assert offset < self.num_out_ports
assert offset != -1, "Cannot get the port of an order edge"
return OutPortV(self, offset, self.out_port_types[offset])

@property
Expand Down Expand Up @@ -613,13 +615,17 @@ def order_edges(self) -> Iterator[OrderEdge]:
def in_edges(self, port: InPort) -> Iterator[Edge]:
"""Returns an iterator over all edges connected to a given in-port."""
for e in self._graph.in_edges(port.node.idx, keys=True):
if e[2] == ORDER_EDGE_KEY:
continue
src, tgt = self._to_edge(*e)
if tgt.offset == port.offset:
yield src, tgt

def out_edges(self, port: OutPort) -> Iterator[Edge]:
"""Returns an iterator over all edges originating from a given out-port."""
for e in self._graph.out_edges(port.node.idx, keys=True):
if e[2] == ORDER_EDGE_KEY:
continue
src, tgt = self._to_edge(*e)
if src.offset == port.offset:
yield src, tgt
Expand Down