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

Record some information about the time and speed of simulation.

def write_to_progress_log(self, content):
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="| ")

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):
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}"

Format time in a human-readable format.