diff --git a/main_package/classes/estimators/structure_score_based_estimator.py b/main_package/classes/estimators/structure_score_based_estimator.py index d918235..df42668 100644 --- a/main_package/classes/estimators/structure_score_based_estimator.py +++ b/main_package/classes/estimators/structure_score_based_estimator.py @@ -10,6 +10,8 @@ from networkx.readwrite import json_graph from random import choice +import concurrent.futures + import copy import utility.cache as ch import structure_graph.conditional_intensity_matrix as condim @@ -92,17 +94,27 @@ class StructureScoreBasedEstimator(se.StructureEstimator): if disable_multiprocessing: cpu_count = 1 - 'Estimate the best parents for each node' - with get_context("spawn").Pool(processes=cpu_count) as pool: + + + + + #with get_context("spawn").Pool(processes=cpu_count) as pool: #with multiprocessing.Pool(processes=cpu_count) as pool: - list_edges_partial = pool.starmap(estimate_parents, zip( - self.nodes, - l_max_parents, - l_iterations_number, - l_patience, - l_tabu_length, - l_tabu_rules_duration, - l_optimizer)) + + 'Estimate the best parents for each node' + with concurrent.futures.ProcessPoolExecutor(max_workers=cpu_count) as executor: + list_edges_partial = executor.map(estimate_parents, + self.nodes, + l_max_parents, + l_iterations_number, + l_patience, + l_tabu_length, + l_tabu_rules_duration, + l_optimizer) + + + + # list_edges_partial = [estimate_parents(n,max_parents,iterations_number,patience,tabu_length,tabu_rules_duration,optimizer) for n in self.nodes] #list_edges_partial = p.map(estimate_parents, self.nodes) #list_edges_partial= estimate_parents('Q',max_parents,iterations_number,patience,tabu_length,tabu_rules_duration,optimizer) diff --git a/main_package/tests/estimators/test_structure_score_based_estimator.py b/main_package/tests/estimators/test_structure_score_based_estimator.py index 877bbae..7fbf623 100644 --- a/main_package/tests/estimators/test_structure_score_based_estimator.py +++ b/main_package/tests/estimators/test_structure_score_based_estimator.py @@ -16,9 +16,6 @@ import structure_graph.sample_path as sp import estimators.structure_score_based_estimator as se import utility.json_importer as ji -from multiprocessing import set_start_method - - class TestStructureScoreBasedEstimator(unittest.TestCase): @@ -26,7 +23,7 @@ class TestStructureScoreBasedEstimator(unittest.TestCase): @classmethod def setUpClass(cls): #cls.read_files = glob.glob(os.path.join('../../data', "*.json")) - cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_ternary_data_15.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name') + cls.importer = ji.JsonImporter("../../data/networks_and_trajectories_binary_data_10.json", 'samples', 'dyn.str', 'variables', 'Time', 'Name') cls.s1 = sp.SamplePath(cls.importer) cls.s1.build_trajectories() cls.s1.build_structure() @@ -37,7 +34,7 @@ class TestStructureScoreBasedEstimator(unittest.TestCase): true_edges = copy.deepcopy(self.s1.structure.edges) true_edges = set(map(tuple, true_edges)) - set_start_method("spawn") + se1 = se.StructureScoreBasedEstimator(self.s1) edges = se1.estimate_structure( max_parents = None, @@ -46,7 +43,7 @@ class TestStructureScoreBasedEstimator(unittest.TestCase): tabu_length = 15, tabu_rules_duration = 15, optimizer = 'tabu', - disable_multiprocessing=False + disable_multiprocessing=True )