def test_save_reload_bnn_graph(self): m1, _ = self.make_model(self.make_net()) m1.save(self.TESTFILE) m1_loaded = Model() m1_loaded.load_graph(self.TESTFILE) m1_loaded_edges = set(m1_loaded.components_graph.edges()) m1_edges = set(m1.components_graph.edges()) self.assertTrue(set(m1.components) == set(m1_loaded.components)) self.assertTrue( set(m1.components_graph.edges()) == set( m1_loaded.components_graph.edges()), m1_edges.symmetric_difference(m1_loaded_edges)) self.assertTrue( len(m1_loaded.components.values()) == len( set(m1_loaded.components.values()))) import os os.remove(self.TESTFILE)
def test_save_reload_then_reconcile_bnn_graph(self): m1, _ = self.make_model(self.make_net()) m1.save(self.TESTFILE) m1_loaded = Model() m1_loaded.load_graph(self.TESTFILE) self.assertTrue(set(m1.components) == set(m1_loaded.components)) m2, _ = self.make_model(self.make_net()) component_map = mf.models.FactorGraph.reconcile_graphs([m2], m1_loaded) self.assertTrue( len(component_map.values()) == len(set(component_map.values())), "Assert there are only 1:1 mappings.") self.assertTrue(len(component_map) == len(m1.components)) sort_m1 = list(set(map(lambda x: x.uuid, m1.components.values()))) sort_m1.sort() sort_m2 = list(set(map(lambda x: x.uuid, m2.components.values()))) sort_m2.sort() sort_component_map_values = list(set(component_map.values())) sort_component_map_values.sort() sort_component_map_keys = list(set(component_map.keys())) sort_component_map_keys.sort() zippy_values = zip(sort_m2, sort_component_map_values) zippy_keys = zip(sort_m1, sort_component_map_keys) self.assertTrue( all([ m1_item == component_map_item for m1_item, component_map_item in zippy_values ])) self.assertTrue( all([ m2_item == component_map_item for m2_item, component_map_item in zippy_keys ])) import os os.remove(self.TESTFILE)