From fe67fae0db22b753447326b9c1cca4dd66cde6d8 Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Sat, 16 Jan 2021 14:56:40 +0000 Subject: [PATCH] added option to log runtime of systems --- binarycpython/utils/grid.py | 7 ++++--- binarycpython/utils/grid_options_defaults.py | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 2a71994db..483dc15fd 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -956,9 +956,10 @@ class Population: end_runtime_binary_c = time.time() # Debug line: logging all the lines - with open(os.path.join(self.grid_options["tmp_dir"], "thread_{}_runtime_systems.txt".format(self.process_ID)), 'a+') as f: - binary_cmdline_string = self._return_argline(full_system_dict) - f.write("{} {}\n".format(end_runtime_binary_c-start_runtime_binary_c, binary_cmdline_string)) + if self.grid_options['log_runtime_systems']==1: + with open(os.path.join(self.grid_options["tmp_dir"], "thread_{}_runtime_systems.txt".format(self.process_ID)), 'a+') as f: + binary_cmdline_string = self._return_argline(full_system_dict) + f.write("{} {}\n".format(end_runtime_binary_c-start_runtime_binary_c, binary_cmdline_string)) # Keep track of systems: probability_of_systems_run += full_system_dict["probability"] diff --git a/binarycpython/utils/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py index e6c20526f..059977117 100644 --- a/binarycpython/utils/grid_options_defaults.py +++ b/binarycpython/utils/grid_options_defaults.py @@ -30,6 +30,7 @@ grid_options_defaults_dict = { "combine_ensemble_with_thread_joining": True, # Flag on whether to combine everything and return it to the user or if false: write it to data_dir/ensemble_output_{popuation_id}_{thread_id}.json # "output_dir": "_commandline_input": "", + "log_runtime_systems": 0, # whether to log the runtime of the systems (1 file per thread. stored in the tmp_dir) ########################## # Execution log: ########################## @@ -465,6 +466,7 @@ grid_options_descriptions = { "evolution_type": "Variable containing the type of evolution used of the grid. Multiprocessing or linear processing", "combine_ensemble_with_thread_joining": "BOolean flag on whether to combine everything and return it to the user or if false: write it to data_dir/ensemble_output_{popuation_id}_{thread_id}.json", "ensemble_results": "Dictinary that stores the ensemble results if combine_ensemble_with_thread_joining==True", + "log_runtime_systems": "Whether to log the runtime of the systems . Each systems run by the thread is logged to a file and is stored in the tmp_dir. (1 file per thread). Don't use this if you are planning to run alot of systems. This is mostly for debugging and finding systems that take long to run. Integer, default = 0. if value is 1 then the systems are logged", } ################################# -- GitLab