diff --git a/bilby/core/result.py b/bilby/core/result.py index 414066e6641d88fbd6ccff986cf12162aa03eaa3..dbe7e29ac8920d6423f415eca12ebda6c92c14a0 100644 --- a/bilby/core/result.py +++ b/bilby/core/result.py @@ -1,3 +1,4 @@ +import datetime import inspect import json import os @@ -362,7 +363,7 @@ class Result(object): The number of times the likelihood function is called log_prior_evaluations: array_like The evaluations of the prior for each sample point - sampling_time: float + sampling_time: (datetime.timedelta, float) The time taken to complete the sampling nburn: int The number of burn-in steps discarded for MCMC samplers @@ -412,6 +413,8 @@ class Result(object): self.log_likelihood_evaluations = log_likelihood_evaluations self.log_prior_evaluations = log_prior_evaluations self.num_likelihood_evaluations = num_likelihood_evaluations + if isinstance(sampling_time, float): + sampling_time = datetime.timedelta(seconds=sampling_time) self.sampling_time = sampling_time self.version = version self.max_autocorrelation_time = max_autocorrelation_time diff --git a/bilby/core/sampler/__init__.py b/bilby/core/sampler/__init__.py index e586f138510cf5c8637b3faa27b4d3753a26b131..dde8d920cd52a03b7d3e647f29c5333378af20db 100644 --- a/bilby/core/sampler/__init__.py +++ b/bilby/core/sampler/__init__.py @@ -189,6 +189,8 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir', # Some samplers calculate the sampling time internally if result.sampling_time is None: result.sampling_time = end_time - start_time + elif isinstance(result.sampling_time, float): + result.sampling_time = datetime.timedelta(result.sampling_time) logger.info('Sampling time: {}'.format(result.sampling_time)) # Convert sampling time into seconds result.sampling_time = result.sampling_time.total_seconds()