Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for the case when CUDA is available on the system #161

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tests/metatensor/test_workflow_metatensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def system(self, device=None, dtype=None):
properties=mts_torch.Labels.range("distance", 1),
)

return system.to(device=device), neighbors.to(device=device)
return system.to(device=device, dtype=dtype), neighbors.to(
device=device, dtype=dtype
)

def check_operation(self, calculator, device, dtype):
"""Make sure computation runs and returns a metatensor.TensorMap."""
Expand All @@ -107,12 +109,16 @@ def check_operation(self, calculator, device, dtype):

def test_operation_as_python(self, CalculatorClass, params, device, dtype):
"""Run `check_operation` as a normal python script"""
calculator = CalculatorClass(**params)
params["potential"].device = device
params["potential"].dtype = dtype
calculator = CalculatorClass(**params, device=device, dtype=dtype)
self.check_operation(calculator=calculator, device=device, dtype=dtype)

def test_operation_as_torch_script(self, CalculatorClass, params, device, dtype):
"""Run `check_operation` as a compiled torch script module."""
calculator = CalculatorClass(**params)
params["potential"].device = device
params["potential"].dtype = dtype
calculator = CalculatorClass(**params, device=device, dtype=dtype)
scripted = torch.jit.script(calculator)
self.check_operation(calculator=scripted, device=device, dtype=dtype)

Expand Down