test_cuaev.py 1.64 KB
Newer Older
1
2
3
import torchani
import unittest
import torch
Gao, Xiang's avatar
Gao, Xiang committed
4
5
import os
from torchani.testing import TestCase, make_tensor
6
7
8
9
10

skipIfNoGPU = unittest.skipIf(not torch.cuda.is_available(),
                              'There is no device to run this test')


Gao, Xiang's avatar
Gao, Xiang committed
11
12
@unittest.skipIf(not torchani.aev.has_cuaev, "only valid when cuaev is installed")
class TestCUAEVNoGPU(TestCase):
13

Gao, Xiang's avatar
Gao, Xiang committed
14
    def testSimple(self):
15
16
17
18
19
        def f(coordinates, species, Rcr: float, Rca: float, EtaR, ShfR, EtaA, Zeta, ShfA, ShfZ, num_species: int):
            return torch.ops.cuaev.cuComputeAEV(coordinates, species, Rcr, Rca, EtaR, ShfR, EtaA, Zeta, ShfA, ShfZ, num_species)
        s = torch.jit.script(f)
        self.assertIn("cuaev::cuComputeAEV", str(s.graph))

Gao, Xiang's avatar
Gao, Xiang committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    def testAEVComputer(self):
        path = os.path.dirname(os.path.realpath(__file__))
        const_file = os.path.join(path, '../torchani/resources/ani-1x_8x/rHCNO-5.2R_16-3.5A_a4-8.params')  # noqa: E501
        consts = torchani.neurochem.Constants(const_file)
        aev_computer = torchani.AEVComputer(**consts, use_cuda_extension=True)
        s = torch.jit.script(aev_computer)
        # Computation of AEV using cuaev when there is no atoms does not require CUDA, and can be run without GPU
        species = make_tensor((8, 0), 'cpu', torch.int64, low=-1, high=4)
        coordinates = make_tensor((8, 0, 3), 'cpu', torch.float32, low=-5, high=5)
        self.assertIn("cuaev::cuComputeAEV", str(s.graph_for((species, coordinates))))


@unittest.skipIf(not torchani.aev.has_cuaev, "only valid when cuaev is installed")
@skipIfNoGPU
class TestCUAEV(TestCase):
35
    def testHello(self):
36
        pass
37
38
39
40


if __name__ == '__main__':
    unittest.main()