From 67d0669894eb4dc2b7992c704df5034ff7c91954 Mon Sep 17 00:00:00 2001 From: Virgile Andreani Date: Tue, 14 Oct 2025 00:49:08 +0200 Subject: [PATCH 1/3] Make pytensor compatible with Python 3.14 --- .github/workflows/test.yml | 16 ++++++++-------- pyproject.toml | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c44c4d44f..a06fb24f56 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,7 +54,7 @@ jobs: if: ${{ needs.changes.outputs.changes == 'true' }} strategy: matrix: - python-version: ["3.11", "3.13"] + python-version: ["3.11", "3.14"] steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: @@ -75,7 +75,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest"] - python-version: ["3.11", "3.13"] + python-version: ["3.11", "3.14"] fast-compile: [0, 1] float32: [0, 1] install-numba: [0] @@ -117,13 +117,13 @@ jobs: part: "tests/link/numba --ignore=tests/link/numba/test_slinalg.py" - install-numba: 1 os: "ubuntu-latest" - python-version: "3.13" + python-version: "3.14" fast-compile: 0 float32: 0 part: "tests/link/numba --ignore=tests/link/numba/test_slinalg.py" - install-numba: 1 os: "ubuntu-latest" - python-version: "3.13" + python-version: "3.14" fast-compile: 0 float32: 0 part: "tests/link/numba/test_slinalg.py" @@ -135,7 +135,7 @@ jobs: part: "tests/link/jax" - install-jax: 1 os: "ubuntu-latest" - python-version: "3.13" + python-version: "3.14" fast-compile: 0 float32: 0 part: "tests/link/jax" @@ -147,7 +147,7 @@ jobs: part: "tests/link/pytorch" - install-xarray: 1 os: "ubuntu-latest" - python-version: "3.13" + python-version: "3.14" fast-compile: 0 float32: 0 part: "tests/xtensor" @@ -161,7 +161,7 @@ jobs: install-torch: 0 part: "tests/link/mlx" - os: "macos-15" - python-version: "3.13" + python-version: "3.14" fast-compile: 0 float32: 0 install-numba: 0 @@ -324,7 +324,7 @@ jobs: - name: Set up Python uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 with: - python-version: "3.13" + python-version: "3.14" - name: Install dependencies run: | diff --git a/pyproject.toml b/pyproject.toml index bc9859caca..c5a30b7a4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta" [project] name = "pytensor" dynamic = ['version'] -requires-python = ">=3.11,<3.14" +requires-python = ">=3.11,<3.15" authors = [{ name = "pymc-devs", email = "pymc.devs@gmail.com" }] description = "Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs." readme = "README.rst" @@ -33,6 +33,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", ] keywords = [ From 273c00e457e0ee64603a96b07d95ef70b63bf7c9 Mon Sep 17 00:00:00 2001 From: Virgile Andreani Date: Wed, 15 Oct 2025 13:50:34 +0200 Subject: [PATCH 2/3] Try numba rc --- .github/workflows/test.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a06fb24f56..a8565c3861 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -202,7 +202,7 @@ jobs: else micromamba install --yes -q "python~=${PYTHON_VERSION}" mkl "numpy${NUMPY_VERSION}" scipy pip mkl-service graphviz cython pytest coverage pytest-cov pytest-benchmark pytest-mock pytest-sphinx; fi - if [[ $INSTALL_NUMBA == "1" ]]; then micromamba install --yes -q -c conda-forge "python~=${PYTHON_VERSION}" "numba>=0.57"; fi + if [[ $INSTALL_NUMBA == "1" ]]; then pip install "numba==0.63.0rc1"; fi if [[ $INSTALL_JAX == "1" ]]; then micromamba install --yes -q -c conda-forge "python~=${PYTHON_VERSION}" jax jaxlib numpyro equinox && pip install tfp-nightly; fi if [[ $INSTALL_TORCH == "1" ]]; then micromamba install --yes -q -c conda-forge "python~=${PYTHON_VERSION}" pytorch pytorch-cuda=12.1 "mkl<=2024.0" -c pytorch -c nvidia; fi if [[ $INSTALL_MLX == "1" ]]; then micromamba install --yes -q -c conda-forge "python~=${PYTHON_VERSION}" "mlx<0.29.4"; fi diff --git a/pyproject.toml b/pyproject.toml index c5a30b7a4d..8ac89f7ccf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,7 @@ tests = [ ] rtd = ["sphinx>=5.1.0,<6", "pygments", "pydot"] jax = ["jax", "jaxlib"] -numba = ["numba>=0.57", "llvmlite"] +numba = ["numba>=0.63.0rc1", "llvmlite"] [tool.setuptools.packages.find] include = ["pytensor*"] From 05f97a8f02b2a7b19197c5fd56ba495a2a2fd0b7 Mon Sep 17 00:00:00 2001 From: Virgile Andreani Date: Wed, 15 Oct 2025 15:58:43 +0200 Subject: [PATCH 3/3] Fix pickling errors with python 3.14 --- tests/link/c/test_cmodule.py | 22 +++++++++++----------- tests/test_config.py | 7 +++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/link/c/test_cmodule.py b/tests/link/c/test_cmodule.py index 212a2d8181..0cba38daf1 100644 --- a/tests/link/c/test_cmodule.py +++ b/tests/link/c/test_cmodule.py @@ -395,18 +395,18 @@ def test_linking_patch(listdir_mock, platform): ] -def test_cache_race_condition(): - with tempfile.TemporaryDirectory() as dir_name: +@config.change_flags(on_opt_error="raise", on_shape_error="raise") +def _f_build_cache_race_condition(factor): + # Some of the caching issues arise during constant folding within the + # optimization passes, so we need these config changes to prevent the + # exceptions from being caught + a = pt.vector() + f = pytensor.function([a], factor * a) + return f(np.array([1], dtype=config.floatX)) - @config.change_flags(on_opt_error="raise", on_shape_error="raise") - def f_build(factor): - # Some of the caching issues arise during constant folding within the - # optimization passes, so we need these config changes to prevent the - # exceptions from being caught - a = pt.vector() - f = pytensor.function([a], factor * a) - return f(np.array([1], dtype=config.floatX)) +def test_cache_race_condition(): + with tempfile.TemporaryDirectory() as dir_name: ctx = multiprocessing.get_context() compiledir_prop = pytensor.config._config_var_dict["compiledir"] @@ -425,7 +425,7 @@ def f_build(factor): # A random, constant input to prevent caching between runs factor = rng.random() procs = [ - ctx.Process(target=f_build, args=(factor,)) + ctx.Process(target=_f_build_cache_race_condition, args=(factor,)) for i in range(num_procs) ] for proc in procs: diff --git a/tests/test_config.py b/tests/test_config.py index ab34037c67..ea1de66561 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -247,9 +247,12 @@ def test_config_pickling(): configparser.IntParam(5, lambda i: i > 0), in_c_key=False, ) + # Python 3.14 emits a pickle.PicklingError + # previous versions used to emit an AttributeError + # the error string changed a little bit too with pytest.raises( - AttributeError, - match=r"Can't (pickle|get) local object 'test_config_pickling\.\.'", + (AttributeError, pickle.PicklingError), + match=r"Can't (pickle|get) local object .*test_config_pickling\.\.", ): pickle.dump(root, io.BytesIO())