Skip to content
Snippets Groups Projects
Commit 9a34533d authored by Matthew David Pitkin's avatar Matthew David Pitkin Committed by Michael Williams
Browse files

Resolve "patch to speed the MCMC"

parent 41cb703c
No related branches found
No related tags found
1 merge request!1378Resolve "patch to speed the MCMC"
Pipeline #656014 passed
......@@ -16,6 +16,7 @@ Bruce Edelman
Carl-Johan Haster
Cecilio Garcia-Quiros
Charlie Hoy
Chentao Yang
Christopher Philip Luke Berry
Christos Karathanasis
Colm Talbot
......
import os
import shutil
from collections import namedtuple
from shutil import copyfile
import numpy as np
from packaging import version
......@@ -333,16 +332,19 @@ class Emcee(MCMCSampler):
def write_chains_to_file(self, sample):
chain_file = self.checkpoint_info.chain_file
temp_chain_file = chain_file + ".temp"
if os.path.isfile(chain_file):
copyfile(chain_file, temp_chain_file)
if self.prerelease:
points = np.hstack([sample.coords, sample.blobs])
else:
points = np.hstack([sample[0], np.array(sample[3])])
with open(temp_chain_file, "a") as ff:
for ii, point in enumerate(points):
ff.write(self.checkpoint_info.chain_template.format(ii, *point))
shutil.move(temp_chain_file, chain_file)
data_to_write = "\n".join(
self.checkpoint_info.chain_template.format(ii, *point)
for ii, point in enumerate(points)
)
with open(temp_chain_file, "w") as ff:
ff.write(data_to_write)
with open(temp_chain_file, "rb") as ftemp, open(chain_file, "ab") as fchain:
shutil.copyfileobj(ftemp, fchain)
os.remove(temp_chain_file)
@property
def _previous_iterations(self):
......
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