Last active
May 23, 2024 07:07
-
-
Save andyfaff/9cdb090af66474a53a2f17381fa7aa93 to your computer and use it in GitHub Desktop.
Pickle-free multiprocessing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import stuff | |
import multiprocessing | |
import pickle | |
from refnx._lib.emcee import EnsembleSampler | |
nvp = len(objective.varying_parameters()) | |
with multiprocessing.pool.Pool(processes=None, initializer=stuff.initialiser, initargs=(pickle.dumps(objective),)) as pwl: | |
sampler = EnsembleSampler(200, nvp, stuff.calculator, pool=pwl) | |
%time sampler.run_mcmc(fitter.chain[-1], 4000) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
obj = None | |
def initialiser(*args): | |
global obj | |
obj = pickle.loads(args[0]) | |
def calculator(x): | |
return obj.logpost(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment