From 23905b1a0b80195ef97154c56d6f3abe04a360d8 Mon Sep 17 00:00:00 2001 From: Ricardo Vieira Date: Sun, 27 Jul 2025 14:36:50 +0200 Subject: [PATCH] Bump PyTensor dependency --- conda-envs/environment-alternative-backends.yml | 2 +- conda-envs/environment-dev.yml | 2 +- conda-envs/environment-docs.yml | 2 +- conda-envs/environment-test.yml | 2 +- conda-envs/windows-environment-dev.yml | 2 +- conda-envs/windows-environment-test.yml | 2 +- pymc/distributions/continuous.py | 2 +- pymc/logprob/linalg.py | 4 ++-- pymc/ode/utils.py | 2 +- requirements-dev.txt | 2 +- requirements.txt | 2 +- tests/distributions/test_dist_math.py | 2 +- tests/distributions/test_distribution.py | 2 +- tests/logprob/test_transforms.py | 6 +++--- tests/ode/test_ode.py | 4 +++- tests/test_printing.py | 8 ++++---- 16 files changed, 24 insertions(+), 22 deletions(-) diff --git a/conda-envs/environment-alternative-backends.yml b/conda-envs/environment-alternative-backends.yml index d2cfd439a..d890791c8 100644 --- a/conda-envs/environment-alternative-backends.yml +++ b/conda-envs/environment-alternative-backends.yml @@ -22,7 +22,7 @@ dependencies: - numpyro>=0.8.0 - pandas>=0.24.0 - pip -- pytensor>=2.31.7,<2.32 +- pytensor>=2.32.0,<2.33 - python-graphviz - networkx - rich>=13.7.1 diff --git a/conda-envs/environment-dev.yml b/conda-envs/environment-dev.yml index a1545e60d..b6a9c52b9 100644 --- a/conda-envs/environment-dev.yml +++ b/conda-envs/environment-dev.yml @@ -12,7 +12,7 @@ dependencies: - numpy>=1.25.0 - pandas>=0.24.0 - pip -- pytensor>=2.31.7,<2.32 +- pytensor>=2.32.0,<2.33 - python-graphviz - networkx - scipy>=1.4.1 diff --git a/conda-envs/environment-docs.yml b/conda-envs/environment-docs.yml index fc0541f46..1fbddb548 100644 --- a/conda-envs/environment-docs.yml +++ b/conda-envs/environment-docs.yml @@ -11,7 +11,7 @@ dependencies: - numpy>=1.25.0 - pandas>=0.24.0 - pip -- pytensor>=2.31.7,<2.32 +- pytensor>=2.32.0,<2.33 - python-graphviz - rich>=13.7.1 - scipy>=1.4.1 diff --git a/conda-envs/environment-test.yml b/conda-envs/environment-test.yml index d2978f581..becb58339 100644 --- a/conda-envs/environment-test.yml +++ b/conda-envs/environment-test.yml @@ -14,7 +14,7 @@ dependencies: - pandas>=0.24.0 - pip - polyagamma -- pytensor>=2.31.7,<2.32 +- pytensor>=2.32.0,<2.33 - python-graphviz - networkx - rich>=13.7.1 diff --git a/conda-envs/windows-environment-dev.yml b/conda-envs/windows-environment-dev.yml index 58547c4d4..3dd404db7 100644 --- a/conda-envs/windows-environment-dev.yml +++ b/conda-envs/windows-environment-dev.yml @@ -12,7 +12,7 @@ dependencies: - numpy>=1.25.0 - pandas>=0.24.0 - pip -- pytensor>=2.31.7,<2.32 +- pytensor>=2.32.0,<2.33 - python-graphviz - networkx - rich>=13.7.1 diff --git a/conda-envs/windows-environment-test.yml b/conda-envs/windows-environment-test.yml index b9a1a36a9..f92108882 100644 --- a/conda-envs/windows-environment-test.yml +++ b/conda-envs/windows-environment-test.yml @@ -15,7 +15,7 @@ dependencies: - pandas>=0.24.0 - pip - polyagamma -- pytensor>=2.31.7,<2.32 +- pytensor>=2.32.0,<2.33 - python-graphviz - networkx - rich>=13.7.1 diff --git a/pymc/distributions/continuous.py b/pymc/distributions/continuous.py index 1ccc8c06a..dc98ed314 100644 --- a/pymc/distributions/continuous.py +++ b/pymc/distributions/continuous.py @@ -1618,7 +1618,7 @@ def support_point(rv, size, b, kappa, mu): def logp(value, b, kappa, mu): value = value - mu - res = pt.log(b / (kappa + (kappa**-1))) + ( + res = pt.log(b / (kappa + pt.reciprocal(kappa))) + ( -value * b * pt.sign(value) * (kappa ** pt.sign(value)) ) diff --git a/pymc/logprob/linalg.py b/pymc/logprob/linalg.py index bd5ac3326..9ee4399d5 100644 --- a/pymc/logprob/linalg.py +++ b/pymc/logprob/linalg.py @@ -14,7 +14,7 @@ import pytensor.tensor as pt from pytensor.graph.rewriting.basic import node_rewriter -from pytensor.tensor.math import _matrix_matrix_matmul +from pytensor.tensor.math import _matmul from pymc.logprob.abstract import MeasurableBlockwise, MeasurableOp, _logprob, _logprob_helper from pymc.logprob.rewriting import measurable_ir_rewrites_db @@ -55,7 +55,7 @@ def logprob_measurable_matmul(op, values, l, r): # noqa: E741 return x_logp - log_abs_jac_det -@node_rewriter(tracks=[_matrix_matrix_matmul]) +@node_rewriter(tracks=[_matmul]) def find_measurable_matmul(fgraph, node): """Find measurable matrix-matrix multiplication operations.""" if isinstance(node.op, MeasurableOp): diff --git a/pymc/ode/utils.py b/pymc/ode/utils.py index 1ba99feab..7ff36c819 100644 --- a/pymc/ode/utils.py +++ b/pymc/ode/utils.py @@ -83,7 +83,7 @@ def augment_system(ode_func, n_states, n_theta): Augemted system of differential equations. """ # Present state of the system - t_y = pt.vector("y", dtype="float64") + t_y = pt.vector("y", dtype="float64", shape=(n_states,)) t_y.tag.test_value = np.ones((n_states,), dtype="float64") # Parameter(s). Should be vector to allow for generaliztion to multiparameter # systems of ODEs. Is m dimensional because it includes all initial conditions as well as ode parameters diff --git a/requirements-dev.txt b/requirements-dev.txt index fd00bfd03..8b5968359 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -16,7 +16,7 @@ pandas>=0.24.0 polyagamma pre-commit>=2.8.0 pymc-sphinx-theme>=0.16.0 -pytensor>=2.31.7,<2.32 +pytensor>=2.32.0,<2.33 pytest-cov>=2.5 pytest>=3.0 rich>=13.7.1 diff --git a/requirements.txt b/requirements.txt index 621303906..6907c855e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ cachetools>=4.2.1 cloudpickle numpy>=1.25.0 pandas>=0.24.0 -pytensor>=2.31.7,<2.32 +pytensor>=2.32.0,<2.33 rich>=13.7.1 scipy>=1.4.1 threadpoolctl>=3.1.0,<4.0.0 diff --git a/tests/distributions/test_dist_math.py b/tests/distributions/test_dist_math.py index ff213954a..31d60aabb 100644 --- a/tests/distributions/test_dist_math.py +++ b/tests/distributions/test_dist_math.py @@ -59,7 +59,7 @@ def test_check_parameters(conditions, succeeds): if succeeds: assert ret.eval() else: - with pytest.raises(ParameterValueError, match="^parameter check msg$"): + with pytest.raises(ParameterValueError, match="^parameter check msg*"): ret.eval() diff --git a/tests/distributions/test_distribution.py b/tests/distributions/test_distribution.py index a41df3481..48ad0579b 100644 --- a/tests/distributions/test_distribution.py +++ b/tests/distributions/test_distribution.py @@ -440,7 +440,7 @@ def test_multivariate_shared_mask_separable(self): obs_logp, unobs_logp = logp_fn() expected_logp = pm.logp(rv, unobs_data).eval() np.testing.assert_almost_equal(obs_logp, []) - np.testing.assert_array_equal(unobs_logp, expected_logp) + np.testing.assert_almost_equal(unobs_logp, expected_logp) # Test that we can update a shared mask mask.set_value(np.array([False])) diff --git a/tests/logprob/test_transforms.py b/tests/logprob/test_transforms.py index b55699b56..691c696e8 100644 --- a/tests/logprob/test_transforms.py +++ b/tests/logprob/test_transforms.py @@ -615,10 +615,10 @@ def test_measurable_power_exponent_with_constant_base(): np.testing.assert_allclose(x_logp_fn_pow(0.1), x_logp_fn_exp2(0.1)) + x_rv_neg = pt.pow(-2, pt.random.normal()) + x_vv_neg = x_rv_neg.clone() with pytest.raises(ParameterValueError, match="base >= 0"): - x_rv_neg = pt.pow(-2, pt.random.normal()) - x_vv_neg = x_rv_neg.clone() - logp(x_rv_neg, x_vv_neg) + logp(x_rv_neg, x_vv_neg).eval({x_vv_neg: 1.5}) def test_measurable_power_exponent_with_variable_base(): diff --git a/tests/ode/test_ode.py b/tests/ode/test_ode.py index affe5380f..5945a9597 100644 --- a/tests/ode/test_ode.py +++ b/tests/ode/test_ode.py @@ -412,7 +412,9 @@ def system(y, t, p): warnings.filterwarnings( "ignore", "invalid value encountered in log", RuntimeWarning ) - idata = pm.sample(50, tune=0, chains=1) + idata = pm.sample( + 50, tune=0, chains=1, progressbar=False, compute_convergence_checks=False + ) assert idata.posterior["R"].shape == (1, 50) assert idata.posterior["sigma"].shape == (1, 50, 2) diff --git a/tests/test_printing.py b/tests/test_printing.py index 879b25b96..28f3df68a 100644 --- a/tests/test_printing.py +++ b/tests/test_printing.py @@ -137,7 +137,7 @@ def setup_class(self): ("plain", True): [ r"alpha ~ Normal(0, 10)", r"sigma ~ HalfNormal(0, 1)", - r"mu ~ Deterministic(f(beta, alpha))", + r"mu ~ Deterministic(f(alpha, beta))", r"beta ~ Normal(0, 10)", r"Z ~ MultivariateNormal(f(), f())", r"nb_with_p_n ~ NegativeBinomial(10, nbp)", @@ -149,7 +149,7 @@ def setup_class(self): r"Censored(Bernoulli(0.5), -1, 1))" ), r"Y_obs ~ Normal(mu, sigma)", - r"pot ~ Potential(f(beta, alpha))", + r"pot ~ Potential(f(alpha, beta))", r"pred ~ Deterministic(f())", ], ("plain", False): [ @@ -169,7 +169,7 @@ def setup_class(self): ("latex", True): [ r"$\text{alpha} \sim \operatorname{Normal}(0,~10)$", r"$\text{sigma} \sim \operatorname{HalfNormal}(0,~1)$", - r"$\text{mu} \sim \operatorname{Deterministic}(f(\text{beta},~\text{alpha}))$", + r"$\text{mu} \sim \operatorname{Deterministic}(f(\text{alpha},~\text{beta}))$", r"$\text{beta} \sim \operatorname{Normal}(0,~10)$", r"$\text{Z} \sim \operatorname{MultivariateNormal}(f(),~f())$", r"$\text{nb\_with\_p\_n} \sim \operatorname{NegativeBinomial}(10,~\text{nbp})$", @@ -181,7 +181,7 @@ def setup_class(self): r"~\operatorname{Censored}(\operatorname{Bernoulli}(0.5),~-1,~1))$" ), r"$\text{Y\_obs} \sim \operatorname{Normal}(\text{mu},~\text{sigma})$", - r"$\text{pot} \sim \operatorname{Potential}(f(\text{beta},~\text{alpha}))$", + r"$\text{pot} \sim \operatorname{Potential}(f(\text{alpha},~\text{beta}))$", r"$\text{pred} \sim \operatorname{Deterministic}(f(\text{}))", ], ("latex", False): [