From 0a38a36a44a017a442dd56f1fc2f7788d1602411 Mon Sep 17 00:00:00 2001 From: michaelcao28 Date: Sat, 6 Jul 2024 00:36:21 +1000 Subject: [PATCH 1/8] init commit --- CONTRIBUTING.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9fb4bee28..2c79f3137 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,45 @@ # Contributing guide +Thank you for your interest in contributing to PyMC and PyMC-experimental! + +This page outlines the steps to follow if you wish to contribute to the pymc-experimental repo and clone the repo locally. + +## Install locally +**1**: Create a folder `pymc-devs` in your local machine and follow the [cloning PyMC locally](https://www.pymc.io/projects/docs/en/latest/contributing/pr_tutorial.html). + +Since PyMC-experimental should integrate with the latest version of PyMC, it is recommended that any development work on PyMC-experimental must also work with the latest version of PyMC. + +You should now have a local copy of PyMC under `pymc-devs/pymc`. + +**2**: Fork the PyMC-experimental repo and clone it locally: + +``` +git clone git@github.com:/pymc-experimental.git +cd pymc-experimental +git remote add upstream git@github.com:pymc-devs/pymc-experimental.git +``` + +Create a new conda environment by first installing the dependencies in the main PyMC repo: +``` +conda env create -n pymc-experimental -f /path/to/pymc-devs/pymc/conda-envs/environment-dev.yml +conda activate pymc-experimental +pip install -e /path/to/pymc-devs/pymc + +# ignores the specific pymc version to install pymc-experimental +pip install -e /path/to/pymc-devs/pymc-experimental --no-deps --ignore-installed pymc +``` + +## Develop the feature + +**1** Develop the feature on your feature branch: +``` +git checkout -b my-exp-feature +``` + + + +You should now have a local copy of PyMC-experimental under `pymc-devs/pymc-experimental`. + +**Final steps**: Review contributing guide in [PyMC's main page](https://www.pymc.io/projects/docs/en/latest/contributing/index.html). + Page in construction, for now go to https://github.com/pymc-devs/pymc-experimental#questions. From d1e03473a62e9f9dbfb996252002da06620a19b1 Mon Sep 17 00:00:00 2001 From: michaelcao28 Date: Sat, 6 Jul 2024 01:17:00 +1000 Subject: [PATCH 2/8] contribution page --- CONTRIBUTING.md | 80 +++++++++++++++++++++++++++++++++++++++++++++---- a.out | 0 2 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 a.out diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2c79f3137..18e654d5b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ Thank you for your interest in contributing to PyMC and PyMC-experimental! This page outlines the steps to follow if you wish to contribute to the pymc-experimental repo and clone the repo locally. ## Install locally -**1**: Create a folder `pymc-devs` in your local machine and follow the [cloning PyMC locally](https://www.pymc.io/projects/docs/en/latest/contributing/pr_tutorial.html). +**1**: Create a folder `pymc-devs` in your local machine and follow the steps on [cloning PyMC locally](https://www.pymc.io/projects/docs/en/latest/contributing/pr_tutorial.html). Since PyMC-experimental should integrate with the latest version of PyMC, it is recommended that any development work on PyMC-experimental must also work with the latest version of PyMC. @@ -19,6 +19,8 @@ cd pymc-experimental git remote add upstream git@github.com:pymc-devs/pymc-experimental.git ``` +You should now have a local copy of PyMC-experimental under `pymc-devs/pymc-experimental`. + Create a new conda environment by first installing the dependencies in the main PyMC repo: ``` conda env create -n pymc-experimental -f /path/to/pymc-devs/pymc/conda-envs/environment-dev.yml @@ -26,20 +28,86 @@ conda activate pymc-experimental pip install -e /path/to/pymc-devs/pymc # ignores the specific pymc version to install pymc-experimental -pip install -e /path/to/pymc-devs/pymc-experimental --no-deps --ignore-installed pymc +pip install -e /path/to/pymc-devs/pymc-experimental --ignore-installed pymc +``` + +**3** Check origin and upstream is correct. + +**PyMC** +``` +cd /path/to/pymc-devs/pymc +git remote -v +``` +Output: +``` +origin git@github.com:/pymc.git (fetch) +origin git@github.com:/pymc.git (push) +upstream git@github.com:pymc-devs/pymc.git (fetch) +upstream git@github.com:pymc-devs/pymc.git (push) ``` -## Develop the feature +**PyMC-experimental** +``` +cd /path/to/pymc-devs/pymc-experimental +git remote -v +``` +Output: +``` +origin git@github.com:/pymc-experimental.git (fetch) +origin git@github.com:/pymc-experimental.git (push) +upstream git@github.com:pymc-devs/pymc-experimental.git (fetch) +upstream git@github.com:pymc-devs/pymc-experimental.git (push) +``` + + + +## Git integration [(from PyMC's main page)](https://www.pymc.io/projects/docs/en/latest/contributing/pr_tutorial.html) **1** Develop the feature on your feature branch: ``` git checkout -b my-exp-feature ``` +**2** Before committing, run pre-commit checks: +``` +pip install pre-commit +pre-commit run --all # 👈 to run it manually +pre-commit install # 👈 to run it automatically before each commit +``` + +**3** Add changed files using git add and then git commit files: +``` +git add modified_files +git commit +``` +to record your changes locally. +**4** After committing, it is a good idea to sync with the base repository in case there have been any changes: +``` +# pymc +cd /path/to/pymc-devs/pymc +git fetch upstream +git rebase upstream/main -You should now have a local copy of PyMC-experimental under `pymc-devs/pymc-experimental`. +# (pymc-dev team) Please double check this +pip install -e /path/to/pymc-devs/pymc + +# pymc-exp +cd /path/to/pymc-devs/pymc-experimental +git fetch upstream +git rebase upstream/main +``` +Then push the changes to the fork in your GitHub account with: +``` +git push -u origin my-exp-feature +``` + +**5** Go to the GitHub web page of your fork of the PyMC repo. Click the ‘Pull request’ button to send your changes to the project’s maintainers for review. This will send a notification to the committers. + +## Final steps + +Review contributing guide in [PyMC's main page](https://www.pymc.io/projects/docs/en/latest/contributing/index.html). -**Final steps**: Review contributing guide in [PyMC's main page](https://www.pymc.io/projects/docs/en/latest/contributing/index.html). +FAQ [page](https://github.com/pymc-devs/pymc-experimental#questions). -Page in construction, for now go to https://github.com/pymc-devs/pymc-experimental#questions. +Discussions [page](https://github.com/pymc-devs/pymc-experimental/discussions/5). diff --git a/a.out b/a.out new file mode 100644 index 000000000..e69de29bb From 3a5b822b8471604e9eb823e9c88ff0727ffb9aad Mon Sep 17 00:00:00 2001 From: Jesse Grabowski <48652735+jessegrabowski@users.noreply.github.com> Date: Fri, 19 Jul 2024 08:11:05 -0500 Subject: [PATCH 3/8] Move `tests/` to project root (#361) --- .github/workflows/test.yml | 5 +++-- codecov.yml | 2 +- {pymc_experimental/tests => tests}/__init__.py | 0 .../tests => tests}/distributions/__init__.py | 0 .../tests => tests}/distributions/test_continuous.py | 0 .../tests => tests}/distributions/test_discrete.py | 0 .../distributions/test_discrete_markov_chain.py | 0 .../tests => tests}/distributions/test_multivariate.py | 0 {pymc_experimental/tests => tests}/model/__init__.py | 0 .../tests => tests}/model/test_marginal_model.py | 2 +- .../tests => tests}/model/test_model_api.py | 0 .../tests => tests}/model/transforms/test_autoreparam.py | 0 .../tests => tests}/statespace/__init__.py | 0 .../tests => tests}/statespace/test_SARIMAX.py | 4 ++-- .../tests => tests}/statespace/test_VARMAX.py | 4 ++-- .../tests => tests}/statespace/test_coord_assignment.py | 4 +--- .../tests => tests}/statespace/test_data/airpass.csv | 0 .../statespace/test_data/airpassangers.csv | 0 .../tests => tests}/statespace/test_data/nile.csv | 0 .../test_data/statsmodels_macrodata_processed.csv | 0 .../tests => tests}/statespace/test_distributions.py | 4 ++-- .../tests => tests}/statespace/test_kalman_filter.py | 4 ++-- .../tests => tests}/statespace/test_representation.py | 7 ++----- .../tests => tests}/statespace/test_statespace.py | 4 ++-- .../tests => tests}/statespace/test_statespace_JAX.py | 9 +++------ .../tests => tests}/statespace/test_structural.py | 4 ++-- .../tests => tests}/statespace/utilities/__init__.py | 0 .../statespace/utilities/shared_fixtures.py | 0 .../statespace/utilities/statsmodel_local_level.py | 0 .../tests => tests}/statespace/utilities/test_helpers.py | 6 ++---- {pymc_experimental/tests => tests}/test_blackjax_smc.py | 0 .../tests => tests}/test_histogram_approximation.py | 0 {pymc_experimental/tests => tests}/test_laplace.py | 0 {pymc_experimental/tests => tests}/test_linearmodel.py | 0 {pymc_experimental/tests => tests}/test_model_builder.py | 0 {pymc_experimental/tests => tests}/test_pathfinder.py | 0 .../tests => tests}/test_pivoted_cholesky.py | 0 .../tests => tests}/test_prior_from_trace.py | 0 {pymc_experimental/tests => tests}/test_splines.py | 0 {pymc_experimental/tests => tests}/utils.py | 0 40 files changed, 25 insertions(+), 34 deletions(-) rename {pymc_experimental/tests => tests}/__init__.py (100%) rename {pymc_experimental/tests => tests}/distributions/__init__.py (100%) rename {pymc_experimental/tests => tests}/distributions/test_continuous.py (100%) rename {pymc_experimental/tests => tests}/distributions/test_discrete.py (100%) rename {pymc_experimental/tests => tests}/distributions/test_discrete_markov_chain.py (100%) rename {pymc_experimental/tests => tests}/distributions/test_multivariate.py (100%) rename {pymc_experimental/tests => tests}/model/__init__.py (100%) rename {pymc_experimental/tests => tests}/model/test_marginal_model.py (99%) rename {pymc_experimental/tests => tests}/model/test_model_api.py (100%) rename {pymc_experimental/tests => tests}/model/transforms/test_autoreparam.py (100%) rename {pymc_experimental/tests => tests}/statespace/__init__.py (100%) rename {pymc_experimental/tests => tests}/statespace/test_SARIMAX.py (98%) rename {pymc_experimental/tests => tests}/statespace/test_VARMAX.py (96%) rename {pymc_experimental/tests => tests}/statespace/test_coord_assignment.py (97%) rename {pymc_experimental/tests => tests}/statespace/test_data/airpass.csv (100%) rename {pymc_experimental/tests => tests}/statespace/test_data/airpassangers.csv (100%) rename {pymc_experimental/tests => tests}/statespace/test_data/nile.csv (100%) rename {pymc_experimental/tests => tests}/statespace/test_data/statsmodels_macrodata_processed.csv (100%) rename {pymc_experimental/tests => tests}/statespace/test_distributions.py (98%) rename {pymc_experimental/tests => tests}/statespace/test_kalman_filter.py (98%) rename {pymc_experimental/tests => tests}/statespace/test_representation.py (96%) rename {pymc_experimental/tests => tests}/statespace/test_statespace.py (98%) rename {pymc_experimental/tests => tests}/statespace/test_statespace_JAX.py (93%) rename {pymc_experimental/tests => tests}/statespace/test_structural.py (99%) rename {pymc_experimental/tests => tests}/statespace/utilities/__init__.py (100%) rename {pymc_experimental/tests => tests}/statespace/utilities/shared_fixtures.py (100%) rename {pymc_experimental/tests => tests}/statespace/utilities/statsmodel_local_level.py (100%) rename {pymc_experimental/tests => tests}/statespace/utilities/test_helpers.py (97%) rename {pymc_experimental/tests => tests}/test_blackjax_smc.py (100%) rename {pymc_experimental/tests => tests}/test_histogram_approximation.py (100%) rename {pymc_experimental/tests => tests}/test_laplace.py (100%) rename {pymc_experimental/tests => tests}/test_linearmodel.py (100%) rename {pymc_experimental/tests => tests}/test_model_builder.py (100%) rename {pymc_experimental/tests => tests}/test_pathfinder.py (100%) rename {pymc_experimental/tests => tests}/test_pivoted_cholesky.py (100%) rename {pymc_experimental/tests => tests}/test_prior_from_trace.py (100%) rename {pymc_experimental/tests => tests}/test_splines.py (100%) rename {pymc_experimental/tests => tests}/utils.py (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1379b99c2..37616dd38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,7 @@ on: paths: - ".github/workflows/*" - "pymc_experimental/**" + - "tests/**" - "setup.py" - "pyproject.toml" - "buildosx" @@ -20,7 +21,7 @@ jobs: os: [ubuntu-latest] python-version: ["3.10"] test-subset: - - pymc_experimental/tests + - tests fail-fast: false runs-on: ${{ matrix.os }} env: @@ -58,7 +59,7 @@ jobs: os: [windows-latest] python-version: ["3.12"] test-subset: - - pymc_experimental/tests + - tests fail-fast: false runs-on: ${{ matrix.os }} env: diff --git a/codecov.yml b/codecov.yml index 6e7041ca8..0a251b891 100644 --- a/codecov.yml +++ b/codecov.yml @@ -22,7 +22,7 @@ coverage: base: auto ignore: - - "pymc_experimental/tests/*" + - "tests/*" comment: layout: "reach, diff, flags, files" diff --git a/pymc_experimental/tests/__init__.py b/tests/__init__.py similarity index 100% rename from pymc_experimental/tests/__init__.py rename to tests/__init__.py diff --git a/pymc_experimental/tests/distributions/__init__.py b/tests/distributions/__init__.py similarity index 100% rename from pymc_experimental/tests/distributions/__init__.py rename to tests/distributions/__init__.py diff --git a/pymc_experimental/tests/distributions/test_continuous.py b/tests/distributions/test_continuous.py similarity index 100% rename from pymc_experimental/tests/distributions/test_continuous.py rename to tests/distributions/test_continuous.py diff --git a/pymc_experimental/tests/distributions/test_discrete.py b/tests/distributions/test_discrete.py similarity index 100% rename from pymc_experimental/tests/distributions/test_discrete.py rename to tests/distributions/test_discrete.py diff --git a/pymc_experimental/tests/distributions/test_discrete_markov_chain.py b/tests/distributions/test_discrete_markov_chain.py similarity index 100% rename from pymc_experimental/tests/distributions/test_discrete_markov_chain.py rename to tests/distributions/test_discrete_markov_chain.py diff --git a/pymc_experimental/tests/distributions/test_multivariate.py b/tests/distributions/test_multivariate.py similarity index 100% rename from pymc_experimental/tests/distributions/test_multivariate.py rename to tests/distributions/test_multivariate.py diff --git a/pymc_experimental/tests/model/__init__.py b/tests/model/__init__.py similarity index 100% rename from pymc_experimental/tests/model/__init__.py rename to tests/model/__init__.py diff --git a/pymc_experimental/tests/model/test_marginal_model.py b/tests/model/test_marginal_model.py similarity index 99% rename from pymc_experimental/tests/model/test_marginal_model.py rename to tests/model/test_marginal_model.py index 31e38615a..fd1ce259c 100644 --- a/pymc_experimental/tests/model/test_marginal_model.py +++ b/tests/model/test_marginal_model.py @@ -22,7 +22,7 @@ is_conditional_dependent, marginalize, ) -from pymc_experimental.tests.utils import equal_computations_up_to_root +from tests.utils import equal_computations_up_to_root @pytest.fixture diff --git a/pymc_experimental/tests/model/test_model_api.py b/tests/model/test_model_api.py similarity index 100% rename from pymc_experimental/tests/model/test_model_api.py rename to tests/model/test_model_api.py diff --git a/pymc_experimental/tests/model/transforms/test_autoreparam.py b/tests/model/transforms/test_autoreparam.py similarity index 100% rename from pymc_experimental/tests/model/transforms/test_autoreparam.py rename to tests/model/transforms/test_autoreparam.py diff --git a/pymc_experimental/tests/statespace/__init__.py b/tests/statespace/__init__.py similarity index 100% rename from pymc_experimental/tests/statespace/__init__.py rename to tests/statespace/__init__.py diff --git a/pymc_experimental/tests/statespace/test_SARIMAX.py b/tests/statespace/test_SARIMAX.py similarity index 98% rename from pymc_experimental/tests/statespace/test_SARIMAX.py rename to tests/statespace/test_SARIMAX.py index fc09a632b..fe9d8435e 100644 --- a/pymc_experimental/tests/statespace/test_SARIMAX.py +++ b/tests/statespace/test_SARIMAX.py @@ -17,10 +17,10 @@ SARIMAX_STATE_STRUCTURES, SHORT_NAME_TO_LONG, ) -from pymc_experimental.tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import +from tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import rng, ) -from pymc_experimental.tests.statespace.utilities.test_helpers import ( +from tests.statespace.utilities.test_helpers import ( load_nile_test_data, make_stationary_params, simulate_from_numpy_model, diff --git a/pymc_experimental/tests/statespace/test_VARMAX.py b/tests/statespace/test_VARMAX.py similarity index 96% rename from pymc_experimental/tests/statespace/test_VARMAX.py rename to tests/statespace/test_VARMAX.py index 2ca0b3635..43faebe8e 100644 --- a/pymc_experimental/tests/statespace/test_VARMAX.py +++ b/tests/statespace/test_VARMAX.py @@ -11,7 +11,7 @@ from pymc_experimental.statespace import BayesianVARMAX from pymc_experimental.statespace.utils.constants import SHORT_NAME_TO_LONG -from pymc_experimental.tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import +from tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import rng, ) @@ -25,7 +25,7 @@ @pytest.fixture(scope="session") def data(): df = pd.read_csv( - "pymc_experimental/tests/statespace/test_data/statsmodels_macrodata_processed.csv", + "tests/statespace/test_data/statsmodels_macrodata_processed.csv", index_col=0, parse_dates=True, ).astype(floatX) diff --git a/pymc_experimental/tests/statespace/test_coord_assignment.py b/tests/statespace/test_coord_assignment.py similarity index 97% rename from pymc_experimental/tests/statespace/test_coord_assignment.py rename to tests/statespace/test_coord_assignment.py index bed645600..58310c4e2 100644 --- a/pymc_experimental/tests/statespace/test_coord_assignment.py +++ b/tests/statespace/test_coord_assignment.py @@ -18,9 +18,7 @@ NO_FREQ_INFO_WARNING, NO_TIME_INDEX_WARNING, ) -from pymc_experimental.tests.statespace.utilities.test_helpers import ( - load_nile_test_data, -) +from tests.statespace.utilities.test_helpers import load_nile_test_data function_names = ["pandas_date_freq", "pandas_date_nofreq", "pandas_nodate", "numpy", "pytensor"] expected_warning = [ diff --git a/pymc_experimental/tests/statespace/test_data/airpass.csv b/tests/statespace/test_data/airpass.csv similarity index 100% rename from pymc_experimental/tests/statespace/test_data/airpass.csv rename to tests/statespace/test_data/airpass.csv diff --git a/pymc_experimental/tests/statespace/test_data/airpassangers.csv b/tests/statespace/test_data/airpassangers.csv similarity index 100% rename from pymc_experimental/tests/statespace/test_data/airpassangers.csv rename to tests/statespace/test_data/airpassangers.csv diff --git a/pymc_experimental/tests/statespace/test_data/nile.csv b/tests/statespace/test_data/nile.csv similarity index 100% rename from pymc_experimental/tests/statespace/test_data/nile.csv rename to tests/statespace/test_data/nile.csv diff --git a/pymc_experimental/tests/statespace/test_data/statsmodels_macrodata_processed.csv b/tests/statespace/test_data/statsmodels_macrodata_processed.csv similarity index 100% rename from pymc_experimental/tests/statespace/test_data/statsmodels_macrodata_processed.csv rename to tests/statespace/test_data/statsmodels_macrodata_processed.csv diff --git a/pymc_experimental/tests/statespace/test_distributions.py b/tests/statespace/test_distributions.py similarity index 98% rename from pymc_experimental/tests/statespace/test_distributions.py rename to tests/statespace/test_distributions.py index 1f441d417..1d049ae92 100644 --- a/pymc_experimental/tests/statespace/test_distributions.py +++ b/tests/statespace/test_distributions.py @@ -17,10 +17,10 @@ OBS_STATE_DIM, TIME_DIM, ) -from pymc_experimental.tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import +from tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import rng, ) -from pymc_experimental.tests.statespace.utilities.test_helpers import ( +from tests.statespace.utilities.test_helpers import ( delete_rvs_from_model, fast_eval, load_nile_test_data, diff --git a/pymc_experimental/tests/statespace/test_kalman_filter.py b/tests/statespace/test_kalman_filter.py similarity index 98% rename from pymc_experimental/tests/statespace/test_kalman_filter.py rename to tests/statespace/test_kalman_filter.py index d836c7961..15d1effa5 100644 --- a/pymc_experimental/tests/statespace/test_kalman_filter.py +++ b/tests/statespace/test_kalman_filter.py @@ -13,10 +13,10 @@ UnivariateFilter, ) from pymc_experimental.statespace.filters.kalman_filter import BaseFilter -from pymc_experimental.tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import +from tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import rng, ) -from pymc_experimental.tests.statespace.utilities.test_helpers import ( +from tests.statespace.utilities.test_helpers import ( get_expected_shape, get_sm_state_from_output_name, initialize_filter, diff --git a/pymc_experimental/tests/statespace/test_representation.py b/tests/statespace/test_representation.py similarity index 96% rename from pymc_experimental/tests/statespace/test_representation.py rename to tests/statespace/test_representation.py index f6cb06a36..10388d94d 100644 --- a/pymc_experimental/tests/statespace/test_representation.py +++ b/tests/statespace/test_representation.py @@ -6,11 +6,8 @@ from numpy.testing import assert_allclose from pymc_experimental.statespace.core.representation import PytensorRepresentation -from pymc_experimental.tests.statespace.utilities.shared_fixtures import TEST_SEED -from pymc_experimental.tests.statespace.utilities.test_helpers import ( - fast_eval, - make_test_inputs, -) +from tests.statespace.utilities.shared_fixtures import TEST_SEED +from tests.statespace.utilities.test_helpers import fast_eval, make_test_inputs floatX = pytensor.config.floatX atol = 1e-12 if floatX == "float64" else 1e-6 diff --git a/pymc_experimental/tests/statespace/test_statespace.py b/tests/statespace/test_statespace.py similarity index 98% rename from pymc_experimental/tests/statespace/test_statespace.py rename to tests/statespace/test_statespace.py index 3aa6b96dd..d93c66062 100644 --- a/pymc_experimental/tests/statespace/test_statespace.py +++ b/tests/statespace/test_statespace.py @@ -13,10 +13,10 @@ MATRIX_NAMES, SMOOTHER_OUTPUT_NAMES, ) -from pymc_experimental.tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import +from tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import rng, ) -from pymc_experimental.tests.statespace.utilities.test_helpers import ( +from tests.statespace.utilities.test_helpers import ( fast_eval, load_nile_test_data, make_test_inputs, diff --git a/pymc_experimental/tests/statespace/test_statespace_JAX.py b/tests/statespace/test_statespace_JAX.py similarity index 93% rename from pymc_experimental/tests/statespace/test_statespace_JAX.py rename to tests/statespace/test_statespace_JAX.py index 20dd3d6fb..d9a0c4f96 100644 --- a/pymc_experimental/tests/statespace/test_statespace_JAX.py +++ b/tests/statespace/test_statespace_JAX.py @@ -12,17 +12,14 @@ MATRIX_NAMES, SMOOTHER_OUTPUT_NAMES, ) -from pymc_experimental.tests.statespace.test_statespace import ( # pylint: disable=unused-import +from tests.statespace.test_statespace import ( # pylint: disable=unused-import exog_ss_mod, - make_statespace_mod, ss_mod, ) -from pymc_experimental.tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import +from tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import rng, ) -from pymc_experimental.tests.statespace.utilities.test_helpers import ( - load_nile_test_data, -) +from tests.statespace.utilities.test_helpers import load_nile_test_data pytest.importorskip("jax") pytest.importorskip("numpyro") diff --git a/pymc_experimental/tests/statespace/test_structural.py b/tests/statespace/test_structural.py similarity index 99% rename from pymc_experimental/tests/statespace/test_structural.py rename to tests/statespace/test_structural.py index 76d52790c..30a037811 100644 --- a/pymc_experimental/tests/statespace/test_structural.py +++ b/tests/statespace/test_structural.py @@ -24,10 +24,10 @@ SHOCK_DIM, SHORT_NAME_TO_LONG, ) -from pymc_experimental.tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import +from tests.statespace.utilities.shared_fixtures import ( # pylint: disable=unused-import rng, ) -from pymc_experimental.tests.statespace.utilities.test_helpers import ( +from tests.statespace.utilities.test_helpers import ( assert_pattern_repeats, simulate_from_numpy_model, unpack_symbolic_matrices_with_params, diff --git a/pymc_experimental/tests/statespace/utilities/__init__.py b/tests/statespace/utilities/__init__.py similarity index 100% rename from pymc_experimental/tests/statespace/utilities/__init__.py rename to tests/statespace/utilities/__init__.py diff --git a/pymc_experimental/tests/statespace/utilities/shared_fixtures.py b/tests/statespace/utilities/shared_fixtures.py similarity index 100% rename from pymc_experimental/tests/statespace/utilities/shared_fixtures.py rename to tests/statespace/utilities/shared_fixtures.py diff --git a/pymc_experimental/tests/statespace/utilities/statsmodel_local_level.py b/tests/statespace/utilities/statsmodel_local_level.py similarity index 100% rename from pymc_experimental/tests/statespace/utilities/statsmodel_local_level.py rename to tests/statespace/utilities/statsmodel_local_level.py diff --git a/pymc_experimental/tests/statespace/utilities/test_helpers.py b/tests/statespace/utilities/test_helpers.py similarity index 97% rename from pymc_experimental/tests/statespace/utilities/test_helpers.py rename to tests/statespace/utilities/test_helpers.py index 7b18b79b5..7f2183c14 100644 --- a/pymc_experimental/tests/statespace/utilities/test_helpers.py +++ b/tests/statespace/utilities/test_helpers.py @@ -11,9 +11,7 @@ MATRIX_NAMES, SHORT_NAME_TO_LONG, ) -from pymc_experimental.tests.statespace.utilities.statsmodel_local_level import ( - LocalLinearTrend, -) +from tests.statespace.utilities.statsmodel_local_level import LocalLinearTrend floatX = pytensor.config.floatX @@ -21,7 +19,7 @@ def load_nile_test_data(): from importlib.metadata import version - nile = pd.read_csv("pymc_experimental/tests/statespace/test_data/nile.csv", dtype={"x": floatX}) + nile = pd.read_csv("tests/statespace/test_data/nile.csv", dtype={"x": floatX}) major, minor, rev = map(int, version("pandas").split(".")) if major >= 2 and minor >= 2 and rev >= 0: freq_str = "YS-JAN" diff --git a/pymc_experimental/tests/test_blackjax_smc.py b/tests/test_blackjax_smc.py similarity index 100% rename from pymc_experimental/tests/test_blackjax_smc.py rename to tests/test_blackjax_smc.py diff --git a/pymc_experimental/tests/test_histogram_approximation.py b/tests/test_histogram_approximation.py similarity index 100% rename from pymc_experimental/tests/test_histogram_approximation.py rename to tests/test_histogram_approximation.py diff --git a/pymc_experimental/tests/test_laplace.py b/tests/test_laplace.py similarity index 100% rename from pymc_experimental/tests/test_laplace.py rename to tests/test_laplace.py diff --git a/pymc_experimental/tests/test_linearmodel.py b/tests/test_linearmodel.py similarity index 100% rename from pymc_experimental/tests/test_linearmodel.py rename to tests/test_linearmodel.py diff --git a/pymc_experimental/tests/test_model_builder.py b/tests/test_model_builder.py similarity index 100% rename from pymc_experimental/tests/test_model_builder.py rename to tests/test_model_builder.py diff --git a/pymc_experimental/tests/test_pathfinder.py b/tests/test_pathfinder.py similarity index 100% rename from pymc_experimental/tests/test_pathfinder.py rename to tests/test_pathfinder.py diff --git a/pymc_experimental/tests/test_pivoted_cholesky.py b/tests/test_pivoted_cholesky.py similarity index 100% rename from pymc_experimental/tests/test_pivoted_cholesky.py rename to tests/test_pivoted_cholesky.py diff --git a/pymc_experimental/tests/test_prior_from_trace.py b/tests/test_prior_from_trace.py similarity index 100% rename from pymc_experimental/tests/test_prior_from_trace.py rename to tests/test_prior_from_trace.py diff --git a/pymc_experimental/tests/test_splines.py b/tests/test_splines.py similarity index 100% rename from pymc_experimental/tests/test_splines.py rename to tests/test_splines.py diff --git a/pymc_experimental/tests/utils.py b/tests/utils.py similarity index 100% rename from pymc_experimental/tests/utils.py rename to tests/utils.py From 22d0d8b5ba6a567a0609dc04097fbc6aeb2005e2 Mon Sep 17 00:00:00 2001 From: Maxim Kochurov Date: Fri, 19 Jul 2024 21:22:22 +0300 Subject: [PATCH 4/8] Add Exponential distribution to model/transforms/autoreparam.py (#365) --- .../model/transforms/autoreparam.py | 38 ++++++++++++++++++ tests/model/transforms/test_autoreparam.py | 40 +++++++++++-------- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/pymc_experimental/model/transforms/autoreparam.py b/pymc_experimental/model/transforms/autoreparam.py index cc1f78289..bb3996459 100644 --- a/pymc_experimental/model/transforms/autoreparam.py +++ b/pymc_experimental/model/transforms/autoreparam.py @@ -246,6 +246,44 @@ def _( return vip_rep +@_vip_reparam_node.register +def _( + op: pm.Exponential, + node: Apply, + name: str, + dims: List[Variable], + transform: Optional[Transform], + lam: pt.TensorVariable, +) -> ModelDeterministic: + rng, size, scale = node.inputs + scale_centered = scale**lam + scale_noncentered = scale ** (1 - lam) + vip_rv_ = pm.Exponential.dist( + scale=scale_centered, + size=size, + rng=rng, + ) + vip_rv_value_ = vip_rv_.clone() + vip_rv_.name = f"{name}::tau_" + if transform is not None: + vip_rv_value_.name = f"{vip_rv_.name}_{transform.name}__" + else: + vip_rv_value_.name = vip_rv_.name + vip_rv = model_free_rv( + vip_rv_, + vip_rv_value_, + transform, + *dims, + ) + + vip_rep_ = scale_noncentered * vip_rv + + vip_rep_.name = name + + vip_rep = model_deterministic(vip_rep_, *dims) + return vip_rep + + def vip_reparametrize( model: pm.Model, var_names: Sequence[str], diff --git a/tests/model/transforms/test_autoreparam.py b/tests/model/transforms/test_autoreparam.py index b2ea245ae..1d2173066 100644 --- a/tests/model/transforms/test_autoreparam.py +++ b/tests/model/transforms/test_autoreparam.py @@ -11,6 +11,7 @@ def model_c(): m = pm.Normal("m") s = pm.LogNormal("s") pm.Normal("g", m, s, shape=5) + pm.Exponential("e", scale=s, shape=7) return mod @@ -20,31 +21,34 @@ def model_nc(): m = pm.Normal("m") s = pm.LogNormal("s") pm.Deterministic("g", pm.Normal("z", shape=5) * s + m) + pm.Deterministic("e", pm.Exponential("z_e", 1, shape=7) * s) return mod -def test_reparametrize_created(model_c: pm.Model): - model_reparam, vip = vip_reparametrize(model_c, ["g"]) - assert "g" in vip.get_lambda() - assert "g::lam_logit__" in model_reparam.named_vars - assert "g::tau_" in model_reparam.named_vars +@pytest.mark.parametrize("var", ["g", "e"]) +def test_reparametrize_created(model_c: pm.Model, var): + model_reparam, vip = vip_reparametrize(model_c, [var]) + assert f"{var}" in vip.get_lambda() + assert f"{var}::lam_logit__" in model_reparam.named_vars + assert f"{var}::tau_" in model_reparam.named_vars vip.set_all_lambda(1) - assert ~np.isfinite(model_reparam["g::lam_logit__"].get_value()).any() + assert ~np.isfinite(model_reparam[f"{var}::lam_logit__"].get_value()).any() -def test_random_draw(model_c: pm.Model, model_nc): +@pytest.mark.parametrize("var", ["g", "e"]) +def test_random_draw(model_c: pm.Model, model_nc, var): model_c = pm.do(model_c, {"m": 3, "s": 2}) model_nc = pm.do(model_nc, {"m": 3, "s": 2}) - model_v, vip = vip_reparametrize(model_c, ["g"]) - assert "g" in [v.name for v in model_v.deterministics] - c = pm.draw(model_c["g"], random_seed=42, draws=1000) - nc = pm.draw(model_nc["g"], random_seed=42, draws=1000) + model_v, vip = vip_reparametrize(model_c, [var]) + assert var in [v.name for v in model_v.deterministics] + c = pm.draw(model_c[var], random_seed=42, draws=1000) + nc = pm.draw(model_nc[var], random_seed=42, draws=1000) vip.set_all_lambda(1) - v_1 = pm.draw(model_v["g"], random_seed=42, draws=1000) + v_1 = pm.draw(model_v[var], random_seed=42, draws=1000) vip.set_all_lambda(0) - v_0 = pm.draw(model_v["g"], random_seed=42, draws=1000) + v_0 = pm.draw(model_v[var], random_seed=42, draws=1000) vip.set_all_lambda(0.5) - v_05 = pm.draw(model_v["g"], random_seed=42, draws=1000) + v_05 = pm.draw(model_v[var], random_seed=42, draws=1000) np.testing.assert_allclose(c.mean(), nc.mean()) np.testing.assert_allclose(c.mean(), v_0.mean()) np.testing.assert_allclose(v_05.mean(), v_1.mean()) @@ -57,10 +61,12 @@ def test_random_draw(model_c: pm.Model, model_nc): def test_reparam_fit(model_c): - model_v, vip = vip_reparametrize(model_c, ["g"]) + vars = ["g", "e"] + model_v, vip = vip_reparametrize(model_c, ["g", "e"]) with model_v: - vip.fit(random_seed=42) - np.testing.assert_allclose(vip.get_lambda()["g"], 0, atol=0.01) + vip.fit(50000, random_seed=42) + for var in vars: + np.testing.assert_allclose(vip.get_lambda()[var], 0, atol=0.01) def test_multilevel(): From a547cc2a50bea98671f8ffd7d99f7d724b907a03 Mon Sep 17 00:00:00 2001 From: michaelcao28 <47520436+michaelcao28@users.noreply.github.com> Date: Fri, 26 Jul 2024 02:02:07 +1000 Subject: [PATCH 5/8] commit --- pymc_experimental/inference/pathfinder.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pymc_experimental/inference/pathfinder.py b/pymc_experimental/inference/pathfinder.py index 5e5533dd6..b211c1d25 100644 --- a/pymc_experimental/inference/pathfinder.py +++ b/pymc_experimental/inference/pathfinder.py @@ -99,7 +99,7 @@ def fit_pathfinder( model = modelcontext(model) - ip = model.initial_point() + ip = model.initial_point() # DEV: testing ip_map = DictToArrayBijection.map(ip) new_logprob, new_input = pm.pytensorf.join_nonshared_inputs( @@ -107,8 +107,10 @@ def fit_pathfinder( ) logprob_fn_list = get_jaxified_graph([new_input], new_logprob) + # DEV: testing def logprob_fn(x): + # DEV: testing return logprob_fn_list(x)[0] [pathfinder_seed, sample_seed] = _get_seeds_per_chain(random_seed, 2) From 6be85770f4c4bfba655ee2023d91f9fe576f3c04 Mon Sep 17 00:00:00 2001 From: michaelcao28 <47520436+michaelcao28@users.noreply.github.com> Date: Fri, 26 Jul 2024 02:18:38 +1000 Subject: [PATCH 6/8] commit test --- pymc_experimental/inference/pathfinder.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pymc_experimental/inference/pathfinder.py b/pymc_experimental/inference/pathfinder.py index b211c1d25..5e5533dd6 100644 --- a/pymc_experimental/inference/pathfinder.py +++ b/pymc_experimental/inference/pathfinder.py @@ -99,7 +99,7 @@ def fit_pathfinder( model = modelcontext(model) - ip = model.initial_point() # DEV: testing + ip = model.initial_point() ip_map = DictToArrayBijection.map(ip) new_logprob, new_input = pm.pytensorf.join_nonshared_inputs( @@ -107,10 +107,8 @@ def fit_pathfinder( ) logprob_fn_list = get_jaxified_graph([new_input], new_logprob) - # DEV: testing def logprob_fn(x): - # DEV: testing return logprob_fn_list(x)[0] [pathfinder_seed, sample_seed] = _get_seeds_per_chain(random_seed, 2) From 5c3b2952607717f32f245af84177d524b282bdf9 Mon Sep 17 00:00:00 2001 From: michaelcao28 <47520436+michaelcao28@users.noreply.github.com> Date: Fri, 26 Jul 2024 02:26:38 +1000 Subject: [PATCH 7/8] commit --- pymc_experimental/inference/pathfinder.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pymc_experimental/inference/pathfinder.py b/pymc_experimental/inference/pathfinder.py index 5e5533dd6..135610fa0 100644 --- a/pymc_experimental/inference/pathfinder.py +++ b/pymc_experimental/inference/pathfinder.py @@ -95,15 +95,18 @@ def fit_pathfinder( """ # Temporarily helper if version.parse(blackjax.__version__).major < 1: + # test raise ImportError("fit_pathfinder requires blackjax 1.0 or above") - model = modelcontext(model) - ip = model.initial_point() + ip = model.initial_point() ip_map = DictToArrayBijection.map(ip) new_logprob, new_input = pm.pytensorf.join_nonshared_inputs( - ip, (model.logp(),), model.value_vars, () + ip, + (model.logp(),), + model.value_vars, + (), ) logprob_fn_list = get_jaxified_graph([new_input], new_logprob) From c7b5f12511f9aa7fd6744afdee187b0c0e3fbe13 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:27:25 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pymc_experimental/inference/pathfinder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc_experimental/inference/pathfinder.py b/pymc_experimental/inference/pathfinder.py index 135610fa0..e13a55ebf 100644 --- a/pymc_experimental/inference/pathfinder.py +++ b/pymc_experimental/inference/pathfinder.py @@ -99,7 +99,7 @@ def fit_pathfinder( raise ImportError("fit_pathfinder requires blackjax 1.0 or above") model = modelcontext(model) - ip = model.initial_point() + ip = model.initial_point() ip_map = DictToArrayBijection.map(ip) new_logprob, new_input = pm.pytensorf.join_nonshared_inputs(