diff --git a/test/test_grad/test_hessian.py b/test/test_grad/test_hessian.py index 9ad29ad..a759310 100644 --- a/test/test_grad/test_hessian.py +++ b/test/test_grad/test_hessian.py @@ -38,13 +38,12 @@ from tad_dftd4 import dftd4 from tad_dftd4.typing import DD, Tensor +from ..conftest import DEVICE from .samples_hessian import samples sample_list = ["LiH", "SiH4", "PbH4-BiH3", "MB16_43_01"] -tol = 1e-8 - -device = None +tol = 1e-7 def test_fail() -> None: @@ -72,10 +71,10 @@ def dummy(x: Tensor) -> Tensor: @pytest.mark.parametrize("dtype", [torch.double]) @pytest.mark.parametrize("name", sample_list) def test_single(dtype: torch.dtype, name: str) -> None: - dd: DD = {"device": device, "dtype": dtype} + dd: DD = {"device": DEVICE, "dtype": dtype} sample = samples[name] - numbers = sample["numbers"].to(device) + numbers = sample["numbers"].to(DEVICE) positions = sample["positions"].to(**dd) charge = torch.tensor(0.0, **dd) @@ -107,13 +106,13 @@ def test_single(dtype: torch.dtype, name: str) -> None: @pytest.mark.parametrize("name1", ["LiH"]) @pytest.mark.parametrize("name2", sample_list) def skip_test_batch(dtype: torch.dtype, name1: str, name2: str) -> None: - dd: DD = {"device": device, "dtype": dtype} + dd: DD = {"device": DEVICE, "dtype": dtype} sample1, sample2 = samples[name1], samples[name2] numbers = pack( [ - sample1["numbers"].to(device), - sample2["numbers"].to(device), + sample1["numbers"].to(DEVICE), + sample2["numbers"].to(DEVICE), ] ) positions = pack( diff --git a/test/test_grad/test_nan.py b/test/test_grad/test_nan.py index 4c9e05e..f4f283b 100644 --- a/test/test_grad/test_nan.py +++ b/test/test_grad/test_nan.py @@ -27,9 +27,10 @@ from tad_dftd4 import dftd4 from tad_dftd4.typing import DD -tol = 1e-8 +from ..conftest import DEVICE + +tol = 1e-7 -device = None # sample, which previously failed with NaN's in tad-dftd3 numbers = torch.tensor([6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1, 7, 8, 8, 8]) @@ -68,9 +69,9 @@ @pytest.mark.grad @pytest.mark.parametrize("dtype", [torch.float, torch.double]) def test_single(dtype: torch.dtype) -> None: - dd: DD = {"device": device, "dtype": dtype} + dd: DD = {"device": DEVICE, "dtype": dtype} - nums = numbers.to(device=device) + nums = numbers.to(device=DEVICE) pos = positions.to(**dd) chrg = charge.to(**dd) par = {k: v.to(**dd) for k, v in param.items()} @@ -96,12 +97,12 @@ def test_single(dtype: torch.dtype) -> None: @pytest.mark.parametrize("dtype", [torch.float, torch.double]) @pytest.mark.parametrize("name", ["LiH", "SiH4"]) def test_batch(dtype: torch.dtype, name: str) -> None: - dd: DD = {"device": device, "dtype": dtype} + dd: DD = {"device": DEVICE, "dtype": dtype} nums = pack( ( - numbers.to(device=device), - samples[name]["numbers"].to(device=device), + numbers.to(device=DEVICE), + samples[name]["numbers"].to(device=DEVICE), ) ) pos = pack( diff --git a/test/test_grad/test_param.py b/test/test_grad/test_param.py index fb65b70..8d717aa 100644 --- a/test/test_grad/test_param.py +++ b/test/test_grad/test_param.py @@ -28,21 +28,21 @@ from tad_dftd4 import dftd4 from tad_dftd4.typing import DD, Callable, Tensor -sample_list = ["LiH", "AmF3", "SiH4"] +from ..conftest import DEVICE -tol = 1e-8 +sample_list = ["LiH", "AmF3", "SiH4"] -device = None +tol = 1e-7 def gradchecker(dtype: torch.dtype, name: str) -> tuple[ Callable[[Tensor, Tensor, Tensor, Tensor], Tensor], # autograd function tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor], ]: - dd: DD = {"device": device, "dtype": dtype} + dd: DD = {"device": DEVICE, "dtype": dtype} sample = samples[name] - numbers = sample["numbers"].to(device=device) + numbers = sample["numbers"].to(device=DEVICE) positions = sample["positions"].to(**dd) charge = torch.tensor(0.0, **dd) @@ -104,13 +104,13 @@ def gradchecker_batch(dtype: torch.dtype, name1: str, name2: str) -> tuple[ Callable[[Tensor, Tensor, Tensor, Tensor], Tensor], # autograd function tuple[Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor], ]: - dd: DD = {"device": device, "dtype": dtype} + dd: DD = {"device": DEVICE, "dtype": dtype} sample1, sample2 = samples[name1], samples[name2] numbers = pack( [ - sample1["numbers"].to(device=device), - sample2["numbers"].to(device=device), + sample1["numbers"].to(device=DEVICE), + sample2["numbers"].to(device=DEVICE), ] ) positions = pack( diff --git a/test/test_grad/test_pos.py b/test/test_grad/test_pos.py index d34b9c4..e3bde2e 100644 --- a/test/test_grad/test_pos.py +++ b/test/test_grad/test_pos.py @@ -32,7 +32,7 @@ sample_list = ["LiH", "SiH4", "PbH4-BiH3", "MB16_43_01"] -tol = 1e-8 +tol = 1e-7 def gradchecker(dtype: torch.dtype, name: str) -> tuple[