Added duration and end_time to metadata

This commit is contained in:
Andreas Tsouchlos 2022-11-23 15:42:10 +01:00
parent 2885ab76c6
commit 203da09dc7
9 changed files with 56 additions and 17 deletions

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name": "204.3.486", "name": "204.3.486",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name": "204.55.187", "name": "204.55.187",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name": "408.33.844", "name": "408.33.844",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name": "816.1A4.845", "name": "816.1A4.845",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name":"96.3965", "name":"96.3965",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name": "999.111.3.5543", "name": "999.111.3.5543",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name": "999.111.3.5565", "name": "999.111.3.5565",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -1,8 +1,11 @@
{ {
"duration": 0,
"name": "PEGReg252x504", "name": "PEGReg252x504",
"labels": [ "labels": [
"proximal $\\gamma = 0.01$", "proximal $\\gamma = 0.01$",
"proximal $\\gamma = 0.05$", "proximal $\\gamma = 0.05$",
"proximal $\\gamma = 0.15$" "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"
} }

View File

@ -9,6 +9,9 @@ import signal
import pickle import pickle
import os import os
from pathlib import Path from pathlib import Path
import platform
from datetime import datetime
import timeit
from utility import noise, misc from utility import noise, misc
@ -285,8 +288,6 @@ class SimulationDeSerializer:
# TODO: Make the directories configurable in the init function # TODO: Make the directories configurable in the init function
def get_unfinished_sims(self) -> typing.List[str]: def get_unfinished_sims(self) -> typing.List[str]:
"""Get a list unfinished simulations.""" """Get a list unfinished simulations."""
result = []
save_files = [f for f in os.listdir(self._saves_dir) if save_files = [f for f in os.listdir(self._saves_dir) if
os.path.isfile(os.path.join(self._saves_dir, f))] os.path.isfile(os.path.join(self._saves_dir, f))]
@ -327,13 +328,11 @@ class SimulationDeSerializer:
:param sim_name: Name of the simulation :param sim_name: Name of the simulation
:return: Tuple of the form (simulator, metadata) :return: Tuple of the form (simulator, metadata)
""" """
metadata = None
simulator = None
# Read metadata # Read metadata
metadata = self._read_metadata(sim_name) metadata = self._read_metadata(sim_name)
# Read simulation state # Read simulation state
simulator = None
with open(self._get_savefile_path(sim_name), "rb") as file: with open(self._get_savefile_path(sim_name), "rb") as file:
simulator = pickle.load(file) simulator = pickle.load(file)
@ -395,7 +394,8 @@ class SimulationManager:
self._simulator = None self._simulator = None
self._sim_name = 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.SIGINT, self._exit_gracefully)
signal.signal(signal.SIGTERM, self._exit_gracefully) signal.signal(signal.SIGTERM, self._exit_gracefully)
@ -403,9 +403,9 @@ class SimulationManager:
def _sim_configured(self) -> bool: def _sim_configured(self) -> bool:
"""Check whether 'configure_simulation()' has been called.""" """Check whether 'configure_simulation()' has been called."""
return (self._simulator is not None) \ return (self._simulator is not None) and (
and (self._sim_name is not None) \ self._sim_name is not None) and (
and (self._metadata is not None) self._metadata is not None)
def configure_simulation(self, simulator: typing.Any, name: str, def configure_simulation(self, simulator: typing.Any, name: str,
column_labels: typing.Sequence[str]) -> None: column_labels: typing.Sequence[str]) -> None:
@ -414,6 +414,7 @@ class SimulationManager:
self._sim_name = name self._sim_name = name
self._metadata["name"] = name self._metadata["name"] = name
self._metadata["labels"] = column_labels self._metadata["labels"] = column_labels
self._metadata["platform"] = platform.platform()
def get_unfinished(self) -> typing.List[str]: def get_unfinished(self) -> typing.List[str]:
"""Get a list of names of all present unfinished simulations.""" """Get a list of names of all present unfinished simulations."""
@ -432,11 +433,18 @@ class SimulationManager:
self._de_serializer.remove_unfinished_sim(sim_name) 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: def _exit_gracefully(self, *args) -> None:
"""Handler called when the program is interrupted. Pauses and saves """Handler called when the program is interrupted. Pauses and saves
the currently running simulation.""" the currently running simulation."""
if self._sim_configured(): if self._sim_configured():
self._simulator.stop() 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._de_serializer.save_state(self._simulator, self._sim_name,
self._metadata) self._metadata)
self._de_serializer.save_results(self._simulator, self._sim_name, self._de_serializer.save_results(self._simulator, self._sim_name,
@ -448,6 +456,13 @@ class SimulationManager:
"""Start the simulation. This is a blocking call.""" """Start the simulation. This is a blocking call."""
assert self._sim_configured() assert self._sim_configured()
self._sim_start_time = timeit.default_timer()
self._simulator.start() 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._de_serializer.save_results(self._simulator, self._sim_name,
self._metadata) self._metadata)