Skip to content

Commit

Permalink
Test all PyTorch versions >=1.11.0 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinfriede authored Apr 5, 2024
1 parent 02240c6 commit 7f6f8ad
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 21 deletions.
67 changes: 49 additions & 18 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# This file is part of tad-multicharge.
#
# SPDX-Identifier: Apache-2.0
# Copyright (C) 2024 Grimme Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Tests

on:
Expand All @@ -6,17 +22,17 @@ on:
- main
- master
paths-ignore:
- "docs/**"
- "doc*/**"
- "./*.ya?ml"
- "**/*.md"
- "**/*.rst"
- "**/*.ya?ml"

pull_request:
paths-ignore:
- "docs/**"
- "doc*/**"
- "./*.ya?ml"
- "**/*.md"
- "**/*.rst"
- "**/*.ya?ml"

workflow_dispatch:

Expand All @@ -25,27 +41,39 @@ jobs:
strategy:
fail-fast: false
matrix:
# torch-version: ["1.11.0", "1.12.1", "1.13.0"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# PyTorch now fully supports Python =<3.11
# see: https://github.com/pytorch/pytorch/issues/86566
#
# PyTorch does not support Python 3.12 (all platforms)
# see: https://github.com/pytorch/pytorch/issues/110436
torch-version: ["1.11.0", "1.12.1", "1.13.1", "2.0.1", "2.1.2", "2.2.2"]
exclude:
# PyTorch now fully supports Python=<3.11
# see: https://github.com/pytorch/pytorch/issues/86566
#
# PyTorch does not support Python 3.12 (all platforms)
# see: https://github.com/pytorch/pytorch/issues/110436
- os: ubuntu-latest
python-version: "3.12"
- os: macos-latest
python-version: "3.12"
- os: windows-latest
python-version: "3.12"
# PyTorch<1.13.0 does only support Python=<3.10
- python-version: "3.11"
torch-version: "1.11.0"
- python-version: "3.11"
torch-version: "1.12.1"
# On macOS and Windows, 1.13.x is also not supported for Python>=3.10
- os: macos-latest
python-version: "3.11"
torch-version: "1.13.1"
- os: windows-latest
python-version: "3.11"
torch-version: "1.13.1"

runs-on: ${{ matrix.os }}

defaults:
run:
shell: ${{ contains(matrix.os, 'windows') && 'powershell' || 'bash {0}' }}
shell: bash {0}

steps:
- name: Checkout code
Expand All @@ -60,18 +88,21 @@ jobs:
run: |
python3 -m pip install --upgrade pip
python3 -m pip install tox
# pip install torch==${{ matrix.torch-version }}+cpu -f https://download.pytorch.org/whl/torch_stable.html
# pip install pytest pytest-cov codecov
# - name: Unittests with pytest
# run: pytest -svv --cov=./src --cov-report=term-missing
- name: Determine TOXENV
run: echo "TOXENV=py$(echo ${{ matrix.python-version }} | tr -d '.')-torch$(echo ${{ matrix.torch-version }} | tr -d '.')" >> $GITHUB_ENV

- name: Print TOXENV
run: echo "TOXENV is set to '${{ env.TOXENV }}'."

# with '-e py' tox runs the python version of the current environment
- name: Unittests with tox
run: tox -e py
run: tox -e ${{ env.TOXENV }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
if: >
matrix.python-version == '3.11' &&
matrix.torch-version == '2.2.2' &&
matrix.os == 'ubuntu-latest'
with:
files: ./coverage.xml # optional
16 changes: 16 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# This file is part of tad-multicharge.
#
# SPDX-Identifier: Apache-2.0
# Copyright (C) 2024 Grimme Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Build

on:
Expand Down
2 changes: 1 addition & 1 deletion test/test_grad/test_dqdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_jacobian(dtype: torch.dtype, name: str) -> None:
assert pytest.approx(ref.cpu(), abs=tol * 10.5) == jac_np

assert pytest.approx(ref.cpu(), abs=tol * 10) == numgrad.cpu()
assert pytest.approx(numgrad.cpu(), abs=tol) == jac_np
assert pytest.approx(numgrad.cpu(), abs=tol * 10) == jac_np


def calc_numgrad(numbers: Tensor, positions: Tensor, charge: Tensor) -> Tensor:
Expand Down
24 changes: 22 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@
[tox]
min_version = 4.0
isolated_build = True
envlist = py{38,39,310,311}
envlist =
py38-torch{1110,1121,1131,201,212,222},
py39-torch{1110,1121,1131,201,212,222},
py310-torch{1110,1121,1131,201,212,222},
py311-torch{1131,201,212,222}

[testenv]
deps = .[tox]
setenv =
PIP_EXTRA_INDEX_URL = {env:PIP_EXTRA_INDEX_URL:https://download.pytorch.org/whl/cpu}
deps =
torch1110: torch==1.11.0
torch1120: torch==1.12.0
torch1121: torch==1.12.1
torch1130: torch==1.13.0
torch1131: torch==1.13.1
torch200: torch==2.0.0
torch201: torch==2.0.1
torch210: torch==2.1.0
torch211: torch==2.1.1
torch212: torch==2.1.2
torch220: torch==2.2.0
torch221: torch==2.2.1
torch222: torch==2.2.2
.[tox]
commands =
pytest -vv {posargs: \
-n logical \
Expand Down

0 comments on commit 7f6f8ad

Please sign in to comment.