Skip to content

Commit

Permalink
fix walltime override
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Oct 1, 2024
1 parent 7b44d2c commit a70c78d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions petric.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self, transverse_slice=None, coronal_slice=None, sagittal_slice=Non
def __call__(self, algo: Algorithm):
if self.skip_iteration(algo):
return
t = getattr(self, '__time', None) or time()
t = self._time_
log.debug("logging iter %d...", algo.iteration)
# initialise `None` values
self.transverse_slice = algo.x.dimensions()[0] // 2 if self.transverse_slice is None else self.transverse_slice
Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, reference_image, whole_object_mask, background_mask, interval
def __call__(self, algo: Algorithm):
if self.skip_iteration(algo):
return
t = getattr(self, '__time', None) or time()
t = self._time_
for tag, value in self.evaluate(algo.x).items():
self.tb_summary_writer.add_scalar(tag, value, algo.iteration, t)

Expand Down Expand Up @@ -159,16 +159,16 @@ def __init__(self, seconds=600, outdir=OUTDIR, transverse_slice=None, coronal_sl
self.tb = tb_cbk.tb # convenient access to the underlying SummaryWriter
self.reset()

def reset(self, seconds=None):
self.limit = time() + (self._seconds if seconds is None else seconds)
def reset(self):
self.limit = time() + self._seconds
self.offset = 0

def __call__(self, algo: Algorithm):
if (now := time()) > self.limit + self.offset:
if (time_excluding_metrics := (now := time()) - self.offset) > self.limit:
log.warning("Timeout reached. Stopping algorithm.")
raise StopIteration
for c in self.callbacks:
c.__time = now - self.offset # privately inject walltime-excluding-petric-callbacks
c._time_ = time_excluding_metrics
c(algo)
self.offset += time() - now

Expand Down

0 comments on commit a70c78d

Please sign in to comment.