Skip to content

Commit

Permalink
Support PyMC v5 (#309)
Browse files Browse the repository at this point in the history
* Implementing support for pymc v4

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* workflow error

* workflow

* allow python version for lint

* getting distributions to work

* some tweaks for pymc3

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* pymc3 fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactoring distributions again

* docstrings for distributions

* starting to re-write docs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint and starting to update tutorials

* fixing some eccentricity dist issues

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updating docs

* updating citations

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update README [ci skip]

* making orphan page [ci skip]

* Require PyMC < 5 for PyMC v4 version of exoplanet

* Require pymc >= 5 in setup.py

Left TODO comments about other exoplanet-dev packages. No released version yet but their main branch has support for pymc >= 5

* Replace aesara by pytensor and pymc4 by pymc

The actual imports are in the compat module, but I updated `at` to `pt`.
That way `exoplanet` stays up to date with latest "notation" for `pytensor.tensor`

* Add upper limit on xarray for pymc3

Causes numpy error for Python >= 3.9 otherwise

* Accept pre-commit changes on tutorial notebooks

* Replace `AESARA_FLAGS` by `PYTENSOR_FLAGS` in `pytest.ini`

* Update docs from PyMC 4 to PyMC 5 (mostly pytensor -> Aesara)

* Comment-out warnings in `docs_setup()` with TODO to maybe remove them

* TODO comment for deprecated `pt.opt.Assert`

* Update `Evaluator()` call to use `model` kwarg

* Replace testval by initval and start by initvals

* Enable using kipping13 prior when eccentricity is a derived parameter

In PyMC 3, we could just used `observed=ecc` with any distribution.
In PyMC >= 5, we need to use a `pm.Potential`

* Add `_truncate_dist` helper function for eccentricity prior

* Fix vanelyen19 prior when eccentricity is a derived parameter

Same as kipping13: if eccentricity is "observed" (derived), extra prior must be a `pm.Potential`

* Test `angle()` and `unit_disk()` distributions and fix shape error

Previously, default initval was hardcoded so passing shape without initval caused error. Added failing tests and fixed

* Pop initval when ecc is None only when bounds are set

* Clean-up `_truncate_dist()` helper function

* Raise `NotImplementedError` when trying to pass observed ecc with bounds 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

* Test eccentricity priors with and without bounds

* Update required Python version from 3.6 to 3.8 in docs

* Convert shape from `int` to `tuple` for pymc>3 in impact parameter distribution

* Remove deprecated `pt.opt.Assert` in favor of `Assert` from `compat`

* Remove leftover commented-out warning filters

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Replace tox dependency by nox

* Check that kipping13_observed raises error with bounds when using PyMC3

* Get shape using `tag.test_value` for PyMC3 tests

`type.shape` works only in PyMC > 3

* Remove extra potential in vaneylen19 distribution PyMC 3 version

The implementation that worked with PyMC v5 did not in PyMC3

* Update dependency versions for PyMC v5

* Add `exoplanet-core` dependency to `docs`

Had to remove from the main dependencies because no of the different versions for PyMC3 and PyMC 5

* Another merge conflict

* Range of tests for deps

* Don't install coverage

---------

Co-authored-by: Dan F-M <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 16, 2024
1 parent 3bfeb14 commit c4eceb4
Show file tree
Hide file tree
Showing 57 changed files with 1,782 additions and 1,623 deletions.
2 changes: 0 additions & 2 deletions .clang-format

This file was deleted.

1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
paper/* linguist-documentation
docs/* linguist-documentation
exoplanet/theano_ops/vendor/* linguist-vendored
*.h linguist-language=C++
docs/notebooks/*.ipynb filter=nbstripout
paper/figures/*.ipynb filter=nbstripout
Expand Down
74 changes: 22 additions & 52 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,46 @@ on:

jobs:
tests:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10"]
python-version: ["3.10"]
os: ["ubuntu-latest"]
session: ["test_pymc3", "test_pymc"]
include:
- python-version: "3.9"
os: "ubuntu-latest"
session: "test_pymc3"
- python-version: "3.11"
os: "ubuntu-latest"
session: "test_pymc"
- python-version: "3.10"
os: "ubuntu-latest"
session: "lint"

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v5
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U coveralls coverage[toml] tox tox-gh-actions
python -m pip install -U nox
- name: Run tests
run: python -m tox

- name: Combine and upload coverage
run: |
python -m coverage combine
python -m coverage xml -i
python -m coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: py${{ matrix.python-version }}

coverage:
needs: tests
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Finish coverage collection
run: |
python -m pip install -U pip
python -m pip install -U coveralls
python -m coveralls --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install tox
- name: Lint the code
run: python -m tox -e lint
python -m nox --non-interactive \
--error-on-missing-interpreter \
--python ${{ matrix.python-version }} \
--session ${{ matrix.session }}
build:
runs-on: ubuntu-latest
Expand All @@ -104,7 +74,7 @@ jobs:
path: dist/*

upload_pypi:
needs: [tests, lint, build]
needs: [tests, build]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
Fast & scalable MCMC for all your exoplanet needs! _exoplanet_ is a toolkit for
probabilistic modeling of time series data in astronomy with a focus on
observations of [exoplanets](https://en.wikipedia.org/wiki/Exoplanet), using
[PyMC3](https://docs.pymc.io). _PyMC3_ is a flexible and high-performance model
building language and inference engine that scales well to problems with a large
number of parameters. _exoplanet_ extends _PyMC3_'s language to support many of
the custom functions and distributions required when fitting exoplanet datasets.
[PyMC](https://www.pymc.io). _PyMC_ is a flexible and high-performance
model-building language and inference engine that scales well to problems with a
large number of parameters. _exoplanet_ extends _PyMC_'s language to support
many of the custom functions and distributions required when fitting exoplanet
datasets.

Read the full documentation at [docs.exoplanet.codes](https://docs.exoplanet.codes).

Expand All @@ -29,7 +30,7 @@ Read the full documentation at [docs.exoplanet.codes](https://docs.exoplanet.cod
The quickest way to get started is to use [pip](https://pip.pypa.io):

```bash
python -m pip install exoplanet
python -m pip install "exoplanet[pymc]"
```

Note that you will need Python (>=3.6) installed for this to work, but then this
Expand All @@ -47,7 +48,7 @@ page](https://gallery.exoplanet.codes).

## Contributing

_exoplanet_ is an open source project and we would love it if you wanted to
_exoplanet_ is an open-source project, and we would love it if you wanted to
contribute. Check out [the developer
documentation](https://docs.exoplanet.codes/en/latest/user/dev/) for more info
about getting started.
2 changes: 1 addition & 1 deletion binder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pymc3-ext>=0.1.0
emcee
numpy<1.22
xarray<2023.10.0
.
.[docs]
17 changes: 8 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ exoplanet

*exoplanet* is a toolkit for probabilistic modeling of time series data in
astronomy with a focus on observations of `exoplanets
<https://en.wikipedia.org/wiki/Exoplanet>`_, using `PyMC3
<https://docs.pymc.io>`_. *PyMC3* is a flexible and high-performance model
<https://en.wikipedia.org/wiki/Exoplanet>`_, using `PyMC
<https://www.pymc.io>`_. *PyMC* is a flexible and high-performance model
building language and inference engine that scales well to problems with a large
number of parameters. *exoplanet* extends *PyMC3*'s language to support many of
number of parameters. *exoplanet* extends *PyMC*'s language to support many of
the custom functions and distributions required when fitting exoplanet datasets.
These features include:

Expand Down Expand Up @@ -44,13 +44,13 @@ an issue <https://github.com/exoplanet-dev/exoplanet/issues>`_ there.
🖼 For more in depth examples of *exoplanet* used for more realistic problems,
go to the `Case studies page <https://gallery.exoplanet.codes>`_.

📈 For more information about scalable Gaussian Processes in PyMC3 (this was
📈 For more information about scalable Gaussian Processes in PyMC (this was
previously implemented as part of *exoplanet*), see the `celerite2 documentation
page <https://celerite2.readthedocs.io>`_.

👉 For helper functions and PyMC3 extras that used to be implemented as part of
*exoplanet*, see the `pymc3-ext project
<https://github.com/exoplanet-dev/pymc3-ext>`_.
👉 For helper functions and PyMC extras that used to be implemented as part of
*exoplanet*, see the `pymc-ext project
<https://github.com/exoplanet-dev/pymc-ext>`_.


Contents
Expand All @@ -62,7 +62,6 @@ Contents

user/install
tutorials/citation.md
user/theano
user/multiprocessing
user/api
user/dev
Expand All @@ -74,7 +73,7 @@ Contents

tutorials/about.md
tutorials/autodiff.md
tutorials/intro-to-pymc3.md
tutorials/intro-to-pymc.md
tutorials/data-and-models.md
tutorials/light-delay.md
tutorials/reparameterization.md
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jupytext:
format_version: 0.13
jupytext_version: 1.15.2
kernelspec:
display_name: Python 3
display_name: Python 3 (ipykernel)
language: python
name: python3
---
Expand All @@ -15,8 +15,8 @@ kernelspec:

+++

This and the following tutorials are automatically executed with every change of the code to make sure that they are always up to date with the code.
As a result, they are designed to require only a relatively small amount of computation time; when using `exoplanet` for research you will probably find that your runtimes are longer.
This and the following tutorials are automatically executed with every change of the code to make sure that they are always up-to-date with the code.
As a result, they are designed to require only a relatively small amount of computation time; when using `exoplanet` for research you will probably find that your run times are longer.
For more in-depth tutorials with real-world applications and real data, check out the [Case Studies page](https://gallery.exoplanet.codes).

At the top of each tutorial, you'll find a cell like the following that indicates the version of `exoplanet` that was used to generate the tutorial:
Expand All @@ -28,9 +28,9 @@ exoplanet.utils.docs_setup()
print(f"exoplanet.__version__ = '{exoplanet.__version__}'")
```

That cell also includes a call to the `exoplanet.utils.docs_setup` function that will squash some warnings (these are generally caused by Theano/Aesara; see {ref}`theano` for more info) and set up our `matplotlib` style.
That cell also includes a call to the `exoplanet.utils.docs_setup` function that will squash some warnings (these are generally caused by Theano/PyTensor) and set up our `matplotlib` style.

To exectute a tutorial on your own, you can click on the buttons at the top right or this page to launch the notebook using [Binder](https://mybinder.org) or download the `.ipynb` file directly.
To execute a tutorial on your own, you can click on the buttons at the top right or this page to launch the notebook using [Binder](https://mybinder.org) or download the `.ipynb` file directly.

```{code-cell}
Expand Down
Loading

0 comments on commit c4eceb4

Please sign in to comment.