-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Cannot pickle Map or System object (incompatibility with emcee) #292
Comments
You must be passing the The reason it's faster is that you're compiling all the operations (instantiating the map, setting the attributes, computing the flux, computing the likelihood) into a single executable function. You're also baking in the dataset into the compiled routine, so there's much, much less data transfer across cores. I usually recommend using |
Thanks @rodluger . After wrestling with theano (entirely new to me!) for a while and rewriting my model function, I was able to get the function to successfully compile in theano. The new 'fast,' 'non-lazy' version runs successfully, but emcee still bombs out with a long error trace, ending in:
System monitoring tools confirm that I'm nowhere near to running out of system memory, and searching online for I don't think this is a problem with starry; more likely, it's probably some issue relating to the unholy fusion of theano with my byzantine, and rather antiquated, error functions (specifically, I'm using https://crossfield.ku.edu/python/phasecurves.html#phasecurves.lnprobfunc). I'll try to explore the PyMC3 options mentioned above, though even their 'Tutorials' seem rather opaque to this frequentist-at-heart astronomer. |
Oh, quite the opposite -- I think that's a starry segfault. I believe you're instantiating the starry map like map = starry.Map(udeg=2, rv=True) If so, can you try doing map = starry.Map(ydeg=1, udeg=2, rv=True) and let me know if that fixes the issue? This could be an old bug popping up again when the degree of the Ylm expansion is zero. |
Adding But I CAN manage to successfully run starry's RM calculation wrapped inside of |
OK, I can confirm the issue is in import starry
import numpy as np
import emcee
from multiprocessing import Pool
import theano
import theano.tensor as tt
if __name__ == "__main__":
# Generate dataset
np.random.seed(0)
theta = np.linspace(0, 360, 100)
data = 0.1 * np.random.randn(len(theta))
def log_prob_(x):
map = starry.Map(rv=True)
map.inc = x[0]
map.veq = x[1]
model = map.rv(theta=theta)
return -0.5 * tt.sum((model - data) ** 2)
x = tt.dvector()
log_prob = theano.function([x], log_prob_(x))
nwalkers = 4
ndim = 2
niter = 100
guess = np.random.randn(nwalkers, ndim)
with Pool() as pool:
sampler = emcee.EnsembleSampler(nwalkers, ndim, log_prob, pool=pool)
sampler.run_mcmc(guess, niter, progress=True) I'll look into it. |
I can also confirm this seems to only happen during multiprocessing. Setting
Looks like |
I figured it out. The issue was on this line. For some reason I had declared |
@iancrossfield Feel free to re-open if you run into more trouble or have any other questions. The code is now working on |
Describe the bug
When I try to use starry in the MCMC sampler `emcee' (via either the Map object directly, or via the System object), emcee fails in both cases because the Map object cannot be pickled. Specifically:
"AttributeError: Can't pickle local object 'Map..Map'"
To Reproduce
Results in the error listed above.
Expected behavior
I expect to be able to successfully use starry Map or System objects in Bayesian inference calculations (specifically, MCMC; very specifically, via 'emcee').
Your setup (please complete the following information):
The text was updated successfully, but these errors were encountered: