Skip to content
Snippets Groups Projects
Commit feea4c58 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Merge branch '345-resume-file-removed-before-result-file-output' into 'master'

Resolve "Resume file removed before result file output"

Closes #345

See merge request !417
parents b237c32e 4826f8fc
No related branches found
No related tags found
No related merge requests found
......@@ -412,12 +412,17 @@ class Result(object):
default=False
outdir: str, optional
Path to the outdir. Default is the one stored in the result object.
extension: str, optional {json, hdf5}
Determines the method to use to store the data
extension: str, optional {json, hdf5, True}
Determines the method to use to store the data (if True defaults
to json)
gzip: bool, optional
If true, and outputing to a json file, this will gzip the resulting
file and add '.gz' to the file extension.
"""
if extension is True:
extension = "json"
outdir = self._safe_outdir_creation(outdir, self.save_to_file)
file_name = result_file_name(outdir, self.label, extension, gzip)
......
......@@ -167,6 +167,10 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
else:
result = sampler.run_sampler()
# Initial save of the sampler in case of failure in post-processing
if save:
result.save_to_file(extension=save, gzip=gzip)
end_time = datetime.datetime.now()
result.sampling_time = (end_time - start_time).total_seconds()
logger.info('Sampling time: {}'.format(end_time - start_time))
......@@ -188,12 +192,11 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
result.samples_to_posterior(likelihood=likelihood, priors=result.priors,
conversion_function=conversion_function)
if save == 'hdf5':
result.save_to_file(extension='hdf5')
logger.info("Results saved to {}/".format(outdir))
elif save:
result.save_to_file(gzip=gzip)
logger.info("Results saved to {}/".format(outdir))
if save:
# The overwrite here ensures we overwrite the initially stored data
result.save_to_file(overwrite=True, extension=save, gzip=gzip)
if plot:
result.plot_corner()
logger.info("Summary of results:\n{}".format(result))
......
......@@ -189,7 +189,10 @@ class Dynesty(NestedSampler):
if self.kwargs["verbose"]:
print("")
# self.result.sampler_output = out
dynesty_result = "{}/{}_dynesty.pickle".format(self.outdir, self.label)
with open(dynesty_result, 'wb') as file:
pickle.dump(out, file)
weights = np.exp(out['logwt'] - out['logz'][-1])
nested_samples = DataFrame(
out.samples, columns=self.search_parameter_keys)
......
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