Skip to content

Commit

Permalink
metrics: add relative timing calculation helper
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Oct 1, 2024
1 parent d206fe8 commit 466e96b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion petric.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ def __init__(self, seconds=3600, outdir=OUTDIR, transverse_slice=None, coronal_s
self.reset()

def reset(self):
self.limit = time() + self._seconds
self.offset = 0
self.limit = (now := time()) + self._seconds
self.tb.add_scalar("reset", 0, -1, now) # for relative timing calculation

def __call__(self, algo: Algorithm):
if (time_excluding_metrics := (now := time()) - self.offset) > self.limit:
log.warning("Timeout reached. Stopping algorithm.")
self.tb.add_scalar("reset", 0, algo.iteration, time_excluding_metrics)
raise StopIteration
for c in self.callbacks:
c._time_ = time_excluding_metrics
Expand Down

0 comments on commit 466e96b

Please sign in to comment.