Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pm.sample cannot pickle LimbDark object #115

Closed
lgrcia opened this issue Oct 16, 2020 · 5 comments · Fixed by #120
Closed

pm.sample cannot pickle LimbDark object #115

lgrcia opened this issue Oct 16, 2020 · 5 comments · Fixed by #120
Labels
documentation Missing docs or mistakes in existing ones

Comments

@lgrcia
Copy link

lgrcia commented Oct 16, 2020

Error
Getting TypeError: cannot pickle 'exoplanet.theano_ops.driver.LimbDark' object when sampling a model containing LimbDarkLightCurve

Reproduction
Fresh virtualenv with exoplanet, pymc3, tqdm installed

python3 -m venv xotest
source ./xotest/bin/activate.fish
pip install tqdm exoplanet pymc3

and running docs/tutorials/transit.py

cd xotest
curl -O https://raw.githubusercontent.com/exoplanet-dev/exoplanet/main/docs/tutorials/transit.py
python ./transit.py

Setup:

  • exoplanet==0.4.0
  • macOS 10.14.6
  • Python 3.8.5
  • pip 20.1.1
@lgrcia lgrcia added the bug Something isn't working label Oct 16, 2020
@dfm
Copy link
Member

dfm commented Oct 16, 2020

You won't be able to run that as a script on macOS with Python 3.8 because of issues with how multiprocessing now works. You'll need to wrap your script in a if __name__ == "__main__" and then make sure that multiprocessing is using fork instead of spawn or forkserver.

Unfortunately there's not much to do from within exoplanet except add a page to the docs so I'm going to relabel this as a documentation issue rather than a bug.

Related issues:

@dfm dfm added documentation Missing docs or mistakes in existing ones and removed bug Something isn't working labels Oct 16, 2020
@lgrcia
Copy link
Author

lgrcia commented Oct 20, 2020

I get this error as well on Linux when simply trying to pickle the model in docs/tutorials/transit.py. Like:

with open("test.pickle", "wb") as f:
    pickle.dump(model, f)

TypeError: cannot pickle 'exoplanet.theano_ops.driver.LimbDark' object

It works with exoplanet 0.3.2 but not 0.4.0 (At the end I was able to sample on macOS by downgrading the package)

@dfm
Copy link
Member

dfm commented Oct 20, 2020

OK - I'll take a look into this because it would be good to be able to pickle these models, but I don't understand why I haven't run into a sampling issue before if you're still getting it. I use parallel sampling on macos and ubuntu every day with v0.4 and the tutorial is automatically run on CI for every push.

@lgrcia
Copy link
Author

lgrcia commented Oct 20, 2020

This is puzzling indeed. I will try to investigate as well what could be wrong in my process.

For reference: Before running into the last point I tried using if __name__ == "__main__" with fork (trying both mp_ctx and multiprocessing.set_start_method as mentioned in pymc-devs/pymc#3844 (comment)) with Python 3.8.5 and Python 3.6.5 on macOS, leading to the same error in v0.4.0.

dfm added a commit that referenced this issue Oct 20, 2020
@dfm dfm linked a pull request Oct 20, 2020 that will close this issue
@dfm
Copy link
Member

dfm commented Oct 20, 2020

This will all have something to do with running in a Jupyter environment vs a script. These tutorials are designed to be run using jupytext, not directly as a script. #120 fixes the issue with pickling and #121 will track documenting best practices for running parallel sampling as a script (this is where the __name__ part comes in!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Missing docs or mistakes in existing ones
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants