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

Bump PyTensor dependency and support Python 3.12 #7203

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
matrix:
os: [ubuntu-20.04]
floatx: [float64]
python-version: ["3.11"]
python-version: ["3.12"]
test-subset:
- |
tests/test_util.py
Expand Down Expand Up @@ -263,7 +263,7 @@ jobs:
matrix:
os: [macos-latest]
floatx: [float64]
python-version: ["3.10"]
python-version: ["3.12"]
test-subset:
- |
tests/sampling/test_parallel.py
Expand Down Expand Up @@ -342,7 +342,7 @@ jobs:
matrix:
os: [ubuntu-20.04]
floatx: [float64]
python-version: ["3.11"]
python-version: ["3.12"]
test-subset:
- tests/sampling/test_jax.py tests/sampling/test_mcmc_external.py
fail-fast: false
Expand Down Expand Up @@ -410,7 +410,7 @@ jobs:
matrix:
os: [windows-latest]
floatx: [float32]
python-version: ["3.11"]
python-version: ["3.12"]
test-subset:
- tests/sampling/test_mcmc.py tests/ode/test_ode.py tests/ode/test_utils.py tests/distributions/test_transform.py
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion conda-envs/environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
- numpy>=1.15.0
- pandas>=0.24.0
- pip
- pytensor>=2.18.1,<2.19
- pytensor>=2.19,<2.20
- python-graphviz
- networkx
- scipy>=1.4.1
Expand Down
2 changes: 1 addition & 1 deletion conda-envs/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
- numpy>=1.15.0
- pandas>=0.24.0
- pip
- pytensor>=2.18.1,<2.19
- pytensor>=2.19,<2.20
- python-graphviz
- scipy>=1.4.1
- typing-extensions>=3.7.4
Expand Down
6 changes: 3 additions & 3 deletions conda-envs/environment-jax.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ dependencies:
- h5py>=2.7
# Jaxlib version must not be greater than jax version!
- blackjax>=1.0.0
- jaxlib==0.4.14
- jax==0.4.16
- jaxlib==0.4.23
- jax==0.4.23
- libblas=*=*mkl
- mkl-service
- numpy>=1.15.0
- numpyro>=0.8.0
- pandas>=0.24.0
- pip
- pytensor>=2.18.1,<2.19
- pytensor>=2.19,<2.20
- python-graphviz
- networkx
- scipy>=1.4.1
Expand Down
2 changes: 1 addition & 1 deletion conda-envs/environment-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
- numpy>=1.15.0
- pandas>=0.24.0
- pip
- pytensor>=2.18.1,<2.19
- pytensor>=2.19,<2.20
- python-graphviz
- networkx
- scipy>=1.4.1
Expand Down
2 changes: 1 addition & 1 deletion conda-envs/windows-environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
- numpy>=1.15.0
- pandas>=0.24.0
- pip
- pytensor>=2.18.1,<2.19
- pytensor>=2.19,<2.20
- python-graphviz
- networkx
- scipy>=1.4.1
Expand Down
2 changes: 1 addition & 1 deletion conda-envs/windows-environment-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
- numpy>=1.15.0
- pandas>=0.24.0
- pip
- pytensor>=2.18.1,<2.19
- pytensor>=2.19,<2.20
- python-graphviz
- networkx
- scipy>=1.4.1
Expand Down
2 changes: 1 addition & 1 deletion pymc/sampling/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def shared_value_matches(var):
# Walk the graph from inputs to outputs and tag the volatile variables
nodes: list[Variable] = general_toposort(
fg.outputs, deps=lambda x: x.owner.inputs if x.owner else []
)
) # type: ignore
volatile_nodes: set[Any] = set()
for node in nodes:
if (
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ numpydoc
pandas>=0.24.0
polyagamma
pre-commit>=2.8.0
pytensor>=2.18.1,<2.19
pytensor>=2.19,<2.20
pytest-cov>=2.5
pytest>=3.0
scipy>=1.4.1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ cloudpickle
fastprogress>=0.2.0
numpy>=1.15.0
pandas>=0.24.0
pytensor>=2.18.1,<2.19
pytensor>=2.19,<2.20
scipy>=1.4.1
typing-extensions>=3.7.4
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
Expand Down
12 changes: 10 additions & 2 deletions tests/backends/test_arviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
from pymc.exceptions import ImputationWarning

# Turn all warnings into errors for this module
Copy link
Contributor

@maresb maresb Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion was to also inline this. (Turn all warnings into errors for this module)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now I'm getting to the nittiest of nits. :)

Copy link
Member Author

@ricardoV94 ricardoV94 Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's why the filterwarnings is there in the first place? Without the temporary filters it looks like

# Turn all warnings ...
pytest.mark.filterwarnings("error")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I misunderstand how filterwarnings works? The arguments get stacked, right?

pytestmark = pytest.mark.filterwarnings(
    # Turn all warnings into errors for this module
    "error",
    # except those related to https://github.com/arviz-devs/arviz/issues/2327
    "ignore:datetime.datetime.utcnow():DeprecationWarning",
)

Copy link
Member Author

@ricardoV94 ricardoV94 Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that, without the temporary ignores, it makes more sense to have the comment above the call. That also explains why the call is there in the first place.

# Turn all warnings ...
pytest.mark.filterwarnings("error")

Makes more sense than

pytest.mark.filterwarnings(
  # Turn all warnings ...
  "error",
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna take the nitpick hint and merge as is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytestmark = pytest.mark.filterwarnings("error")
pytestmark = pytest.mark.filterwarnings(
"error",
# Related to https://github.com/arviz-devs/arviz/issues/2327
"ignore:datetime.datetime.utcnow():DeprecationWarning",
)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -672,13 +676,17 @@ def test_include_transformed(self):
)
assert "p_interval__" in inference_data.posterior

@pytest.mark.filterwarnings(
"error",
# Related to https://github.com/arviz-devs/arviz/issues/2327
"ignore:datetime.datetime.utcnow():DeprecationWarning",
)
@pytest.mark.parametrize("chains", (1, 2))
def test_single_chain(self, chains):
# Test that no UserWarning is raised when sampling with NUTS defaults

# When this test was added, a `UserWarning: More chains (500) than draws (1)` used to be issued
# when sampling with a single chain
warnings.simplefilter("error")
with pm.Model():
pm.Normal("x")
pm.sample(chains=chains, return_inferencedata=True)
Expand Down
7 changes: 5 additions & 2 deletions tests/distributions/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@
from pymc.testing import assert_support_point_is_expected, select_by_precision

# Turn all warnings into errors for this module
# Ignoring NumPy deprecation warning tracked in https://github.com/pymc-devs/pytensor/issues/146
pytestmark = pytest.mark.filterwarnings("error", "ignore: NumPy will stop allowing conversion")
pytestmark = pytest.mark.filterwarnings(
"error",
# Related to https://github.com/arviz-devs/arviz/issues/2327
"ignore:datetime.datetime.utcnow():DeprecationWarning",
)


class TestRandomWalk:
Expand Down
2 changes: 1 addition & 1 deletion tests/sampling/test_mcmc_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_external_nuts_sampler(recwarn, nuts_sampler):
warns = {
(warn.category, warn.message.args[0])
for warn in recwarn
if warn.category is not FutureWarning
if warn.category not in (FutureWarning, DeprecationWarning)
}
expected = set()
if nuts_sampler == "nutpie":
Expand Down
22 changes: 17 additions & 5 deletions tests/variational/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ def test_fit_oo(inference, fit_kwargs, simple_model_data):
warn_ctxt = nullcontext()

with warn_ctxt:
trace = inference.fit(**fit_kwargs).sample(10000)
with warnings.catch_warnings():
# Related to https://github.com/arviz-devs/arviz/issues/2327
warnings.filterwarnings(
"ignore", message="datetime.datetime.utcnow()", category=DeprecationWarning
)

trace = inference.fit(**fit_kwargs).sample(10000)
mu_post = simple_model_data["mu_post"]
d = simple_model_data["d"]
np.testing.assert_allclose(np.mean(trace.posterior["mu"]), mu_post, rtol=0.05)
Expand Down Expand Up @@ -207,10 +213,16 @@ def test_fit_start(inference_spec, simple_model):
expected_warning = observed_value.name.startswith("minibatch")
with warnings.catch_warnings(record=True) as record:
warnings.simplefilter("always")
try:
trace = inference.fit(n=0).sample(10000)
except NotImplementedInference as e:
pytest.skip(str(e))
with warnings.catch_warnings():
# Related to https://github.com/arviz-devs/arviz/issues/2327
warnings.filterwarnings(
"ignore", message="datetime.datetime.utcnow()", category=DeprecationWarning
)

try:
trace = inference.fit(n=0).sample(10000)
except NotImplementedInference as e:
pytest.skip(str(e))

if expected_warning:
assert len(record) > 0
Expand Down
Loading