aegis_sim.recording.progressrecorder
1import logging 2import time 3import numpy as np 4import pathlib 5 6from .recorder import Recorder 7from aegis_sim import variables 8from aegis_sim.utilities.funcs import skip 9 10from aegis_sim.parameterization import parametermanager 11 12 13class ProgressRecorder(Recorder): 14 def __init__(self, odir: pathlib.Path, resuming=False): 15 self.odir = odir 16 self.init_odir() 17 self.time_start = time.time() 18 if not resuming: 19 self.init_headers() 20 21 def init_headers(self): 22 content = ("step", "ETA", "t1M", "runtime", "steps/min", "popsize") 23 with open(self.odir / "progress.log", "ab") as f: 24 np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 25 26 def write(self, popsize="?"): 27 """Record some information about the time and speed of simulation.""" 28 29 if skip("LOGGING_RATE"): 30 return 31 32 step = variables.steps 33 34 logging.info( 35 "%s / %s / N=%s / simname=%s", 36 step, 37 parametermanager.parameters.STEPS_PER_SIMULATION, 38 popsize, 39 variables.custom_config_path.stem, 40 ) 41 42 # Get time estimations 43 time_diff = time.time() - self.time_start 44 45 seconds_per_100 = time_diff / step * 100 46 eta = (parametermanager.parameters.STEPS_PER_SIMULATION - step) / 100 * seconds_per_100 47 48 steps_per_min = int(step / (time_diff / 60)) 49 50 runtime = self.get_dhm(time_diff) 51 time_per_1M = self.get_dhm(time_diff / step * 1000000) 52 eta = self.get_dhm(eta) 53 54 # Save time estimations 55 content = (step, eta, time_per_1M, runtime, steps_per_min, popsize) 56 self.write_to_progress_log(content) 57 58 def write_to_progress_log(self, content): 59 """ 60 61 # OUTPUT SPECIFICATION 62 path: /progress.log 63 filetype: txt 64 category: log 65 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). 66 trait granularity: N/A 67 time granularity: N/A 68 frequency parameter: LOGGING_RATE 69 structure: A str table with custom separator (` | `). 70 """ 71 with open(self.odir / "progress.log", "ab") as f: 72 np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 73 74 @staticmethod 75 def get_dhm(timediff): 76 """Format time in a human-readable format.""" 77 d = int(timediff / 86400) 78 timediff %= 86400 79 h = int(timediff / 3600) 80 timediff %= 3600 81 m = int(timediff / 60) 82 return f"{d}`{h:02}:{m:02}"
14class ProgressRecorder(Recorder): 15 def __init__(self, odir: pathlib.Path, resuming=False): 16 self.odir = odir 17 self.init_odir() 18 self.time_start = time.time() 19 if not resuming: 20 self.init_headers() 21 22 def init_headers(self): 23 content = ("step", "ETA", "t1M", "runtime", "steps/min", "popsize") 24 with open(self.odir / "progress.log", "ab") as f: 25 np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 26 27 def write(self, popsize="?"): 28 """Record some information about the time and speed of simulation.""" 29 30 if skip("LOGGING_RATE"): 31 return 32 33 step = variables.steps 34 35 logging.info( 36 "%s / %s / N=%s / simname=%s", 37 step, 38 parametermanager.parameters.STEPS_PER_SIMULATION, 39 popsize, 40 variables.custom_config_path.stem, 41 ) 42 43 # Get time estimations 44 time_diff = time.time() - self.time_start 45 46 seconds_per_100 = time_diff / step * 100 47 eta = (parametermanager.parameters.STEPS_PER_SIMULATION - step) / 100 * seconds_per_100 48 49 steps_per_min = int(step / (time_diff / 60)) 50 51 runtime = self.get_dhm(time_diff) 52 time_per_1M = self.get_dhm(time_diff / step * 1000000) 53 eta = self.get_dhm(eta) 54 55 # Save time estimations 56 content = (step, eta, time_per_1M, runtime, steps_per_min, popsize) 57 self.write_to_progress_log(content) 58 59 def write_to_progress_log(self, content): 60 """ 61 62 # OUTPUT SPECIFICATION 63 path: /progress.log 64 filetype: txt 65 category: log 66 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). 67 trait granularity: N/A 68 time granularity: N/A 69 frequency parameter: LOGGING_RATE 70 structure: A str table with custom separator (` | `). 71 """ 72 with open(self.odir / "progress.log", "ab") as f: 73 np.savetxt(f, [content], fmt="%-10s", delimiter="| ") 74 75 @staticmethod 76 def get_dhm(timediff): 77 """Format time in a human-readable format.""" 78 d = int(timediff / 86400) 79 timediff %= 86400 80 h = int(timediff / 3600) 81 timediff %= 3600 82 m = int(timediff / 60) 83 return f"{d}`{h:02}:{m:02}"
def
write(self, popsize='?'):
27 def write(self, popsize="?"): 28 """Record some information about the time and speed of simulation.""" 29 30 if skip("LOGGING_RATE"): 31 return 32 33 step = variables.steps 34 35 logging.info( 36 "%s / %s / N=%s / simname=%s", 37 step, 38 parametermanager.parameters.STEPS_PER_SIMULATION, 39 popsize, 40 variables.custom_config_path.stem, 41 ) 42 43 # Get time estimations 44 time_diff = time.time() - self.time_start 45 46 seconds_per_100 = time_diff / step * 100 47 eta = (parametermanager.parameters.STEPS_PER_SIMULATION - step) / 100 * seconds_per_100 48 49 steps_per_min = int(step / (time_diff / 60)) 50 51 runtime = self.get_dhm(time_diff) 52 time_per_1M = self.get_dhm(time_diff / step * 1000000) 53 eta = self.get_dhm(eta) 54 55 # Save time estimations 56 content = (step, eta, time_per_1M, runtime, steps_per_min, popsize) 57 self.write_to_progress_log(content)
Record some information about the time and speed of simulation.
def
write_to_progress_log(self, content):
59 def write_to_progress_log(self, content): 60 """ 61 62 # OUTPUT SPECIFICATION 63 path: /progress.log 64 filetype: txt 65 category: log 66 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). 67 trait granularity: N/A 68 time granularity: N/A 69 frequency parameter: LOGGING_RATE 70 structure: A str table with custom separator (` | `). 71 """ 72 with open(self.odir / "progress.log", "ab") as f: 73 np.savetxt(f, [content], fmt="%-10s", delimiter="| ")
OUTPUT SPECIFICATION
path: /progress.log
filetype: txt
category: log
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).
trait granularity: N/A
time granularity: N/A
frequency parameter: LOGGING_RATE
structure: A str table with custom separator (|).
@staticmethod
def
get_dhm(timediff):
75 @staticmethod 76 def get_dhm(timediff): 77 """Format time in a human-readable format.""" 78 d = int(timediff / 86400) 79 timediff %= 86400 80 h = int(timediff / 3600) 81 timediff %= 3600 82 m = int(timediff / 60) 83 return f"{d}`{h:02}:{m:02}"
Format time in a human-readable format.