Skip to content

Commit

Permalink
Merge pull request pybamm-team#3531 from agriyakhetarpal/support-pyth…
Browse files Browse the repository at this point in the history
…on-3.12

Support Python 3.12
  • Loading branch information
Saransh-cpp authored Dec 19, 2023
2 parents b604201 + 61cc1c8 commit 463f477
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Install dependencies
run: pip install --upgrade pip setuptools wheel
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run_periodic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Check style
run: |
Expand All @@ -46,7 +46,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
if: matrix.os != 'windows-latest'
run: python -m nox -s pybamm-requires

- name: Run unit tests for GNU/Linux with Python 3.8, 3.9, and 3.10, and for macOS and Windows with all Python versions
- name: Run unit tests for GNU/Linux with Python 3.8, 3.9, 3.10, and 3.12; and for macOS and Windows with all Python versions
if: (matrix.os == 'ubuntu-latest' && matrix.python-version != 3.11) || (matrix.os != 'ubuntu-latest')
run: python -m nox -s unit

Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
46 changes: 24 additions & 22 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Check style
run: |
Expand All @@ -38,8 +38,9 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# We check coverage on Ubuntu with Python 3.11, so we skip unit tests for it here
# TODO: check coverage with Python 3.12 when [odes] supports it
exclude:
- os: ubuntu-latest
python-version: "3.11"
Expand Down Expand Up @@ -116,6 +117,7 @@ jobs:
run: python -m nox -s unit

# Runs only on Ubuntu with Python 3.11
# TODO: check coverage with Python 3.12 when [odes] supports it
check_coverage:
needs: style
runs-on: ubuntu-latest
Expand Down Expand Up @@ -180,7 +182,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
name: Integration tests (${{ matrix.os }} / Python ${{ matrix.python-version }})

steps:
Expand Down Expand Up @@ -253,14 +255,14 @@ jobs:
- name: Run integration tests for ${{ matrix.os }} with Python ${{ matrix.python-version }}
run: python -m nox -s integration

# Runs only on Ubuntu with Python 3.11. Skips IDAKLU module compilation
# Runs only on Ubuntu with Python 3.12. Skips IDAKLU module compilation
# for speedups, which is already tested in other jobs.
run_doctests:
needs: style
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Doctests (ubuntu-latest / Python 3.11)
name: Doctests (ubuntu-latest / Python 3.12)

steps:
- name: Check out PyBaMM repository
Expand All @@ -270,39 +272,39 @@ jobs:
- name: Install Linux system dependencies
uses: awalsh128/[email protected]
with:
packages: gfortran gcc graphviz pandoc
packages: graphviz pandoc
execute_install_scripts: true

# dot -c is for registering graphviz fonts and plugins
- name: Install OpenBLAS and TeXLive for Linux
- name: Install TeXLive for Linux
run: |
sudo apt-get update
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
sudo apt-get install texlive-latex-extra dvipng
- name: Set up Python 3.11
- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12
cache: 'pip'

- name: Install nox
run: python -m pip install nox

- name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11
- name: Install docs dependencies and run doctests for GNU/Linux with Python 3.12
run: python -m nox -s doctests

- name: Check if the documentation can be built for GNU/Linux with Python 3.11
- name: Check if the documentation can be built for GNU/Linux with Python 3.12
run: python -m nox -s docs

# Runs only on Ubuntu with Python 3.11
# Runs only on Ubuntu with Python 3.12
run_example_tests:
needs: style
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Example notebooks (ubuntu-latest / Python 3.11)
name: Example notebooks (ubuntu-latest / Python 3.12)

steps:
- name: Check out PyBaMM repository
Expand All @@ -322,11 +324,11 @@ jobs:
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
- name: Set up Python 3.11
- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12
cache: 'pip'

- name: Install nox
Expand All @@ -348,16 +350,16 @@ jobs:
- name: Install SuiteSparse and SUNDIALS on GNU/Linux
run: python -m nox -s pybamm-requires

- name: Run example notebooks tests for GNU/Linux with Python 3.11
- name: Run example notebooks tests for GNU/Linux with Python 3.12
run: python -m nox -s examples

# Runs only on Ubuntu with Python 3.11
# Runs only on Ubuntu with Python 3.12
run_scripts_tests:
needs: style
runs-on: ubuntu-latest
strategy:
fail-fast: false
name: Example scripts (ubuntu-latest / Python 3.11)
name: Example scripts (ubuntu-latest / Python 3.12)

steps:
- name: Check out PyBaMM repository
Expand All @@ -377,11 +379,11 @@ jobs:
sudo dot -c
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
- name: Set up Python 3.11
- name: Set up Python 3.12
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12
cache: 'pip'

- name: Install nox
Expand All @@ -403,5 +405,5 @@ jobs:
- name: Install SuiteSparse and SUNDIALS on GNU/Linux
run: python -m nox -s pybamm-requires

- name: Run example scripts tests for GNU/Linux with Python 3.11
- name: Run example scripts tests for GNU/Linux with Python 3.12
run: python -m nox -s scripts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ setup.log
# test
test.c
test.json
.pytest_cache/

# tox
.tox/
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build:
- "graphviz"
os: ubuntu-22.04
tools:
python: "3.11"
python: "3.12"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- Added support for Python 3.12 ([#3531](https://github.com/pybamm-team/PyBaMM/pull/3531))
- Added method to get QuickPlot axes by variable ([#3596](https://github.com/pybamm-team/PyBaMM/pull/3596))
- Added custom experiment terminations ([#3596](https://github.com/pybamm-team/PyBaMM/pull/3596))
- Mechanical parameters are now a function of stoichiometry and temperature ([#3576](https://github.com/pybamm-team/PyBaMM/pull/3576))
Expand Down
14 changes: 11 additions & 3 deletions docs/source/user_guide/installation/GNU-linux.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GNU-Linux & MacOS
Prerequisites
-------------

To use PyBaMM, you must have Python 3.8, 3.9, 3.10, or 3.11 installed.
To use PyBaMM, you must have Python 3.8, 3.9, 3.10, 3.11, or 3.12 installed.

.. tab:: Debian-based distributions (Debian, Ubuntu, Linux Mint)

Expand Down Expand Up @@ -50,7 +50,7 @@ User install

We recommend to install PyBaMM within a virtual environment, in order
not to alter any distribution Python files.
First, make sure you are using Python 3.8, 3.9, 3.10, or 3.11.
First, make sure you are using Python 3.8, 3.9, 3.10, 3.11, or 3.12.
To create a virtual environment ``env`` within your current directory type:

.. code:: bash
Expand Down Expand Up @@ -105,7 +105,15 @@ Optional - scikits.odes solver
Users can install `scikits.odes <https://github.com/bmcage/odes>`__ in
order to use the wrapped SUNDIALS ODE and DAE
`solvers <https://docs.pybamm.org/en/latest/source/api/solvers/scikits_solvers.html>`__.
Currently, only GNU/Linux and macOS are supported.

.. note::

Currently, only GNU/Linux and macOS are supported.

.. note::

The ``scikits.odes`` solver is not supported on Python 3.12 yet, please refer to https://github.com/bmcage/odes/issues/162.
There is support for Python 3.8, 3.9, 3.10, and 3.11.

.. tab:: GNU/Linux

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ or download the source archive on the repository's homepage.

To install PyBaMM, you will need:

- Python 3 (PyBaMM supports versions 3.8, 3.9, 3.10, and 3.11)
- Python 3 (PyBaMM supports versions 3.8, 3.9, 3.10, 3.11, and 3.12)
- The Python headers file for your current Python version.
- A BLAS library (for instance `openblas <https://www.openblas.net/>`_).
- A C compiler (ex: ``gcc``).
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/installation/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Windows
Prerequisites
-------------

To use PyBaMM, you must have Python 3.8, 3.9, 3.10, or 3.11 installed.
To use PyBaMM, you must have Python 3.8, 3.9, 3.10, 3.11, or 3.12 installed.

To install Python 3 download the installation files from `Python’s
website <https://www.python.org/downloads/windows/>`__. Make sure to
Expand Down
62 changes: 38 additions & 24 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def set_environment_variables(env_dict, session):
"""
Sets environment variables for a nox session object.
Sets environment variables for a nox Session object.
Parameters
-----------
Expand Down Expand Up @@ -61,7 +61,10 @@ def run_coverage(session):
set_environment_variables(PYBAMM_ENV, session=session)
session.install("coverage", silent=False)
if sys.platform != "win32":
session.install("-e", ".[all,jax,odes]", silent=False)
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
else:
session.install("-e", ".[all,jax,odes]", silent=False)
else:
if sys.version_info < (3, 9):
session.install("-e", ".[all]", silent=False)
Expand All @@ -77,7 +80,10 @@ def run_integration(session):
"""Run the integration tests."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.install("-e", ".[all,jax,odes]", silent=False)
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
else:
session.install("-e", ".[all,jax,odes]", silent=False)
else:
if sys.version_info < (3, 9):
session.install("-e", ".[all]", silent=False)
Expand All @@ -98,7 +104,10 @@ def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
session.install("-e", ".[all,jax,odes]", silent=False)
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
else:
session.install("-e", ".[all,jax,odes]", silent=False)
else:
if sys.version_info < (3, 9):
session.install("-e", ".[all]", silent=False)
Expand Down Expand Up @@ -131,34 +140,35 @@ def set_dev(session):
session.install("virtualenv", "cmake")
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
session.run(
python,
"-m",
"pip",
"install",
"--upgrade",
"pip",
"setuptools",
"wheel",
external=True,
)
if sys.platform == "linux":
session.run(
python,
"-m",
"pip",
"install",
"-e",
".[all,dev,jax,odes]",
external=True,
)
if sys.version_info > (3, 12):
session.run(
python,
"-m",
"pip",
"install",
"-e",
".[all,dev,jax]",
external=True,
)
else:
session.run(
python,
"-m",
"pip",
"install",
"-e",
".[all,dev,jax,odes]",
external=True,
)
else:
if sys.version_info < (3, 9):
session.run(
python,
"-m",
"pip",
"install",
"-e",
".[all,dev]",
external=True,
)
Expand All @@ -168,6 +178,7 @@ def set_dev(session):
"-m",
"pip",
"install",
"-e",
".[all,dev,jax]",
external=True,
)
Expand All @@ -178,6 +189,9 @@ def run_tests(session):
"""Run the unit tests and integration tests sequentially."""
set_environment_variables(PYBAMM_ENV, session=session)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
else:
session.install("-e", ".[all,jax,odes]", silent=False)
else:
if sys.version_info < (3, 9):
Expand Down
Loading

0 comments on commit 463f477

Please sign in to comment.