Skip to content

Commit 8cf1f8a

Browse files
authored
Merge pull request #232 from pymc-labs/pymc5-migration
PyMC 5 migration
2 parents 4c72d96 + 7bd84d8 commit 8cf1f8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+10314
-2123
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fetch-depth: 0
1818
- uses: actions/setup-python@v4
1919
with:
20-
python-version: 3.8
20+
python-version: '3.10'
2121
- name: Build the sdist and the wheel
2222
run: |
2323
pip install build
@@ -40,7 +40,7 @@ jobs:
4040
echo "Checking import and version number (on release)"
4141
venv-bdist/bin/python -c "import homepy; assert homepy.__version__ == '${{ github.ref_name }}' if '${{ github.ref_type }}' == 'tag' else homepy.__version__; print(homepy.__version__)"
4242
cd ..
43-
- uses: actions/upload-artifact@v3
43+
- uses: actions/upload-artifact@v4
4444
with:
4545
name: artifact
4646
path: dist/*
@@ -63,7 +63,7 @@ jobs:
6363
CACHE_NUMBER: 0
6464
with:
6565
path: ~/conda_pkgs_dir
66-
key: ${{ runner.os }}-py3.8-conda-${{ env.CACHE_NUMBER }}-${{
66+
key: ${{ runner.os }}-py3.10-conda-${{ env.CACHE_NUMBER }}-${{
6767
hashFiles('envs/environment-test.yml') }}
6868
- uses: conda-incubator/setup-miniconda@v2
6969
with:
@@ -73,13 +73,15 @@ jobs:
7373
activate-environment: homepy
7474
channel-priority: strict
7575
environment-file: envs/environment-test.yml
76-
python-version: '3.8'
76+
python-version: '3.10'
7777
use-mamba: true
7878
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
7979
- name: Install-package
8080
run: |
8181
pip install -e .[dev]
8282
python --version
83+
# Verify PyMC v5 is installed
84+
python -c "import pymc; print(f'PyMC version: {pymc.__version__}'); assert pymc.__version__.startswith('5'), 'PyMC v5 required'"
8385
- name: Run tests
8486
run: |
8587
conda activate homepy
@@ -102,7 +104,7 @@ jobs:
102104
repository_url: https://test.pypi.org/legacy/
103105
- uses: actions/setup-python@v4
104106
with:
105-
python-version: 3.8
107+
python-version: '3.10'
106108
- name: Test pip install from test.pypi
107109
run: |
108110
# Give time to test.pypi to update its index. If we don't wait,

.github/workflows/tests.yml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- uses: actions/checkout@v3
4444
- uses: actions/setup-python@v4
4545
with:
46-
python-version: '3.8'
46+
python-version: '3.10'
4747
- uses: pre-commit/action@v3.0.0
4848
tests:
4949
needs:
@@ -57,32 +57,19 @@ jobs:
5757
strategy:
5858
fail-fast: true
5959
steps:
60-
- uses: actions/checkout@v2
61-
- name: Cache conda
62-
uses: actions/cache@v3
63-
env:
64-
# Increase this value to reset cache if environment-test.yml has not changed
65-
CACHE_NUMBER: 0
66-
with:
67-
path: ~/conda_pkgs_dir
68-
key: ${{ runner.os }}-py3.8-conda-${{ env.CACHE_NUMBER }}-${{
69-
hashFiles('envs/environment-test.yml') }}
70-
- uses: conda-incubator/setup-miniconda@v2
60+
- uses: actions/checkout@v3
61+
- uses: mamba-org/setup-micromamba@v2
7162
with:
72-
miniforge-variant: Mambaforge
73-
miniforge-version: latest
74-
mamba-version: "*"
75-
activate-environment: homepy
76-
channel-priority: strict
7763
environment-file: envs/environment-test.yml
78-
python-version: '3.8'
79-
use-mamba: true
80-
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
64+
environment-name: homepy-test
65+
init-shell: bash
66+
cache-environment: true
8167
- name: Install-package
8268
run: |
8369
pip install -e .[dev]
8470
python --version
71+
# Verify PyMC v5 is installed
72+
python -c "import pymc; print(f'PyMC version: {pymc.__version__}'); assert pymc.__version__.startswith('5'), 'PyMC v5 required'"
8573
- name: Run tests
8674
run: |
87-
conda activate homepy
88-
pytest
75+
python -m pytest -vv --cov=homepy --cov-report=xml --no-cov-on-fail --cov-report term-missing

.pre-commit-config.yaml

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude: ^(docs/logos|homepy/tests|)/
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.0.1
4+
rev: v5.0.0
55
hooks:
66
- id: check-merge-conflict
77
- id: check-toml
@@ -13,46 +13,31 @@ repos:
1313
- id: requirements-txt-fixer
1414
exclude: ^requirements-dev\.txt$
1515
- id: trailing-whitespace
16-
- repo: https://github.com/PyCQA/isort
17-
rev: 5.12.0
18-
hooks:
19-
- id: isort
20-
name: isort
21-
- repo: https://github.com/asottile/pyupgrade
22-
rev: v2.29.1
23-
hooks:
24-
- id: pyupgrade
25-
args: [--py37-plus]
26-
- repo: https://github.com/psf/black
27-
rev: 22.3.0
28-
hooks:
29-
- id: black
30-
- repo: https://github.com/PyCQA/pylint
31-
rev: v2.12.1
32-
hooks:
33-
- id: pylint
34-
args: [--rcfile=.pylintrc]
35-
files: ^homepy/
3616
- repo: https://github.com/MarcoGorelli/madforhooks
37-
rev: 0.2.1
17+
rev: 0.4.1
3818
hooks:
3919
- id: no-print-statements
4020
files: ^homepy/
4121
- id: conda-env-sorter
4222
files: ^conda-envs/environment-dev-py.+\.yml$
43-
- repo: https://github.com/nbQA-dev/nbQA
44-
rev: 1.6.1
45-
hooks:
46-
- id: nbqa-pyupgrade
47-
additional_dependencies: [pyupgrade==2.29.1]
48-
args: ["--py37-plus"]
49-
- id: nbqa-isort
50-
additional_dependencies: [isort==5.12.0]
51-
- id: nbqa-black
52-
additional_dependencies: [black==22.3.0]
53-
- id: nbqa-pylint
54-
args: [--rcfile=.pylintrc]
55-
additional_dependencies: [pylint==2.12.1]
23+
- repo: https://github.com/astral-sh/ruff-pre-commit
24+
rev: v0.12.7
25+
hooks:
26+
- id: ruff
27+
types_or:
28+
- python
29+
- pyi
30+
- jupyter
31+
args:
32+
- --fix
33+
- --exit-non-zero-on-fix
34+
exclude: ^(docs)
35+
- id: ruff-format
36+
types_or:
37+
- python
38+
- pyi
39+
- jupyter
40+
exclude: ^(docs)
5641
- repo: local
5742
hooks:
5843
- id: check-no-tests-are-ignored
@@ -68,3 +53,11 @@ repos:
6853
files: ^conda-envs/environment-dev-py.+.yml$
6954
language: python
7055
name: Generate pip dependency from conda
56+
- repo: https://github.com/lucianopaz/head_of_apache
57+
rev: "0.1.1"
58+
hooks:
59+
- id: head_of_apache
60+
args:
61+
- --author
62+
- PyMC Labs
63+
- --last-year-present

docs/02_modeling.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
" </tr>\n",
222222
" </tbody>\n",
223223
"</table>\n",
224-
"<p>9000 rows × 6 columns</p>\n",
224+
"<p>9000 rows \u00d7 6 columns</p>\n",
225225
"</div>"
226226
],
227227
"text/plain": [
@@ -1075,7 +1075,7 @@
10751075
"\n",
10761076
"The `n` parameter is equal to the concentration parameter from our observational distribution. In our case, since we assumed that `n` followed an exponential distribution with unit length scale, it's impossible that it's value were too big.\n",
10771077
"\n",
1078-
"The `p` parameter is linked to the negative binomial's mean. Under the parametrization that numpy works with, the expected value of the negative binomial is `n * (1 - p) / p`. With some math, we can see that small `p` values imply extremely large expected observations! This means that our prior for the model made it possible to have extremely large means after the link function! Let's see how we can fix that."
1078+
"The `p` parameter is linked to the negative binomial's mean. Under the parametrization that numpy works with, the expected value of the negative binomial is `n * (1 - p) / p`. With some math, we can see that small `p` values imply extremely large expected observations! This means that our prior for the model made it possible to have extremely large means after the link function! Let's see how we can fix thpt."
10791079
]
10801080
},
10811081
{
@@ -4857,7 +4857,7 @@
48574857
],
48584858
"source": [
48594859
"import graphviz\n",
4860-
"from aesara.graph.basic import walk\n",
4860+
"from pytensor.graph.basic import walk\n",
48614861
"\n",
48624862
"tracked = [\n",
48634863
" n\n",

docs/04_customizing.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"import numpy as np\n",
6262
"import pandas as pd\n",
6363
"import pymc as pm\n",
64-
"from aesara import tensor as at\n",
64+
"from pytensor import tensor as at\n",
6565
"\n",
6666
"import homepy"
6767
]
@@ -795,7 +795,7 @@
795795
" coefficients = pm.Normal(name, mu=mu, sigma=sigma, shape=len(regressor_columns))\n",
796796
"\n",
797797
" regressors = pm.ConstantData(\"The regressors\", data[regressor_columns].values)\n",
798-
" return at.dot(regressors, coefficients)"
798+
" return pt.dot(regressors, coefficients)"
799799
]
800800
},
801801
{
@@ -2033,7 +2033,7 @@
20332033
" </tr>\n",
20342034
" </tbody>\n",
20352035
"</table>\n",
2036-
"<p>9000 rows × 6 columns</p>\n",
2036+
"<p>9000 rows \u00d7 6 columns</p>\n",
20372037
"</div>"
20382038
],
20392039
"text/plain": [
@@ -2735,7 +2735,7 @@
27352735
" d.node.dim_name: inds[d.observation_indexes]\n",
27362736
" for d in hierarchy.levels[hierarchy.depth_to_level[hierarchy.depth]]\n",
27372737
" }\n",
2738-
" return at.concatenate(\n",
2738+
" return pt.concatenate(\n",
27392739
" self.hierarchy.walk_hierarchy(\n",
27402740
" root_callback=self.root_callback,\n",
27412741
" intermediate_callback=self.intermediate_callback,\n",
@@ -2764,7 +2764,7 @@
27642764
" latent = pm.gp.Latent(cov_func=cov)\n",
27652765
" return pm.Deterministic(\n",
27662766
" f\"gp_{dim_name}\",\n",
2767-
" at.stack(\n",
2767+
" pt.stack(\n",
27682768
" [\n",
27692769
" parent_gp + latent.prior(f\"gp_{dim_name}_{i}\", X)\n",
27702770
" for i in hierarchy.coords[dim_name]\n",

0 commit comments

Comments
 (0)