aegis_sim.recording.simpleprogressrecorder
1import time 2import pathlib 3 4from .recorder import Recorder 5from aegis_sim import variables 6 7from aegis_sim.parameterization import parametermanager 8 9class SimpleProgressRecorder(Recorder): 10 def __init__(self, odir: pathlib.Path): 11 self.odir = odir 12 self.init_odir() 13 self.time_start = time.time() 14 15 self.progress_path = self.odir / "simpleprogress.log" 16 self.write_one(0) 17 # self.init_headers() 18 19 # def init_headers(self): 20 # content = ("step", "ETA", "t1M", "runtime", "steps/min", "popsize") 21 # with open(self.odir / "progress.log", "ab") as f: 22 # np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 23 24 def write(self): 25 """Record some information about the time and speed of simulation.""" 26 27 last_updated = self.check_when_last_updated(file_path=self.progress_path) 28 if last_updated > 1: 29 step = variables.steps 30 self.write_one(step) 31 32 def write_one(self, step): 33 message = f"{step}/{parametermanager.parameters.STEPS_PER_SIMULATION}" 34 with open(self.progress_path, "w") as file_: 35 file_.write(message) 36 37 @staticmethod 38 def check_when_last_updated(file_path: pathlib.Path): 39 last_modified_time = file_path.stat().st_mtime 40 time_since_modification = time.time() - last_modified_time 41 seconds = time_since_modification 42 return seconds 43 44 45 # # Get time estimations 46 # time_diff = time.time() - self.time_start 47 48 # seconds_per_100 = time_diff / step * 100 49 # eta = (parametermanager.parameters.STEPS_PER_SIMULATION - step) / 100 * seconds_per_100 50 51 # steps_per_min = int(step / (time_diff / 60)) 52 53 # runtime = self.get_dhm(time_diff) 54 # time_per_1M = self.get_dhm(time_diff / step * 1000000) 55 # eta = self.get_dhm(eta) 56 57 # # Save time estimations 58 # content = (step, eta, time_per_1M, runtime, steps_per_min, popsize) 59 # self.write_to_progress_log(content) 60 61 # def write_to_progress_log(self, content): 62 # """ 63 64 # # OUTPUT SPECIFICATION 65 # path: /progress.log 66 # filetype: txt 67 # category: log 68 # description: A table documenting the estimated time of simulation completion (ETA), time to run one million steps (t1M), time since simulation start (runtime), number of simulated steps per minute (stg/min) and population size (popsize). 69 # trait granularity: 70 # time granularity: 71 # frequency parameter: A str table with custom separator (` | `). 72 # """ 73 # with open(self.odir / "progress.log", "ab") as f: 74 # np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 75 76 # @staticmethod 77 # def get_dhm(timediff): 78 # """Format time in a human-readable format.""" 79 # d = int(timediff / 86400) 80 # timediff %= 86400 81 # h = int(timediff / 3600) 82 # timediff %= 3600 83 # m = int(timediff / 60) 84 # return f"{d}`{h:02}:{m:02}"
10class SimpleProgressRecorder(Recorder): 11 def __init__(self, odir: pathlib.Path): 12 self.odir = odir 13 self.init_odir() 14 self.time_start = time.time() 15 16 self.progress_path = self.odir / "simpleprogress.log" 17 self.write_one(0) 18 # self.init_headers() 19 20 # def init_headers(self): 21 # content = ("step", "ETA", "t1M", "runtime", "steps/min", "popsize") 22 # with open(self.odir / "progress.log", "ab") as f: 23 # np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 24 25 def write(self): 26 """Record some information about the time and speed of simulation.""" 27 28 last_updated = self.check_when_last_updated(file_path=self.progress_path) 29 if last_updated > 1: 30 step = variables.steps 31 self.write_one(step) 32 33 def write_one(self, step): 34 message = f"{step}/{parametermanager.parameters.STEPS_PER_SIMULATION}" 35 with open(self.progress_path, "w") as file_: 36 file_.write(message) 37 38 @staticmethod 39 def check_when_last_updated(file_path: pathlib.Path): 40 last_modified_time = file_path.stat().st_mtime 41 time_since_modification = time.time() - last_modified_time 42 seconds = time_since_modification 43 return seconds 44 45 46 # # Get time estimations 47 # time_diff = time.time() - self.time_start 48 49 # seconds_per_100 = time_diff / step * 100 50 # eta = (parametermanager.parameters.STEPS_PER_SIMULATION - step) / 100 * seconds_per_100 51 52 # steps_per_min = int(step / (time_diff / 60)) 53 54 # runtime = self.get_dhm(time_diff) 55 # time_per_1M = self.get_dhm(time_diff / step * 1000000) 56 # eta = self.get_dhm(eta) 57 58 # # Save time estimations 59 # content = (step, eta, time_per_1M, runtime, steps_per_min, popsize) 60 # self.write_to_progress_log(content) 61 62 # def write_to_progress_log(self, content): 63 # """ 64 65 # # OUTPUT SPECIFICATION 66 # path: /progress.log 67 # filetype: txt 68 # category: log 69 # description: A table documenting the estimated time of simulation completion (ETA), time to run one million steps (t1M), time since simulation start (runtime), number of simulated steps per minute (stg/min) and population size (popsize). 70 # trait granularity: 71 # time granularity: 72 # frequency parameter: A str table with custom separator (` | `). 73 # """ 74 # with open(self.odir / "progress.log", "ab") as f: 75 # np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 76 77 # @staticmethod 78 # def get_dhm(timediff): 79 # """Format time in a human-readable format.""" 80 # d = int(timediff / 86400) 81 # timediff %= 86400 82 # h = int(timediff / 3600) 83 # timediff %= 3600 84 # m = int(timediff / 60) 85 # return f"{d}`{h:02}:{m:02}"
def
write(self):
25 def write(self): 26 """Record some information about the time and speed of simulation.""" 27 28 last_updated = self.check_when_last_updated(file_path=self.progress_path) 29 if last_updated > 1: 30 step = variables.steps 31 self.write_one(step)
Record some information about the time and speed of simulation.
@staticmethod
def
check_when_last_updated(file_path: pathlib.Path):
38 @staticmethod 39 def check_when_last_updated(file_path: pathlib.Path): 40 last_modified_time = file_path.stat().st_mtime 41 time_since_modification = time.time() - last_modified_time 42 seconds = time_since_modification 43 return seconds 44 45 46 # # Get time estimations 47 # time_diff = time.time() - self.time_start 48 49 # seconds_per_100 = time_diff / step * 100 50 # eta = (parametermanager.parameters.STEPS_PER_SIMULATION - step) / 100 * seconds_per_100 51 52 # steps_per_min = int(step / (time_diff / 60)) 53 54 # runtime = self.get_dhm(time_diff) 55 # time_per_1M = self.get_dhm(time_diff / step * 1000000) 56 # eta = self.get_dhm(eta) 57 58 # # Save time estimations 59 # content = (step, eta, time_per_1M, runtime, steps_per_min, popsize) 60 # self.write_to_progress_log(content)