Skip to content

Commit

Permalink
Support Python 3.12 (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinfriede authored Sep 19, 2024
1 parent 74fc34c commit 9c4af05
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos-arm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
os: [macos-14]
# Python 3.8/3.9 is not on macos-latest (macos-14-arm64)
# https://github.com/actions/setup-python/issues/696
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
# only test oldest and newest version of torch
torch-version: ["1.11.0", "2.4.1"]
exclude:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-x86.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
fail-fast: false
matrix:
os: [macos-12, macos-13]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# only test oldest and newest version of torch
torch-version: ["1.11.0", "2.2.2"]
exclude:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-nolibcint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
torch-version: ["2.4.1"]
exclude:
# Check latest versions here: https://download.pytorch.org/whl/torch/
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
# python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
torch-version: ["2.0.1", "2.1.2", "2.2.2", "2.3.1", "2.4.1"]
exclude:
# Check latest versions here: https://download.pytorch.org/whl/torch/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# only test oldest and newest version of torch
torch-version: ["1.11.0", "2.4.1"]
exclude:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
<!---->
<br>
<!---->
<a href="https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10%20|%203.11-blue.svg">
<img src="https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10%20|%203.11-blue.svg" alt="Python Versions"/>
<a href="https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12-blue.svg">
<img src="https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10%20|%203.11%20|%203.12-blue.svg" alt="Python Versions"/>
</a>
<a href="https://img.shields.io/badge/PyTorch-%3E=1.11.0-blue.svg">
<img src="https://img.shields.io/badge/PyTorch-%3E=1.11.0-blue.svg" alt="PyTorch Versions"/>
Expand Down Expand Up @@ -137,9 +137,9 @@ For more examples and details, check out [the documentation](https://dxtb.readth
| 1.13.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
| 2.0.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
| 2.1.2 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
| 2.2.2 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | planned |
| 2.3.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | planned |
| 2.4.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | planned |
| 2.2.2 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| 2.3.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| 2.4.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |

Note that only the latest bug fix version is listed, but all preceding bug fix minor versions are supported.
For example, although only version 2.2.2 is listed, version 2.2.0 and 2.2.1 are also supported.
Expand Down
2 changes: 1 addition & 1 deletion environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ channels:
dependencies:
- numpy<2
- pydantic
- python>=3.8,<3.12
- python>=3.8,<3.13
- pytorch>=1.11.0,<2.5
- scipy # for xitorch
- pytest
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ install_requires =
tomli-w
torch>=1.11.0,<2.5
typing-extensions
python_requires = >=3.8, <3.12
python_requires = >=3.8, <3.13
package_dir =
=src

Expand Down
18 changes: 12 additions & 6 deletions test/test_a_memory_leak/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from __future__ import annotations

import gc
import warnings

import torch

Expand All @@ -41,12 +42,17 @@ def garbage_collect() -> None:

def _tensors_from_gc() -> Generator[Tensor, None, None]:
# return [obj for obj in gc.get_objects() if isinstance(obj, Tensor)]
for obj in gc.get_objects():
try:
if isinstance(obj, Tensor):
yield obj
except Exception: # nosec B112 pylint: disable=broad-exception-caught
continue
with warnings.catch_warnings():
warnings.simplefilter("ignore", FutureWarning)

for obj in gc.get_objects():
try:
if isinstance(obj, Tensor):
yield obj
except (
Exception
): # nosec B112 pylint: disable=broad-exception-caught
continue


@overload
Expand Down
7 changes: 5 additions & 2 deletions test/test_config/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
from __future__ import annotations

import pytest
import torch

from dxtb._src.constants import defaults, labels
from dxtb._src.exlibs.available import has_libcint
from dxtb._src.typing import get_default_device, get_default_dtype
from dxtb._src.typing import get_default_dtype
from dxtb.config import Config as Cfg

from ..conftest import DEVICE


def test_default() -> None:
cfg = Cfg()
Expand All @@ -41,7 +44,7 @@ def test_default() -> None:
assert cfg.ints.uplo == defaults.INTUPLO

assert cfg.anomaly == False
assert cfg.device == get_default_device()
assert cfg.device == torch.device("cpu") if DEVICE is None else DEVICE
assert cfg.dtype == get_default_dtype()

assert cfg.scf.maxiter == defaults.MAXITER
Expand Down
13 changes: 9 additions & 4 deletions test/test_hamiltonian/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import pytest
import torch
from tad_mctc._version import __tversion__

from dxtb import GFN1_XTB as par
from dxtb import IndexHelper
Expand All @@ -51,12 +52,16 @@ def test_write_to_pt() -> None:
h = GFN1Hamiltonian(numbers, par, ihelp)
h._matrix = torch.tensor([[1.0, 2.0], [3.0, 4.0]])

kwargs: dict = {"map_location": torch.device("cpu")}
if __tversion__ > (1, 12, 1):
kwargs["weights_only"] = True

with td.TemporaryDirectory() as tmpdir:
p_write = Path(tmpdir) / "test.pt"
h.to_pt(p_write)

read_mat = torch.load(p_write)
assert pytest.approx(h._matrix.cpu()) == read_mat.cpu()
read_mat = torch.load(p_write, **kwargs)
assert pytest.approx(h._matrix.cpu()) == read_mat

with td.TemporaryDirectory() as tmpdir:
p_write = Path(tmpdir) / f"{h.label.casefold()}"
Expand All @@ -65,5 +70,5 @@ def test_write_to_pt() -> None:
h.label = str(p_write)
h.to_pt()

read_mat = torch.load(f"{p_write}.pt")
assert pytest.approx(h._matrix.cpu()) == read_mat.cpu()
read_mat = torch.load(f"{p_write}.pt", **kwargs)
assert pytest.approx(h._matrix.cpu()) == read_mat

0 comments on commit 9c4af05

Please sign in to comment.