From eb06dc2e5180456e5445cf18c86edfea45e0aeed Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Thu, 21 Oct 2021 17:21:33 +0100 Subject: [PATCH] Fix two minor issues in dynesty printed output 1. Flush the output: neccersery when writing to file 2. Write the total ellapsed time of the run rather than the time since the last checkpoint --- bilby/core/sampler/dynesty.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bilby/core/sampler/dynesty.py b/bilby/core/sampler/dynesty.py index f2d9051d5..cd5811c85 100644 --- a/bilby/core/sampler/dynesty.py +++ b/bilby/core/sampler/dynesty.py @@ -246,6 +246,12 @@ class Dynesty(NestedSampler): else: self._last_print_time = _time + # Add time in current run to overall sampling time + total_time = self.sampling_time + _time - self.start_time + + # Remove fractional seconds + total_time_str = str(total_time).split('.')[0] + # Extract results at the current iteration. (worst, ustar, vstar, loglstar, logvol, logwt, logz, logzvar, h, nc, worst_it, boundidx, bounditer, @@ -281,12 +287,11 @@ class Dynesty(NestedSampler): self.pbar.set_postfix_str(" ".join(string), refresh=False) self.pbar.update(niter - self.pbar.n) elif "interval" in self.kwargs["print_method"]: - formatted = " ".join([str(_time - self.start_time)] + string) - print("{}it [{}]".format(niter, formatted), file=sys.stdout) + formatted = " ".join([total_time_str] + string) + print("{}it [{}]".format(niter, formatted), file=sys.stdout, flush=True) else: - _time = datetime.datetime.now() - formatted = " ".join([str(_time - self.start_time)] + string) - print("{}it [{}]".format(niter, formatted), file=sys.stdout) + formatted = " ".join([total_time_str] + string) + print("{}it [{}]".format(niter, formatted), file=sys.stdout, flush=True) def _apply_dynesty_boundaries(self): self._periodic = list() -- GitLab