add timestamp to models

This commit is contained in:
Valentin Boettcher 2022-11-28 16:02:15 -05:00
parent 720ce192d8
commit c52deba63f
No known key found for this signature in database
GPG key ID: E034E12B7AF56ACE
3 changed files with 23 additions and 3 deletions

View file

@ -17,6 +17,7 @@ from hopsflow.util import EnsembleValue
import hashlib
import hops.core.hierarchy_parameters as params
from collections.abc import Callable
from datetime import datetime
@dataclass
@ -43,7 +44,14 @@ class Model(ABC):
breaking changes.
"""
_ignored_keys: list[str] = field(default_factory=lambda: ["_sigmas", "description"])
timestamp: datetime = field(default_factory=lambda: datetime.now())
"""
A timestamp that signals when the simulation was run. Is not used to hash or compare objects.
"""
_ignored_keys: list[str] = field(
default_factory=lambda: ["_sigmas", "description", "timestamp"]
)
"""Keys that are ignored when comparing or hashing models."""
###########################################################################

View file

@ -173,7 +173,7 @@ class OttoEngine(QubitModelMutliBath):
"""The smoothness of the modulation of ``H``."""
timings_L: tuple[Timings, Timings] = field(
default_factory=lambda: ((0, 0.05, 0.15, 0.2), (0.5, 0.55, 0.65, 0.7))
default_factory=lambda: ((0.0, 0.05, 0.15, 0.2), (0.5, 0.55, 0.65, 0.7))
)
"""The timings for the ``L`` modulation. See :any:`SmoothlyInterpolatdPeriodicMatrix`."""
@ -215,7 +215,7 @@ class OttoEngine(QubitModelMutliBath):
self.ω_s[i] = res.x
if self.t == "auto":
if isinstance(self.t, str) and self.t == "auto":
t_max = self.num_cycles * self.Θ
# we set this here to avoid different results on different platforms

View file

@ -1,3 +1,5 @@
from datetime import datetime
import dateutil.parser
from functools import singledispatchmethod
import dataclasses
from dataclasses import dataclass
@ -96,6 +98,13 @@ class JSONEncoder(json.JSONEncoder):
"value": obj.__getstate__(),
}
@default.register
def _(self, obj: datetime):
return {
"type": "datetime",
"value": obj.isoformat(),
}
@classmethod
def dumps(cls, data, **kwargs) -> str:
"""Like :any:`json.dumps`, just for this encoder.
@ -164,6 +173,9 @@ def object_hook(dct: dict[str, Any]):
if type == "tuple":
return tuple(dct["value"])
if type == "datetime":
return dateutil.parser.parse(dct["value"])
return dct