Skip to content

Commit

Permalink
add Executor attribute for controlling prints
Browse files Browse the repository at this point in the history
  • Loading branch information
danlessa committed Apr 18, 2024
1 parent e2f47a2 commit 9dc7097
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 11 additions & 6 deletions cadCAD/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 0 additions & 2 deletions cadCAD/engine/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 9dc7097

Please sign in to comment.