Unverified Commit 83031ce1 authored by Gao, Xiang's avatar Gao, Xiang Committed by GitHub
Browse files

rewrite unittests to completely remove dependency on NeuroChem (#2)

rewrite unittests to completely remove dependency on NeuroChem
parent 2359a387
*.h5 filter=lfs diff=lfs merge=lfs -text
tests/test_data/* filter=lfs diff=lfs merge=lfs -text
\ No newline at end of file
......@@ -50,7 +50,8 @@ def subset_rmse(subset_dataloader):
coordinates, energies = batch[molecule_id]
coordinates = coordinates.to(aev_computer.device)
energies = energies.to(aev_computer.device)
count, squared_error = evaluate(model, coordinates, energies, _species)
count, squared_error = evaluate(
model, coordinates, energies, _species)
squared_error = squared_error.item()
a.add(count, squared_error)
mse = a.avg()
......@@ -79,7 +80,8 @@ while True:
coordinates, energies = batch[molecule_id]
coordinates = coordinates.to(aev_computer.device)
energies = energies.to(aev_computer.device)
count, squared_error = evaluate(model, coordinates, energies, _species)
count, squared_error = evaluate(
model, coordinates, energies, _species)
a.add(count, squared_error / len(_species))
optimize_step(a)
step += 1
......
......@@ -78,7 +78,8 @@ while True:
coordinates, energies = batch[molecule_id]
coordinates = coordinates.to(aev_computer.device)
energies = energies.to(aev_computer.device)
count, squared_error = evaluate(model, coordinates, energies, _species)
count, squared_error = evaluate(
model, coordinates, energies, _species)
a.add(count, squared_error / len(_species))
optimize_step(a)
step += 1
......
......@@ -17,6 +17,6 @@ setup(name='torchani',
'h5py',
],
test_suite='nose.collector',
tests_require=['nose', 'cntk'],
tests_require=['nose'],
cmdclass=cmdclass,
)
import torch
import numpy
import torchani
import unittest
import os
import pickle
path = os.path.dirname(os.path.realpath(__file__))
N = 97
class TestAEV(unittest.TestCase):
def setUp(self, dtype=torchani.default_dtype):
self.aev = torchani.SortedAEV(dtype=dtype, device=torch.device('cpu'))
self.tolerance = 1e-5
def _test_molecule(self, coordinates, species, expected_radial, expected_angular):
radial, angular = self.aev(coordinates, species)
radial_diff = expected_radial - radial
radial_max_error = torch.max(torch.abs(radial_diff)).item()
angular_diff = expected_angular - angular
angular_max_error = torch.max(torch.abs(angular_diff)).item()
self.assertLess(radial_max_error, self.tolerance)
self.assertLess(angular_max_error, self.tolerance)
def testGDB(self):
for i in range(N):
datafile = os.path.join(path, 'test_data/{}'.format(i))
with open(datafile, 'rb') as f:
coordinates, species, radial, angular, _, _ = pickle.load(f)
self._test_molecule(coordinates, species, radial, angular)
if __name__ == '__main__':
unittest.main()
......@@ -85,7 +85,9 @@ class TestBenchmark(unittest.TestCase):
'terms and indices>radial terms',
'terms and indices>angular terms',
'total>terms and indices',
'total>partition', 'total>assemble'])
'total>combinations', 'total>assemble',
'total>mask_r', 'total>mask_a'
])
def testModelOnAEV(self):
aev_computer = torchani.SortedAEV(
......
......@@ -11,9 +11,13 @@ from bisect import bisect
from pickle import dump, load
path = os.path.dirname(os.path.realpath(__file__))
dataset_dir = os.path.join(path, 'dataset')
class TestDataset(unittest.TestCase):
def setUp(self, data_path=torchani.buildin_dataset_dir):
def setUp(self, data_path=dataset_dir):
self.data_path = data_path
self.ds = torchani.data.load_dataset(data_path)
......
File added
File added
File added
File added
File added
File added
File added
File added
File added
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment