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

Support Python 3.12 #488

Merged
merged 8 commits into from
Jan 18, 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
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
if: ${{ needs.changes.outputs.changes == 'true' }}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -70,7 +70,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.11"]
python-version: ["3.9", "3.12"]
fast-compile: [0,1]
float32: [0,1]
install-numba: [0]
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
float32: 0
part: "tests/link/numba"
- install-numba: 1
python-version: "3.11"
python-version: "3.11" # TODO: bump to 3.12 when numba 0.59 is released
fast-compile: 0
float32: 0
part: "tests/link/numba"
Expand All @@ -111,7 +111,7 @@ jobs:
float32: 0
part: "tests/link/jax"
- install-jax: 1
python-version: "3.11"
python-version: "3.12"
fast-compile: 0
float32: 0
part: "tests/link/jax"
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
- name: Install dependencies
shell: bash -l {0}
run: |
mamba install --yes -q "python~=${PYTHON_VERSION}=*_cpython" mkl "numpy<1.26" scipy pip mkl-service graphviz cython pytest coverage pytest-cov pytest-benchmark pytest-mock sympy
mamba install --yes -q "python~=${PYTHON_VERSION}=*_cpython" mkl numpy scipy pip mkl-service graphviz cython pytest coverage pytest-cov pytest-benchmark pytest-mock sympy
# numba-scipy downgrades the installed scipy to 1.7.3 in Python 3.9, but
# not numpy, even though scipy 1.7 requires numpy<1.23. When installing
# PyTensor next, pip installs a lower version of numpy via the PyPI.
Expand Down Expand Up @@ -249,7 +249,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
- id: ruff-format
args: ["--line-length=88"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
rev: v1.8.0
hooks:
- id: mypy
language: python
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "pytensor"
dynamic = ['version']
requires-python = ">=3.9,<3.12"
requires-python = ">=3.9,<3.13"
authors = [{ name = "pymc-devs", email = "pymc.devs@gmail.com" }]
description = "Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs."
readme = "README.rst"
Expand All @@ -33,6 +33,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

keywords = [
Expand Down
8 changes: 6 additions & 2 deletions pytensor/tensor/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def c_code_cache_version(self):
def shape(x: Union[np.ndarray, Number, Variable]) -> Variable:
"""Return the shape of `x`."""
if not isinstance(x, Variable):
x = ptb.as_tensor_variable(x) # type: ignore
# The following is a type error in Python 3.9 but not 3.12.
# Thus we need to ignore unused-ignore on 3.12.
x = ptb.as_tensor_variable(x) # type: ignore[arg-type,unused-ignore]

return cast(Variable, _shape(x))

Expand Down Expand Up @@ -579,7 +581,9 @@ def specify_shape(

# If the specified shape is already encoded in the input static shape, do nothing
# This ignores PyTensor constants in shape
x = ptb.as_tensor_variable(x) # type: ignore
x = ptb.as_tensor_variable(x) # type: ignore[arg-type,unused-ignore]
# The above is a type error in Python 3.9 but not 3.12.
# Thus we need to ignore unused-ignore on 3.12.
new_shape_info = any(
s != xts for (s, xts) in zip(shape, x.type.shape) if s is not None
)
Expand Down