1
0
Fork 0

Updated parallel implementation

master
Luca Moretti 4 years ago
parent 28e3000ed1
commit 9e4d6b9fe5
  1. 11
      main_package/classes/estimators/structure_constraint_based_estimator.py
  2. 8
      main_package/classes/optimizers/constraint_based_optimizer.py
  3. 4
      main_package/tests/estimators/test_structure_constraint_based_estimator.py

@ -215,7 +215,7 @@ class StructureConstraintBasedEstimator(se.StructureEstimator):
return optimizer_obj.optimize_structure()
@timing
def ctpc_algorithm(self):
def ctpc_algorithm(self,disable_multiprocessing:bool= False ):
"""
Compute the CTPC algorithm.
Parameters:
@ -233,8 +233,9 @@ class StructureConstraintBasedEstimator(se.StructureEstimator):
'get the number of CPU'
cpu_count = multiprocessing.cpu_count()
#if disable_multiprocessing:
#cpu_count = 1
if disable_multiprocessing:
print("DISABILITATO")
cpu_count = 1
'Remove all the edges from the structure'
self.sample_path.structure.clean_structure_edges()
@ -250,8 +251,8 @@ class StructureConstraintBasedEstimator(se.StructureEstimator):
@timing
def estimate_structure(self):
return self.ctpc_algorithm()
def estimate_structure(self,disable_multiprocessing:bool=False):
return self.ctpc_algorithm(disable_multiprocessing=disable_multiprocessing)

@ -86,8 +86,12 @@ class ConstraintBasedOptimizer(Optimizer):
graph.remove_edges([(test_parent, self.node_id)])
other_nodes.remove(test_parent)
print(f"TEST PARENT: {test_parent}")
if u.__contains__(test_parent):
u.remove(test_parent)
try:
u.remove(test_parent)
except:
print(f"u: {u}")
print(f"utest_parent: {test_parent}")
removed = True
break
#else:

@ -22,7 +22,7 @@ class TestStructureConstraintBasedEstimator(unittest.TestCase):
@classmethod
def setUpClass(cls):
#cls.read_files = glob.glob(os.path.join('../../data', "*.json"))
cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_binary_data_01_15.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name')
cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_ternary_data_01_6.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name')
cls.s1 = sp.SamplePath(cls.importer)
cls.s1.build_trajectories()
cls.s1.build_structure()
@ -32,7 +32,7 @@ class TestStructureConstraintBasedEstimator(unittest.TestCase):
true_edges = set(map(tuple, true_edges))
se1 = se.StructureConstraintBasedEstimator(self.s1,0.1,0.1)
edges = se1.ctpc_algorithm()
edges = se1.estimate_structure(disable_multiprocessing=True)
self.assertEqual(edges, true_edges)