Skip to content
Snippets Groups Projects
Commit 8298687f authored by Colm Talbot's avatar Colm Talbot
Browse files

Merge branch 'fix-hdf5-time-saving' into 'master'

Make sampling time saving work with hdf5

See merge request !1085
parents f9e92e6a 01338356
No related branches found
No related tags found
1 merge request!1085Make sampling time saving work with hdf5
Pipeline #365798 passed
......@@ -363,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: (datetime.timedelta, 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
......
import datetime
import inspect
import json
import os
......@@ -301,6 +302,8 @@ def encode_for_hdf5(key, item):
output = item.copy()
elif isinstance(item, tuple):
output = {str(ii): elem for ii, elem in enumerate(item)}
elif isinstance(item, datetime.timedelta):
output = item.total_seconds()
else:
raise ValueError(f'Cannot save {key}: {type(item)} type')
return output
......
......@@ -69,6 +69,7 @@ class TestResult(unittest.TestCase):
sampler_kwargs=dict(test="test", func=lambda x: x),
injection_parameters=dict(x=0.5, y=0.5),
meta_data=dict(test="test"),
sampling_time=100.0,
)
n = 100
......@@ -254,6 +255,7 @@ class TestResult(unittest.TestCase):
self.assertEqual(self.result.priors["y"], loaded_result.priors["y"])
self.assertEqual(self.result.priors["c"], loaded_result.priors["c"])
self.assertEqual(self.result.priors["d"], loaded_result.priors["d"])
self.assertEqual(self.result.sampling_time, loaded_result.sampling_time)
def test_save_and_dont_overwrite_json(self):
self._save_and_dont_overwrite_test(extension='json')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment