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

Support PyMC v5 #309

Merged
merged 56 commits into from
Apr 16, 2024
Merged

Support PyMC v5 #309

merged 56 commits into from
Apr 16, 2024

Conversation

vandalt
Copy link
Contributor

@vandalt vandalt commented Nov 3, 2023

This builds upon #271, where pretty much all the hard work required to update from PyMC3 had already been done, and implements support of PyMC v5. Most of the changes were replacing aesara by pytensor plus a few API changes.

Some things left to address:

  • Should the joss directory be updated? I'm guessing the answer is no
  • Update requirement version for exoplanet-core, pymc-ext and celerite2 once pymc >= 5 support is released there. This is required for the tests to pass.
  • Is it OK to remove warning filters in utils.docs_setup()? I left TODO comments to discuss this.
  • There is a reference to pytensor.opt.Assert (which used to be theano.opt.Assert) which no longer exists. See comment in the code
  • For the Docs: is the lowest compatible Python version 3.6? I have not tested this but I saw that 3.8 is the lowest version test by nox (and the lowest still getting security updates I think)
  • Updating the case studies. Not technically required before merging into main, but probably worth waiting in case it exposes bugs or deprecation warnings.

src/exoplanet/utils.py Outdated Show resolved Hide resolved
docs/user/install.rst Outdated Show resolved Hide resolved
@dfm
Copy link
Member

dfm commented Nov 7, 2023

@vandalt — Thanks!! 🚀

It will take me a week or so to go through this in detail, but here are some initial comments.

First, can you take a look at the merge conflicts with main? You could rebase if you want, but I'd also be fine with the merge commit (merge from main, fix the conflicts, then commit).

Should the joss directory be updated? I'm guessing the answer is no

Agreed. I think we should leave that as is.

Update requirement version for exoplanet-core, pymc-ext and celerite2 once pymc >= 5 support is released there. This is required for the tests to pass.

I'll try to get those released ASAP. Might be worth adding a test against the GitHub versions of those in the meantime as well though? What do you think?

Is it OK to remove warning filters in utils.docs_setup()? I left TODO comments to discuss this.

This is fine with me as long as pytensor doesn't spew so many warnings!

For the Docs: is the lowest compatible Python version 3.6? I have not tested this but I saw that 3.8 is the lowest version test by nox (and the lowest still getting security updates I think)

I'm happy to update to 3.8 or 3.9 as the lower bound!

Updating the case studies. Not technically required before merging into main, but probably worth waiting in case it exposes bugs or deprecation warnings.

I think this is a big one, but I don't think we should worry about solving it before merging this PR. Instead, we should open a separate issue to track that.

@vandalt
Copy link
Contributor Author

vandalt commented Nov 7, 2023

Thanks!

I'll try to get those released ASAP. Might be worth adding a test against the GitHub versions of those in the meantime as well though? What do you think?

Yes, I can add that!

This is fine with me as long as pytensor doesn't spew so many warnings!

I'll try removing and make sure there are not too many warnings when running the tests with pytest -s or the tutorials

I think this [case studies update] is a big one, but I don't think we should worry about solving it before merging this PR. Instead, we should open a separate issue to track that.

I agree it's a big one, but I think trying a quick update+run for each notebooks (without necessarily fixing everything) would be worthwhile. So far the pRV one helped uncover a problem with passing observed=ecc to eccentricity priors (basically having observed pointing to a prior or Deterministic parameter no longer works. We need to use pm.Potential). I added a test for this and will push it soon, hopefully with a fix

@vandalt
Copy link
Contributor Author

vandalt commented Nov 7, 2023

@dfm another point I forgot to raise is that unit_disk and angles are defined both here and in exoplanet-dev/pymc-ext. Should one of them be removed (with a deprecation warning at first)?

@vandalt
Copy link
Contributor Author

vandalt commented Mar 6, 2024

Hi @dfm!

I finally took time to look at the remaining issues with this PR.

  • I just finished a first attempt at updating the case studies. I'll send a PR on that repo later today.
  • While doing that, I noticed (as mentioned above) that PyMC 5 no longer supports observed to depend on other random variables/model parameters. This required an update of the eccentricity prior to use pm.Potential() when ecc is a derived parameter.
  • I rebased onto main (not super experienced with rebase/merged conflict, hopefully I did not mess the commit history too much!)

I think the only remaining thing would be to update the celerite2, pymc-ext and exoplanet-core requirements. Let me know if it's best to wait for release candidates or if I should test against the git versions for now.

Thanks!

@dfm
Copy link
Member

dfm commented Mar 6, 2024

Thanks for all your work on this, @vandalt!!

I'll work on getting those other packages released ASAP, but it probably won't be until next week. Can you try to remember to ping me if you don't see any motion by Monday afternoon or Tuesday morning next week?

@dfm
Copy link
Member

dfm commented Mar 7, 2024

@vandalt — I did manage to publish new releases of all of the dependencies yesterday and re-ran the tests. Any guesses for why the PyMC3 tests are failing now?

@vandalt
Copy link
Contributor Author

vandalt commented Mar 8, 2024

@dfm

Yes sorry, I had forgotten to re-run the tests with PyMC3 locally. Most errors were related to differences in how to access the shape of a variable in PyMC3 vs 5.

For the Kipping eccentricity prior, I had added a test for something that was not implemented in the PyMC3 version (truncated distribution with observed eccentricity), so I modified the test to expect the NotImplementedError.

For the vaneylen19 eccentricity prior, I'm not 100% sure what caused the issue, but reverting the PyMC3 version of the prior closer to its original form fixed the issue on my local setup. This comes at the cost of slightly more if USING_PYMC3 conditions, but at least now the tests pass for both versions!

@dfm
Copy link
Member

dfm commented Mar 8, 2024

Great - thanks!! I'll look into debugging the docs build errors because those can be tricky to track down.

@vandalt
Copy link
Contributor Author

vandalt commented Mar 9, 2024

It seems the docs thing was not too tricky (and 100% my fault 😅): I had moved exoplanet-core from the "main" dependencies to the pymc and pymc3 extra groups, because the required versions were now different. I just added exoplanet-core to the docs extra as well.

vandalt and others added 25 commits April 16, 2024 10:36
In PyMC 3, we could just used `observed=ecc` with any distribution.
In PyMC >= 5, we need to use a `pm.Potential`
Same as kipping13: if eccentricity is "observed" (derived), extra prior must be a `pm.Potential`
Previously, default initval was hardcoded so passing shape without initval caused error. Added failing tests and fixed
…nds in kipping13

This did not work with the original PyMC3 implementation either, but is supported in PyMC 5.
This error makes it a bit clearer
`type.shape` works only in PyMC > 3
The implementation that worked with PyMC v5 did not in PyMC3
Had to remove from the main dependencies because no of the different versions for PyMC3 and PyMC 5
@dfm
Copy link
Member

dfm commented Apr 16, 2024

@vandalt — I pushed a few changes to fix some merge conflicts and get the tests passing, but now I think we're good to go here!! I'm going to merge and we can fix issues as they come up in future PRs. Thanks again for all your work getting this over the finish line!! I (and the whole community) really really appreciate everything that you've done here!!! 🚀

@dfm dfm merged commit c4eceb4 into exoplanet-dev:main Apr 16, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants