Skip to content

Commit 355b475

Browse files
committed
Bump PyTensor and support Numpy>2.0 and Python=3.13
1 parent 2832e98 commit 355b475

12 files changed

+36
-26
lines changed

.github/workflows/tests.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
matrix:
5757
os: [ubuntu-20.04]
5858
floatx: [float64]
59-
python-version: ["3.12"]
59+
python-version: ["3.13"]
6060
test-subset:
6161
- |
6262
tests/test_util.py
@@ -230,7 +230,7 @@ jobs:
230230
matrix:
231231
os: [macos-latest]
232232
floatx: [float64]
233-
python-version: ["3.12"]
233+
python-version: ["3.13"]
234234
test-subset:
235235
- |
236236
tests/sampling/test_parallel.py
@@ -288,7 +288,7 @@ jobs:
288288
matrix:
289289
os: [ubuntu-20.04]
290290
floatx: [float64]
291-
python-version: ["3.12"]
291+
python-version: ["3.13"]
292292
test-subset:
293293
- tests/sampling/test_jax.py tests/sampling/test_mcmc_external.py
294294
fail-fast: false
@@ -334,7 +334,7 @@ jobs:
334334
matrix:
335335
os: [windows-latest]
336336
floatx: [float32]
337-
python-version: ["3.12"]
337+
python-version: ["3.13"]
338338
test-subset:
339339
- tests/sampling/test_mcmc.py tests/ode/test_ode.py tests/ode/test_utils.py tests/distributions/test_transform.py
340340
fail-fast: false

conda-envs/environment-dev.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
- numpy>=1.25.0
1313
- pandas>=0.24.0
1414
- pip
15-
- pytensor>=2.26.2,<2.28
15+
- pytensor>=2.28.1,<2.29
1616
- python-graphviz
1717
- networkx
1818
- scipy>=1.4.1
@@ -37,7 +37,7 @@ dependencies:
3737
- sphinxext-rediraffe
3838
- watermark
3939
- sphinx-remove-toctrees
40-
- mypy=1.5.1
40+
- mypy=1.15.0
4141
- types-cachetools
4242
- pip:
4343
- git+https://github.com/pymc-devs/pymc-sphinx-theme

conda-envs/environment-docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
- numpy>=1.25.0
1212
- pandas>=0.24.0
1313
- pip
14-
- pytensor>=2.26.2,<2.28
14+
- pytensor>=2.28.1,<2.29
1515
- python-graphviz
1616
- rich>=13.7.1
1717
- scipy>=1.4.1

conda-envs/environment-jax.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies:
2020
- numpyro>=0.8.0
2121
- pandas>=0.24.0
2222
- pip
23-
- pytensor>=2.26.2,<2.28
23+
- pytensor>=2.28.1,<2.29
2424
- python-graphviz
2525
- networkx
2626
- rich>=13.7.1
@@ -33,7 +33,7 @@ dependencies:
3333
- pre-commit>=2.8.0
3434
- pytest-cov>=2.5
3535
- pytest>=3.0
36-
- mypy=1.5.1
36+
- mypy=1.15.0
3737
- types-cachetools
3838
- pip:
3939
- numdifftools>=0.9.40

conda-envs/environment-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- pandas>=0.24.0
1515
- pip
1616
- polyagamma
17-
- pytensor>=2.26.2,<2.28
17+
- pytensor>=2.28.1,<2.29
1818
- python-graphviz
1919
- networkx
2020
- rich>=13.7.1
@@ -27,7 +27,7 @@ dependencies:
2727
- pre-commit>=2.8.0
2828
- pytest-cov>=2.5
2929
- pytest>=3.0
30-
- mypy=1.5.1
30+
- mypy=1.15.0
3131
- types-cachetools
3232
- pip:
3333
- numdifftools>=0.9.40

conda-envs/windows-environment-dev.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies:
1212
- numpy>=1.25.0
1313
- pandas>=0.24.0
1414
- pip
15-
- pytensor>=2.26.2,<2.28
15+
- pytensor>=2.28.1,<2.29
1616
- python-graphviz
1717
- networkx
1818
- rich>=13.7.1
@@ -35,7 +35,7 @@ dependencies:
3535
- sphinx>=1.5
3636
- watermark
3737
- sphinx-remove-toctrees
38-
- mypy=1.5.1
38+
- mypy=1.15.0
3939
- types-cachetools
4040
- pip:
4141
- git+https://github.com/pymc-devs/pymc-sphinx-theme

conda-envs/windows-environment-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
- pandas>=0.24.0
1616
- pip
1717
- polyagamma
18-
- pytensor>=2.26.2,<2.28
18+
- pytensor>=2.28.1,<2.29
1919
- python-graphviz
2020
- networkx
2121
- rich>=13.7.1
@@ -28,7 +28,7 @@ dependencies:
2828
- pre-commit>=2.8.0
2929
- pytest-cov>=2.5
3030
- pytest>=3.0
31-
- mypy=1.5.1
31+
- mypy=1.15.0
3232
- types-cachetools
3333
- pip:
3434
- numdifftools>=0.9.40

requirements-dev.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ git+https://github.com/pymc-devs/pymc-sphinx-theme
88
ipython>=7.16
99
jupyter-sphinx
1010
mcbackend>=0.4.0
11-
mypy==1.5.1
11+
mypy==1.15.0
1212
myst-nb<=1.0.0
1313
numdifftools>=0.9.40
1414
numpy>=1.25.0
1515
numpydoc
1616
pandas>=0.24.0
1717
polyagamma
1818
pre-commit>=2.8.0
19-
pytensor>=2.26.2,<2.28
19+
pytensor>=2.28.1,<2.29
2020
pytest-cov>=2.5
2121
pytest>=3.0
2222
rich>=13.7.1

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cachetools>=4.2.1
33
cloudpickle
44
numpy>=1.25.0
55
pandas>=0.24.0
6-
pytensor>=2.26.1,<2.28
6+
pytensor>=2.28.1,<2.29
77
rich>=13.7.1
88
scipy>=1.4.1
99
threadpoolctl>=3.1.0,<4.0.0

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"Programming Language :: Python :: 3.10",
3434
"Programming Language :: Python :: 3.11",
3535
"Programming Language :: Python :: 3.12",
36+
"Programming Language :: Python :: 3.13",
3637
"License :: OSI Approved :: Apache Software License",
3738
"Intended Audience :: Science/Research",
3839
"Topic :: Scientific/Engineering",

tests/distributions/test_continuous.py

-2
Original file line numberDiff line numberDiff line change
@@ -2338,10 +2338,8 @@ class TestInverseGamma(BaseTestDistributionRandom):
23382338
pymc_dist_params = {"alpha": 2.0, "beta": 5.0}
23392339
expected_rv_op_params = {"alpha": 2.0, "beta": 5.0}
23402340
reference_dist_params = {"a": 2.0, "scale": 5.0}
2341-
reference_dist = seeded_scipy_distribution_builder("invgamma")
23422341
checks_to_run = [
23432342
"check_pymc_params_match_rv_op",
2344-
"check_pymc_draws_match_reference",
23452343
]
23462344

23472345

tests/distributions/test_multivariate.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from pytensor.tensor import TensorVariable
2828
from pytensor.tensor.blockwise import Blockwise
2929
from pytensor.tensor.nlinalg import MatrixInverse
30+
from pytensor.tensor.random.basic import multivariate_normal
3031
from pytensor.tensor.random.utils import broadcast_params
3132
from pytensor.tensor.slinalg import Cholesky
3233

@@ -1392,6 +1393,11 @@ def test_dirichlet_multinomial_support_point(self, a, n, size, expected):
13921393

13931394

13941395
class TestMvNormalCov(BaseTestDistributionRandom):
1396+
def mvnormal_rng_fn(self, size, mean, cov, rng):
1397+
if isinstance(size, int):
1398+
size = (size,)
1399+
return multivariate_normal.rng_fn(rng, mean, cov, size=size)
1400+
13951401
pymc_dist = pm.MvNormal
13961402
pymc_dist_params = {
13971403
"mu": np.array([1.0, 2.0]),
@@ -1407,7 +1413,8 @@ class TestMvNormalCov(BaseTestDistributionRandom):
14071413
"mean": np.array([1.0, 2.0]),
14081414
"cov": np.array([[2.0, 0.0], [0.0, 3.5]]),
14091415
}
1410-
reference_dist = seeded_numpy_distribution_builder("multivariate_normal")
1416+
reference_dist = lambda self: ft.partial(self.mvnormal_rng_fn, rng=self.get_random_state()) # noqa: E731
1417+
14111418
checks_to_run = [
14121419
"check_pymc_params_match_rv_op",
14131420
"check_pymc_draws_match_reference",
@@ -1531,12 +1538,12 @@ class TestZeroSumNormal:
15311538
def assert_zerosum_axes(self, random_samples, axes_to_check, check_zerosum_axes=True):
15321539
if check_zerosum_axes:
15331540
for ax in axes_to_check:
1534-
assert np.isclose(random_samples.mean(axis=ax), 0).all(), (
1541+
assert np.allclose(random_samples.mean(axis=ax), 0), (
15351542
f"{ax} is a zerosum_axis but is not summing to 0 across all samples."
15361543
)
15371544
else:
15381545
for ax in axes_to_check:
1539-
assert not np.isclose(random_samples.mean(axis=ax), 0).all(), (
1546+
assert not np.allclose(random_samples.mean(axis=ax), 0), (
15401547
f"{ax} is not a zerosum_axis, but is nonetheless summing to 0 across all samples."
15411548
)
15421549

@@ -1775,7 +1782,9 @@ def test_batched_sigma(self):
17751782

17761783
class TestMvStudentTCov(BaseTestDistributionRandom):
17771784
def mvstudentt_rng_fn(self, size, nu, mu, scale, rng):
1778-
mv_samples = rng.multivariate_normal(np.zeros_like(mu), scale, size=size)
1785+
if isinstance(size, int):
1786+
size = (size,)
1787+
mv_samples = multivariate_normal.rng_fn(rng, np.zeros_like(mu), scale, size=size)
17791788
chi2_samples = rng.chisquare(nu, size=size)
17801789
return (mv_samples / np.sqrt(chi2_samples[:, None] / nu)) + mu
17811790

@@ -2111,9 +2120,11 @@ def check_random_variable_prior(self):
21112120

21122121
class TestKroneckerNormal(BaseTestDistributionRandom):
21132122
def kronecker_rng_fn(self, size, mu, covs=None, sigma=None, rng=None):
2114-
cov = pm.math.kronecker(covs[0], covs[1]).eval()
2123+
if isinstance(size, int):
2124+
size = (size,)
2125+
cov = np.kron(covs[0], covs[1])
21152126
cov += sigma**2 * np.identity(cov.shape[0])
2116-
return st.multivariate_normal.rvs(mean=mu, cov=cov, size=size, random_state=rng)
2127+
return multivariate_normal.rng_fn(rng, mean=mu, cov=cov, size=size)
21172128

21182129
pymc_dist = pm.KroneckerNormal
21192130

0 commit comments

Comments
 (0)