graphix icon indicating copy to clipboard operation
graphix copied to clipboard

[Bug]: `remove_edge` ignores edge symmetry with `rustworkx`

Open thierry-martinez opened this issue 1 year ago • 0 comments

The following test succeeds with networkx back-end but fails with rustworkx back-end. Edge keys in the table num_to_data are directed.

@pytest.mark.parametrize("use_rustworkx", [False, True])
def test_remove_edge(use_rustworkx: bool) -> None:
    g = GraphState(nodes=(0, 1), edges=[(0, 1)], use_rustworkx=use_rustworkx)
    g.remove_edge(1, 0)

The following trivial fix circumvents this bug, but there must be cleaner way to fix it (why all the graph is duplicated as views in Python data structures when rustworkx is used?).

@@ -145,7 +145,14 @@ class EdgeList:
                 continue
             self.add_edge(enum, edata, eidx)
 
-    def remove_edge(self, enum: tuple[int, int]):
+    def remove_edge(self, enum):
+        (u, v) = enum
+        try:
+            self.remove_edge_((u, v))
+        except ValueError:
+            self.remove_edge_((v, u))
+
+    def remove_edge_(self, enum: tuple[int, int]):
         if enum not in self.num_to_data:
             raise ValueError(f"Edge {enum} does not exist")
         self.edges.remove(enum)

thierry-martinez avatar Aug 29 '24 13:08 thierry-martinez