Unverified Commit 2007d181 authored by Jinze Xue's avatar Jinze Xue Committed by GitHub
Browse files

remove test warning (#584)

parent 1d64bbae
import torch import torch
import torchani import torchani
import os import os
from torchani.testing import TestCase
class _TestAEVBase(torchani.testing.TestCase): class _TestAEVBase(TestCase):
def setUp(self): def setUp(self):
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
......
...@@ -9,6 +9,7 @@ import ase.io ...@@ -9,6 +9,7 @@ import ase.io
import math import math
import traceback import traceback
from common_aev_test import _TestAEVBase from common_aev_test import _TestAEVBase
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
...@@ -16,7 +17,7 @@ const_file = os.path.join(path, '../torchani/resources/ani-1x_8x/rHCNO-5.2R_16-3 ...@@ -16,7 +17,7 @@ const_file = os.path.join(path, '../torchani/resources/ani-1x_8x/rHCNO-5.2R_16-3
N = 97 N = 97
class TestAEVConstructor(torchani.testing.TestCase): class TestAEVConstructor(TestCase):
# Test that checks that the friendly constructor # Test that checks that the friendly constructor
# reproduces the values from ANI1x with the correct parameters # reproduces the values from ANI1x with the correct parameters
def testCoverLinearly(self): def testCoverLinearly(self):
...@@ -38,7 +39,7 @@ class TestAEVConstructor(torchani.testing.TestCase): ...@@ -38,7 +39,7 @@ class TestAEVConstructor(torchani.testing.TestCase):
self.assertEqual(c, ca) self.assertEqual(c, ca)
class TestIsolated(torchani.testing.TestCase): class TestIsolated(TestCase):
# Tests that there is no error when atoms are separated # Tests that there is no error when atoms are separated
# a distance greater than the cutoff radius from all other atoms # a distance greater than the cutoff radius from all other atoms
# this can throw an IndexError for large distances or lone atoms # this can throw an IndexError for large distances or lone atoms
...@@ -157,7 +158,7 @@ class TestAEVJIT(TestAEV): ...@@ -157,7 +158,7 @@ class TestAEVJIT(TestAEV):
self.aev_computer = torch.jit.script(self.aev_computer) self.aev_computer = torch.jit.script(self.aev_computer)
class TestPBCSeeEachOther(torchani.testing.TestCase): class TestPBCSeeEachOther(TestCase):
def setUp(self): def setUp(self):
consts = torchani.neurochem.Constants(const_file) consts = torchani.neurochem.Constants(const_file)
self.aev_computer = torchani.AEVComputer(**consts).to(torch.double) self.aev_computer = torchani.AEVComputer(**consts).to(torch.double)
...@@ -261,7 +262,7 @@ class TestPBCSeeEachOther(torchani.testing.TestCase): ...@@ -261,7 +262,7 @@ class TestPBCSeeEachOther(torchani.testing.TestCase):
self.assertEqual(atom_index2.tolist(), [1]) self.assertEqual(atom_index2.tolist(), [1])
class TestAEVOnBoundary(torchani.testing.TestCase): class TestAEVOnBoundary(TestCase):
def setUp(self): def setUp(self):
self.eps = 1e-9 self.eps = 1e-9
...@@ -307,7 +308,7 @@ class TestAEVOnBoundary(torchani.testing.TestCase): ...@@ -307,7 +308,7 @@ class TestAEVOnBoundary(torchani.testing.TestCase):
self.assertEqual(aev, self.aev) self.assertEqual(aev, self.aev)
class TestAEVOnBenzenePBC(torchani.testing.TestCase): class TestAEVOnBenzenePBC(TestCase):
def setUp(self): def setUp(self):
consts = torchani.neurochem.Constants(const_file) consts = torchani.neurochem.Constants(const_file)
......
...@@ -2,9 +2,10 @@ import torch ...@@ -2,9 +2,10 @@ import torch
import torchani import torchani
import math import math
import unittest import unittest
from torchani.testing import TestCase
class TestALAtomic(torchani.testing.TestCase): class TestALAtomic(TestCase):
def setUp(self): def setUp(self):
self.device = torch.device( self.device = torch.device(
'cuda' if torch.cuda.is_available() else 'cpu') 'cuda' if torch.cuda.is_available() else 'cpu')
......
...@@ -4,6 +4,7 @@ from ase.md.nptberendsen import NPTBerendsen ...@@ -4,6 +4,7 @@ from ase.md.nptberendsen import NPTBerendsen
from ase import units from ase import units
from ase.io import read from ase.io import read
from ase.calculators.test import numeric_force from ase.calculators.test import numeric_force
from torchani.testing import TestCase
import numpy as np import numpy as np
import torch import torch
import torchani import torchani
...@@ -21,7 +22,7 @@ def get_numeric_force(atoms, eps): ...@@ -21,7 +22,7 @@ def get_numeric_force(atoms, eps):
return fn return fn
class TestASE(torchani.testing.TestCase): class TestASE(TestCase):
def setUp(self): def setUp(self):
self.model = torchani.models.ANI1x(model_index=0).double() self.model = torchani.models.ANI1x(model_index=0).double()
......
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
import torch import torch
import torchani import torchani
import unittest import unittest
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
dataset_path = os.path.join(path, '../dataset/ani-1x/sample.h5') dataset_path = os.path.join(path, '../dataset/ani-1x/sample.h5')
...@@ -9,7 +10,7 @@ batch_size = 256 ...@@ -9,7 +10,7 @@ batch_size = 256
ani1x_sae_dict = {'H': -0.60095298, 'C': -38.08316124, 'N': -54.7077577, 'O': -75.19446356} ani1x_sae_dict = {'H': -0.60095298, 'C': -38.08316124, 'N': -54.7077577, 'O': -75.19446356}
class TestData(torchani.testing.TestCase): class TestData(TestCase):
def testTensorShape(self): def testTensorShape(self):
ds = torchani.data.load(dataset_path).subtract_self_energies(ani1x_sae_dict).species_to_indices().shuffle().collate(batch_size).cache() ds = torchani.data.load(dataset_path).subtract_self_energies(ani1x_sae_dict).species_to_indices().shuffle().collate(batch_size).cache()
......
...@@ -3,13 +3,14 @@ import torchani ...@@ -3,13 +3,14 @@ import torchani
import unittest import unittest
import os import os
import pickle import pickle
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
N = 97 N = 97
class TestCorrectInput(torchani.testing.TestCase): class TestCorrectInput(TestCase):
def setUp(self): def setUp(self):
self.model = torchani.models.ANI1x(model_index=0, periodic_table_index=False) self.model = torchani.models.ANI1x(model_index=0, periodic_table_index=False)
...@@ -32,7 +33,7 @@ class TestCorrectInput(torchani.testing.TestCase): ...@@ -32,7 +33,7 @@ class TestCorrectInput(torchani.testing.TestCase):
self.assertRaises(AssertionError, self.model, (torch.tensor([0, 1, 2, 3]), torch.zeros((4, 3)))) self.assertRaises(AssertionError, self.model, (torch.tensor([0, 1, 2, 3]), torch.zeros((4, 3))))
class TestEnergies(torchani.testing.TestCase): class TestEnergies(TestCase):
# tests the predicions for a torchani.nn.Sequential(AEVComputer(), # tests the predicions for a torchani.nn.Sequential(AEVComputer(),
# ANIModel(), EnergyShifter()) against precomputed values # ANIModel(), EnergyShifter()) against precomputed values
......
...@@ -3,12 +3,13 @@ import pickle ...@@ -3,12 +3,13 @@ import pickle
import os import os
import torch import torch
import torchani import torchani
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
N = 10 N = 10
class TestEnsemble(torchani.testing.TestCase): class TestEnsemble(TestCase):
def setUp(self): def setUp(self):
self.conformations = 20 self.conformations = 20
......
...@@ -3,12 +3,13 @@ import torchani ...@@ -3,12 +3,13 @@ import torchani
import unittest import unittest
import os import os
import pickle import pickle
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
N = 97 N = 97
class TestForce(torchani.testing.TestCase): class TestForce(TestCase):
def setUp(self): def setUp(self):
model = torchani.models.ANI1x(model_index=0) model = torchani.models.ANI1x(model_index=0)
......
...@@ -3,11 +3,12 @@ import torchani ...@@ -3,11 +3,12 @@ import torchani
import unittest import unittest
import os import os
import pickle import pickle
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
class TestGrad(torchani.testing.TestCase): class TestGrad(TestCase):
# torch.autograd.gradcheck and torch.autograd.gradgradcheck verify that # torch.autograd.gradcheck and torch.autograd.gradgradcheck verify that
# the numerical and analytical gradient and hessian of a function # the numerical and analytical gradient and hessian of a function
# matches to within a given tolerance. # matches to within a given tolerance.
......
...@@ -2,13 +2,14 @@ import torch ...@@ -2,13 +2,14 @@ import torch
import torchani import torchani
import unittest import unittest
import os import os
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
dspath = os.path.join(path, '../dataset/ani-1x/sample.h5') dspath = os.path.join(path, '../dataset/ani-1x/sample.h5')
class TestBuiltinModelsJIT(torchani.testing.TestCase): class TestBuiltinModelsJIT(TestCase):
# Tests if JIT compiled models have the same output energies # Tests if JIT compiled models have the same output energies
# as eager (non JIT) models # as eager (non JIT) models
......
...@@ -2,6 +2,7 @@ import torchani ...@@ -2,6 +2,7 @@ import torchani
import torch import torch
import os import os
import unittest import unittest
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
...@@ -9,7 +10,7 @@ iptpath = os.path.join(path, 'test_data/inputtrain.ipt') ...@@ -9,7 +10,7 @@ iptpath = os.path.join(path, 'test_data/inputtrain.ipt')
dspath = os.path.join(path, '../dataset/ani1-up_to_gdb4/ani_gdb_s01.h5') dspath = os.path.join(path, '../dataset/ani1-up_to_gdb4/ani_gdb_s01.h5')
class TestNeuroChem(torchani.testing.TestCase): class TestNeuroChem(TestCase):
def testNeuroChemTrainer(self): def testNeuroChemTrainer(self):
d = torch.device('cuda' if torch.cuda.is_available() else 'cpu') d = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
......
import unittest import unittest
import torch import torch
import torchani import torchani
from torchani.testing import TestCase
b = torchani.utils.broadcast_first_dim b = torchani.utils.broadcast_first_dim
class TestPaddings(torchani.testing.TestCase): class TestPaddings(TestCase):
def testVectorSpecies(self): def testVectorSpecies(self):
species1 = torch.tensor([[0, 2, 3, 1]]) species1 = torch.tensor([[0, 2, 3, 1]])
...@@ -90,7 +91,7 @@ class TestPaddings(torchani.testing.TestCase): ...@@ -90,7 +91,7 @@ class TestPaddings(torchani.testing.TestCase):
self.assertEqual(expected, present_species) self.assertEqual(expected, present_species)
class TestStripRedundantPadding(torchani.testing.TestCase): class TestStripRedundantPadding(TestCase):
def testStripRestore(self): def testStripRestore(self):
species1 = torch.randint(4, (5, 4), dtype=torch.long) species1 = torch.randint(4, (5, 4), dtype=torch.long)
......
import unittest import unittest
import torch import torch
import torchani import torchani
from torchani.testing import TestCase
class TestSpeciesConverter(torchani.testing.TestCase): class TestSpeciesConverter(TestCase):
def setUp(self): def setUp(self):
self.c = torchani.SpeciesConverter(['H', 'C', 'N', 'O']) self.c = torchani.SpeciesConverter(['H', 'C', 'N', 'O'])
...@@ -29,7 +30,7 @@ class TestSpeciesConverterJIT(TestSpeciesConverter): ...@@ -29,7 +30,7 @@ class TestSpeciesConverterJIT(TestSpeciesConverter):
self.c = torch.jit.script(self.c) self.c = torch.jit.script(self.c)
class TestBuiltinEnsemblePeriodicTableIndex(torchani.testing.TestCase): class TestBuiltinEnsemblePeriodicTableIndex(TestCase):
def setUp(self): def setUp(self):
self.model1 = torchani.models.ANI1x() self.model1 = torchani.models.ANI1x()
......
...@@ -6,12 +6,13 @@ import copy ...@@ -6,12 +6,13 @@ import copy
import pickle import pickle
from ase.optimize import BFGS from ase.optimize import BFGS
from ase import Atoms from ase import Atoms
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
class TestStructureOptimization(torchani.testing.TestCase): class TestStructureOptimization(TestCase):
def setUp(self): def setUp(self):
self.tolerance = 1e-6 self.tolerance = 1e-6
......
import unittest import unittest
import torch import torch
import torchani import torchani
from torchani.testing import TestCase
class TestUtils(torchani.testing.TestCase): class TestUtils(TestCase):
def testChemicalSymbolsToInts(self): def testChemicalSymbolsToInts(self):
str2i = torchani.utils.ChemicalSymbolsToInts(['A', 'B', 'C', 'D', 'E', 'F']) str2i = torchani.utils.ChemicalSymbolsToInts(['A', 'B', 'C', 'D', 'E', 'F'])
......
...@@ -7,13 +7,14 @@ import ase ...@@ -7,13 +7,14 @@ import ase
import ase.optimize import ase.optimize
import ase.vibrations import ase.vibrations
import numpy import numpy
from torchani.testing import TestCase
path = os.path.dirname(os.path.realpath(__file__)) path = os.path.dirname(os.path.realpath(__file__))
path = os.path.join(path, '../dataset/xyz_files/H2O.xyz') path = os.path.join(path, '../dataset/xyz_files/H2O.xyz')
class TestVibrational(torchani.testing.TestCase): class TestVibrational(TestCase):
def testVibrationalWavenumbers(self): def testVibrationalWavenumbers(self):
model = torchani.models.ANI1x().double() model = torchani.models.ANI1x().double()
......
...@@ -38,7 +38,6 @@ from . import models ...@@ -38,7 +38,6 @@ from . import models
from . import units from . import units
from pkg_resources import get_distribution, DistributionNotFound from pkg_resources import get_distribution, DistributionNotFound
import warnings import warnings
from . import testing
try: try:
__version__ = get_distribution(__name__).version __version__ = get_distribution(__name__).version
...@@ -47,7 +46,7 @@ except DistributionNotFound: ...@@ -47,7 +46,7 @@ except DistributionNotFound:
pass pass
__all__ = ['AEVComputer', 'EnergyShifter', 'ANIModel', 'Ensemble', 'SpeciesConverter', __all__ = ['AEVComputer', 'EnergyShifter', 'ANIModel', 'Ensemble', 'SpeciesConverter',
'utils', 'neurochem', 'models', 'units', 'testing'] 'utils', 'neurochem', 'models', 'units']
try: try:
from . import ase # noqa: F401 from . import ase # noqa: F401
......
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