Skip to content

Commit

Permalink
fixed failing tests using old networkx
Browse files Browse the repository at this point in the history
  • Loading branch information
boothby committed Dec 31, 2024
1 parent 5fcbcb5 commit 8f26d6a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def graphs_equal(G, H):
return type(G) == type(H) and {*G} == {*H} and len(G.edges) == len(H.edges) and all(H.has_edge(*e) for e in G.edges)
5 changes: 3 additions & 2 deletions tests/test_generator_chimera.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import networkx as nx
import dwave_networkx as dnx
import numpy as np
from .common import graphs_equal

alpha_map = dict(enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'))

Expand Down Expand Up @@ -376,13 +377,13 @@ def test_defect_free_chimera(self):
H = G.copy()
H.remove_nodes_from([*H][::3])
H.remove_edges_from([*H.edges][::3])
self.assertTrue(nx.utils.graphs_equal(G, dnx.generators.chimera.defect_free_chimera(H)))
self.assertTrue(graphs_equal(G, dnx.generators.chimera.defect_free_chimera(H)))

G = dnx.chimera_graph(2, 4, 2, coordinates=True)
H = G.copy()
H.remove_nodes_from([*H][::3])
H.remove_edges_from([*H.edges][::3])
self.assertTrue(nx.utils.graphs_equal(G, dnx.generators.chimera.defect_free_chimera(H)))
self.assertTrue(graphs_equal(G, dnx.generators.chimera.defect_free_chimera(H)))

class TestChimeraTorus(unittest.TestCase):
def test(self):
Expand Down
8 changes: 5 additions & 3 deletions tests/test_generator_pegasus.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
get_tuple_fragmentation_fn,
)

from .common import graphs_equal

alpha_map = dict(enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'))


Expand Down Expand Up @@ -407,19 +409,19 @@ def test_defect_free_pegasus(self):
H = G.copy()
H.remove_nodes_from([*H][::3])
H.remove_edges_from([*H.edges][::3])
self.assertTrue(nx.utils.graphs_equal(G, dnx.generators.pegasus.defect_free_pegasus(H)))
self.assertTrue(graphs_equal(G, dnx.generators.pegasus.defect_free_pegasus(H)))

G = dnx.pegasus_graph(3, offsets_index=1, coordinates=True)
H = G.copy()
H.remove_nodes_from([*H][::3])
H.remove_edges_from([*H.edges][::3])
self.assertTrue(nx.utils.graphs_equal(G, dnx.generators.pegasus.defect_free_pegasus(H)))
self.assertTrue(graphs_equal(G, dnx.generators.pegasus.defect_free_pegasus(H)))

G = dnx.pegasus_graph(3, nice_coordinates=True)
H = G.copy()
H.remove_nodes_from([*H][::3])
H.remove_edges_from([*H.edges][::3])
self.assertTrue(nx.utils.graphs_equal(G, dnx.generators.pegasus.defect_free_pegasus(H)))
self.assertTrue(graphs_equal(G, dnx.generators.pegasus.defect_free_pegasus(H)))



Expand Down
5 changes: 3 additions & 2 deletions tests/test_generator_zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import networkx as nx
import dwave_networkx as dnx
import numpy as np
from .common import graphs_equal

class TestZephyrGraph(unittest.TestCase):
def test_single_tile(self):
Expand Down Expand Up @@ -279,13 +280,13 @@ def test_defect_free_zephyr(self):
H = G.copy()
H.remove_nodes_from([*H][::3])
H.remove_edges_from([*H.edges][::3])
self.assertTrue(nx.utils.graphs_equal(G, dnx.generators.zephyr.defect_free_zephyr(H)))
self.assertTrue(graphs_equal(G, dnx.generators.zephyr.defect_free_zephyr(H)))

G = dnx.zephyr_graph(2, 2, coordinates=True)
H = G.copy()
H.remove_nodes_from([*H][::3])
H.remove_edges_from([*H.edges][::3])
self.assertTrue(nx.utils.graphs_equal(G, dnx.generators.zephyr.defect_free_zephyr(H)))
self.assertTrue(graphs_equal(G, dnx.generators.zephyr.defect_free_zephyr(H)))

class TestZephyrTorus(unittest.TestCase):
def test(self):
Expand Down

0 comments on commit 8f26d6a

Please sign in to comment.