diff --git a/sw/sim_results/2043486_metadata.json b/sw/sim_results/2043486_metadata.json index 551e85a..7f877c2 100644 --- a/sw/sim_results/2043486_metadata.json +++ b/sw/sim_results/2043486_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name": "204.3.486", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/sim_results/20455187_metadata.json b/sw/sim_results/20455187_metadata.json index c715048..bd033bf 100644 --- a/sw/sim_results/20455187_metadata.json +++ b/sw/sim_results/20455187_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name": "204.55.187", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/sim_results/40833844_metadata.json b/sw/sim_results/40833844_metadata.json index ff4c018..641964c 100644 --- a/sw/sim_results/40833844_metadata.json +++ b/sw/sim_results/40833844_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name": "408.33.844", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/sim_results/8161a4845_metadata.json b/sw/sim_results/8161a4845_metadata.json index 7af4536..ac1e4ef 100644 --- a/sw/sim_results/8161a4845_metadata.json +++ b/sw/sim_results/8161a4845_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name": "816.1A4.845", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/sim_results/963965_metadata.json b/sw/sim_results/963965_metadata.json index c3a50ea..f02603d 100644 --- a/sw/sim_results/963965_metadata.json +++ b/sw/sim_results/963965_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name":"96.3965", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/sim_results/99911135543_metadata.json b/sw/sim_results/99911135543_metadata.json index eb6cc77..f910ea0 100644 --- a/sw/sim_results/99911135543_metadata.json +++ b/sw/sim_results/99911135543_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name": "999.111.3.5543", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/sim_results/99911135565_metadata.json b/sw/sim_results/99911135565_metadata.json index 089e6b3..f06c662 100644 --- a/sw/sim_results/99911135565_metadata.json +++ b/sw/sim_results/99911135565_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name": "999.111.3.5565", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/sim_results/pegreg252x504_metadata.json b/sw/sim_results/pegreg252x504_metadata.json index 8f70c7f..c01b1c7 100644 --- a/sw/sim_results/pegreg252x504_metadata.json +++ b/sw/sim_results/pegreg252x504_metadata.json @@ -1,8 +1,11 @@ { + "duration": 0, "name": "PEGReg252x504", "labels": [ "proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.15$" - ] + ], + "platform": "Linux-6.0.9-arch1-1-x86_64-with-glibc2.36", + "end_time": "2022-11-23 15:13:09.470306" } \ No newline at end of file diff --git a/sw/utility/simulation.py b/sw/utility/simulation.py index f716461..ac6b1e2 100644 --- a/sw/utility/simulation.py +++ b/sw/utility/simulation.py @@ -9,6 +9,9 @@ import signal import pickle import os from pathlib import Path +import platform +from datetime import datetime +import timeit from utility import noise, misc @@ -285,8 +288,6 @@ class SimulationDeSerializer: # TODO: Make the directories configurable in the init function def get_unfinished_sims(self) -> typing.List[str]: """Get a list unfinished simulations.""" - result = [] - save_files = [f for f in os.listdir(self._saves_dir) if os.path.isfile(os.path.join(self._saves_dir, f))] @@ -327,13 +328,11 @@ class SimulationDeSerializer: :param sim_name: Name of the simulation :return: Tuple of the form (simulator, metadata) """ - metadata = None - simulator = None - # Read metadata metadata = self._read_metadata(sim_name) # Read simulation state + simulator = None with open(self._get_savefile_path(sim_name), "rb") as file: simulator = pickle.load(file) @@ -395,7 +394,8 @@ class SimulationManager: self._simulator = None self._sim_name = None - self._metadata = {} + self._metadata = {"duration": 0} + self._sim_start_time = None signal.signal(signal.SIGINT, self._exit_gracefully) signal.signal(signal.SIGTERM, self._exit_gracefully) @@ -403,9 +403,9 @@ class SimulationManager: def _sim_configured(self) -> bool: """Check whether 'configure_simulation()' has been called.""" - return (self._simulator is not None) \ - and (self._sim_name is not None) \ - and (self._metadata is not None) + return (self._simulator is not None) and ( + self._sim_name is not None) and ( + self._metadata is not None) def configure_simulation(self, simulator: typing.Any, name: str, column_labels: typing.Sequence[str]) -> None: @@ -414,6 +414,7 @@ class SimulationManager: self._sim_name = name self._metadata["name"] = name self._metadata["labels"] = column_labels + self._metadata["platform"] = platform.platform() def get_unfinished(self) -> typing.List[str]: """Get a list of names of all present unfinished simulations.""" @@ -432,11 +433,18 @@ class SimulationManager: self._de_serializer.remove_unfinished_sim(sim_name) + # TODO: Metadata is being written twice here. Should save_results() also + # save the metadata? def _exit_gracefully(self, *args) -> None: """Handler called when the program is interrupted. Pauses and saves the currently running simulation.""" if self._sim_configured(): self._simulator.stop() + + self._metadata["end_time"] = f"{datetime.now(tz=None)}" + self._metadata["duration"] \ + += timeit.default_timer() - self._sim_start_time + self._de_serializer.save_state(self._simulator, self._sim_name, self._metadata) self._de_serializer.save_results(self._simulator, self._sim_name, @@ -448,6 +456,13 @@ class SimulationManager: """Start the simulation. This is a blocking call.""" assert self._sim_configured() + self._sim_start_time = timeit.default_timer() + self._simulator.start() + + self._metadata["end_time"] = f"{datetime.now(tz=None)}" + self._metadata["duration"] \ + += timeit.default_timer() - self._sim_start_time + self._de_serializer.save_results(self._simulator, self._sim_name, self._metadata)