Added duration and end_time to metadata
This commit is contained in:
parent
2885ab76c6
commit
203da09dc7
@ -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"
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
@ -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"
|
||||
}
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user