From 9c4af05c53854b5ccfdfa6d09f05d9d978aecd2d Mon Sep 17 00:00:00 2001
From: Marvin Friede <51965259+marvinfriede@users.noreply.github.com>
Date: Thu, 19 Sep 2024 14:18:53 -0500
Subject: [PATCH] Support Python 3.12 (#172)
---
.github/workflows/macos-arm.yaml | 2 +-
.github/workflows/macos-x86.yaml | 2 +-
.github/workflows/ubuntu-nolibcint.yaml | 2 +-
.github/workflows/ubuntu.yaml | 3 +--
.github/workflows/windows.yaml | 2 +-
README.md | 10 +++++-----
environment.yaml | 2 +-
setup.cfg | 2 +-
test/test_a_memory_leak/util.py | 18 ++++++++++++------
test/test_config/test_main.py | 7 +++++--
test/test_hamiltonian/test_base.py | 13 +++++++++----
11 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/.github/workflows/macos-arm.yaml b/.github/workflows/macos-arm.yaml
index d7a05db7..d32855da 100644
--- a/.github/workflows/macos-arm.yaml
+++ b/.github/workflows/macos-arm.yaml
@@ -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:
diff --git a/.github/workflows/macos-x86.yaml b/.github/workflows/macos-x86.yaml
index 91148214..bcaecb3b 100644
--- a/.github/workflows/macos-x86.yaml
+++ b/.github/workflows/macos-x86.yaml
@@ -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:
diff --git a/.github/workflows/ubuntu-nolibcint.yaml b/.github/workflows/ubuntu-nolibcint.yaml
index a4aa8631..cd92bbc6 100644
--- a/.github/workflows/ubuntu-nolibcint.yaml
+++ b/.github/workflows/ubuntu-nolibcint.yaml
@@ -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/
diff --git a/.github/workflows/ubuntu.yaml b/.github/workflows/ubuntu.yaml
index fb62714c..2aa7c5cb 100644
--- a/.github/workflows/ubuntu.yaml
+++ b/.github/workflows/ubuntu.yaml
@@ -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/
diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml
index 462aaee0..231acfdb 100644
--- a/.github/workflows/windows.yaml
+++ b/.github/workflows/windows.yaml
@@ -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:
diff --git a/README.md b/README.md
index 9c89ccb2..d2481f87 100644
--- a/README.md
+++ b/README.md
@@ -43,8 +43,8 @@
-
-
+
+
@@ -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.
diff --git a/environment.yaml b/environment.yaml
index 3d573c00..55d548b7 100644
--- a/environment.yaml
+++ b/environment.yaml
@@ -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
diff --git a/setup.cfg b/setup.cfg
index 39d98319..ccd62164 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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
diff --git a/test/test_a_memory_leak/util.py b/test/test_a_memory_leak/util.py
index c38f3aec..c789d8ff 100644
--- a/test/test_a_memory_leak/util.py
+++ b/test/test_a_memory_leak/util.py
@@ -23,6 +23,7 @@
from __future__ import annotations
import gc
+import warnings
import torch
@@ -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
diff --git a/test/test_config/test_main.py b/test/test_config/test_main.py
index d2ee38e7..4755b666 100644
--- a/test/test_config/test_main.py
+++ b/test/test_config/test_main.py
@@ -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()
@@ -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
diff --git a/test/test_hamiltonian/test_base.py b/test/test_hamiltonian/test_base.py
index 439bcf67..76e3f4a0 100644
--- a/test/test_hamiltonian/test_base.py
+++ b/test/test_hamiltonian/test_base.py
@@ -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
@@ -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()}"
@@ -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