Skip to content

Commit

Permalink
Resolve "patch to speed the MCMC"
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpitkin authored and mj-will committed Aug 22, 2024
1 parent 41cb703 commit 9a34533
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Bruce Edelman
Carl-Johan Haster
Cecilio Garcia-Quiros
Charlie Hoy
Chentao Yang
Christopher Philip Luke Berry
Christos Karathanasis
Colm Talbot
Expand Down
16 changes: 9 additions & 7 deletions bilby/core/sampler/emcee.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import shutil
from collections import namedtuple
from shutil import copyfile

import numpy as np
from packaging import version
Expand Down Expand Up @@ -333,16 +332,19 @@ def sampler(self):
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):
Expand Down

0 comments on commit 9a34533

Please sign in to comment.