From 9dc7097713c950bba85f41d31cb640510692c7b4 Mon Sep 17 00:00:00 2001 From: Danilo Lessa Bernardineli Date: Thu, 18 Apr 2024 15:56:06 -0300 Subject: [PATCH] add Executor attribute for controlling prints --- cadCAD/engine/__init__.py | 17 +++++++++++------ cadCAD/engine/execution.py | 2 -- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cadCAD/engine/__init__.py b/cadCAD/engine/__init__.py index 4dc33409..5e08856b 100644 --- a/cadCAD/engine/__init__.py +++ b/cadCAD/engine/__init__.py @@ -70,7 +70,7 @@ def distroduce_proc( class Executor: def __init__(self, - exec_context: ExecutionContext, configs: List[Configuration], sc=None, empty_return=False + exec_context: ExecutionContext, configs: List[Configuration], sc=None, empty_return=False, supress_print=False ) -> None: self.sc = sc self.SimExecutor = SimExecutor @@ -79,6 +79,7 @@ def __init__(self, self.additional_objs = exec_context.additional_objs self.configs = configs self.empty_return = empty_return + self.supress_print = supress_print def execute(self) -> Tuple[object, object, Dict[str, object]]: if self.empty_return is True: @@ -97,7 +98,8 @@ def execute(self) -> Tuple[object, object, Dict[str, object]]: config_idx = 0 # Execution Info - print_exec_info(self.exec_context, configs_as_objs(self.configs)) + if self.supress_print is False: + print_exec_info(self.exec_context, configs_as_objs(self.configs)) t1 = time() for x in tqdm(self.configs, @@ -209,8 +211,9 @@ def get_final_results(simulations: List[StateHistory], else: raise ValueError("Invalid execution mode specified") - - print("Execution Method: " + self.exec_method.__name__) + if self.supress_print is False: + print("Execution Method: " + self.exec_method.__name__) + simulations_results = self.exec_method( sim_executors, var_dict_list, states_lists, configs_structs, env_processes_list, Ts, SimIDs, RunIDs, ExpIDs, SubsetIDs, SubsetWindows, original_N, self.additional_objs @@ -219,7 +222,8 @@ def get_final_results(simulations: List[StateHistory], final_result = get_final_results( simulations_results, partial_state_updates, eps, sessions, remote_threshold) elif self.exec_context == ExecutionMode.distributed: - print("Execution Method: " + self.exec_method.__name__) + if self.supress_print is False: + print("Execution Method: " + self.exec_method.__name__) simulations_results = self.exec_method( sim_executors, var_dict_list, states_lists, configs_structs, env_processes_list, Ts, SimIDs, RunIDs, ExpIDs, SubsetIDs, SubsetWindows, original_N, self.sc @@ -228,6 +232,7 @@ def get_final_results(simulations: List[StateHistory], simulations_results, partial_state_updates, eps, sessions) t2 = time() - print(f"Total execution time: {t2 - t1 :.2f}s") + if self.supress_print is False: + print(f"Total execution time: {t2 - t1 :.2f}s") return final_result diff --git a/cadCAD/engine/execution.py b/cadCAD/engine/execution.py index 97a5fa87..cd1319ac 100644 --- a/cadCAD/engine/execution.py +++ b/cadCAD/engine/execution.py @@ -35,7 +35,6 @@ def single_proc_exec( Ts, SimIDs, Ns, SubsetIDs, SubsetWindows, var_dict_list) results: List = [] - print(f'Execution Mode: single_threaded') for raw_param in zip(*raw_params): simulation_exec, states_list, config, env_processes, T, sim_id, N, subset_id, subset_window, var_dict = raw_param result = simulation_exec( @@ -60,7 +59,6 @@ def parallelize_simulations( additional_objs=None ): - print(f'Execution Mode: parallelized') params = list( zip( simulation_execs, var_dict_list, states_lists, configs_structs, env_processes_list,