Skip to content
Snippets Groups Projects
Commit a2f2a878 authored by Matthew David Pitkin's avatar Matthew David Pitkin Committed by Colm Talbot
Browse files

Catch error if trying to load zero bytes resume file

parent 69ca3538
No related branches found
No related tags found
No related merge requests found
......@@ -388,7 +388,9 @@ class Bilby_MCMC(MCMCSampler):
If true, resume file was successfully loaded, otherwise false
"""
if os.path.isfile(self.resume_file) is False:
if os.path.isfile(self.resume_file) is False or not os.path.getsize(
self.resume_file
):
return False
import dill
......
......@@ -736,7 +736,10 @@ class Dynesty(NestedSampler):
if os.path.isfile(self.resume_file):
logger.info(f"Reading resume file {self.resume_file}")
with open(self.resume_file, "rb") as file:
sampler = dill.load(file)
try:
sampler = dill.load(file)
except EOFError:
sampler = None
if not hasattr(sampler, "versions"):
logger.warning(
......
......@@ -311,7 +311,11 @@ class Emcee(MCMCSampler):
"""
if hasattr(self, "_sampler"):
pass
elif self.resume and os.path.isfile(self.checkpoint_info.sampler_file):
elif (
self.resume
and os.path.isfile(self.checkpoint_info.sampler_file)
and os.path.getsize(self.checkpoint_info.sampler_file)
):
import dill
logger.info(
......
......@@ -166,7 +166,11 @@ class Kombine(Emcee):
return self.sampler.chain[:nsteps, :, :]
def check_resume(self):
return self.resume and os.path.isfile(self.checkpoint_info.sampler_file)
return (
self.resume
and os.path.isfile(self.checkpoint_info.sampler_file)
and os.path.getsize(self.checkpoint_info.sampler_file) > 0
)
@signal_wrapper
def run_sampler(self):
......
......@@ -415,7 +415,11 @@ class Ptemcee(MCMCSampler):
# This is a very ugly hack to support numpy>=1.24
ptemcee.sampler.np.float = float
if os.path.isfile(self.resume_file) and self.resume is True:
if (
os.path.isfile(self.resume_file)
and os.path.getsize(self.resume_file)
and self.resume is True
):
import dill
logger.info(f"Resume data {self.resume_file} found")
......@@ -513,7 +517,7 @@ class Ptemcee(MCMCSampler):
logger.info("Starting to sample")
while True:
for (pos0, log_posterior, log_likelihood) in sampler.sample(
for pos0, log_posterior, log_likelihood in sampler.sample(
self.pos0,
storechain=False,
iterations=self.convergence_inputs.niterations_per_check,
......
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