Skip to content

Commit

Permalink
Fix wrong TEST_CONFIG in UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
iProzd committed Jan 26, 2024
1 parent c1a5154 commit 769284a
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 22 deletions.
1 change: 0 additions & 1 deletion deepmd/pt/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

JIT = False
CACHE_PER_SYS = 5 # keep at most so many sets per sys in memory
TEST_CONFIG = "tests/water/se_e2_a.json"
ENERGY_BIAS_TRAINABLE = True

PRECISION_DICT = {
Expand Down
20 changes: 19 additions & 1 deletion source/tests/pt/test_LKF.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@
main,
)

import json
import os


class TestLKF(unittest.TestCase):
def test_lkf(self):
main(["train", str(Path(__file__).parent / "water/lkf.json")])
with open(str(Path(__file__).parent / "water/lkf.json")) as fin:
content = fin.read()
self.config = json.loads(content)
self.config["training"]["training_data"]["systems"] = [
str(Path(__file__).parent / "water/data/data_0")
]
self.config["training"]["validation_data"]["systems"] = [
str(Path(__file__).parent / "water/data/data_0")
]
self.input_json = "test_lkf.json"
with open(self.input_json, "w") as fp:
json.dump(self.config, fp, indent=4)
main(["train", self.input_json])

def tearDown(self):
os.remove(self.input_json)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions source/tests/pt/test_autodiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TestForce:
def test(
self,
):
self.model = None
places = 8
delta = 1e-5
natoms = 5
Expand Down Expand Up @@ -88,6 +89,7 @@ class TestVirial:
def test(
self,
):
self.model = None
places = 8
delta = 1e-4
natoms = 5
Expand Down
8 changes: 5 additions & 3 deletions source/tests/pt/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
from deepmd.pt.utils.env import (
DEVICE,
GLOBAL_NP_FLOAT_PRECISION,
GLOBAL_PT_FLOAT_PRECISION,
TEST_CONFIG,
GLOBAL_PT_FLOAT_PRECISION
)
from deepmd.tf.common import (
expand_sys_str,
)
from deepmd.tf.env import (
op_module,
)
from pathlib import (
Path,
)

CUR_DIR = os.path.dirname(__file__)

Expand Down Expand Up @@ -84,7 +86,7 @@ def base_se_a(rcut, rcut_smth, sel, batch, mean, stddev):
class TestSeA(unittest.TestCase):
def setUp(self):
dp_random.seed(20)
with open(TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
content = fin.read()
config = json.loads(content)
model_config = config["model"]
Expand Down
9 changes: 6 additions & 3 deletions source/tests/pt/test_embedding_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
)
from deepmd.pt.utils.env import (
DEVICE,
GLOBAL_NP_FLOAT_PRECISION,
TEST_CONFIG,
GLOBAL_NP_FLOAT_PRECISION
)
from deepmd.tf.common import (
expand_sys_str,
)
from deepmd.tf.descriptor import DescrptSeA as DescrptSeA_tf

from pathlib import (
Path,
)

CUR_DIR = os.path.dirname(__file__)


Expand Down Expand Up @@ -83,7 +86,7 @@ def base_se_a(descriptor, coord, atype, natoms, box):
class TestSeA(unittest.TestCase):
def setUp(self):
dp_random.seed(0)
with open(TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
content = fin.read()
config = json.loads(content)
model_config = config["model"]
Expand Down
6 changes: 4 additions & 2 deletions source/tests/pt/test_force_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from deepmd.pt.utils.stat import (
make_stat_input,
)

from pathlib import (
Path,
)

class CheckSymmetry(DeepmdDataSystem):
def __init__(
Expand Down Expand Up @@ -61,7 +63,7 @@ def get_data(batch):

class TestForceGrad(unittest.TestCase):
def setUp(self):
with open(env.TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
self.config = json.load(fin)
self.system_index = 0
self.batch_index = 0
Expand Down
3 changes: 3 additions & 0 deletions source/tests/pt/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@


class TestJIT:
def __init__(self):
self.config = None

def test_jit(self):
trainer = get_trainer(deepcopy(self.config))
trainer.run()
Expand Down
9 changes: 5 additions & 4 deletions source/tests/pt/test_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
from deepmd.pt.utils.dataset import (
DeepmdDataSet,
)
from deepmd.pt.utils.env import (
TEST_CONFIG,
)
from deepmd.tf.common import (
expand_sys_str,
)
from deepmd.tf.loss.ener import (
EnerStdLoss,
)
from pathlib import (
Path,
)


CUR_DIR = os.path.dirname(__file__)


def get_batch():
with open(TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
content = fin.read()
config = json.loads(content)
model_config = config["model"]
Expand Down
9 changes: 6 additions & 3 deletions source/tests/pt/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
DpLoaderSet,
)
from deepmd.pt.utils.env import (
DEVICE,
TEST_CONFIG,
DEVICE
)
from deepmd.pt.utils.learning_rate import LearningRateExp as MyLRExp
from deepmd.pt.utils.stat import (
Expand All @@ -47,6 +46,10 @@
LearningRateExp,
)

from pathlib import (
Path,
)

VariableState = collections.namedtuple("VariableState", ["value", "gradient"])


Expand All @@ -71,7 +74,7 @@ def torch2tf(torch_name):

class DpTrainer:
def __init__(self):
with open(TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
content = fin.read()
config = json.loads(content)
model_config = config["model"]
Expand Down
1 change: 1 addition & 0 deletions source/tests/pt/test_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class TestPermutation:
def test(
self,
):
self.model = None
natoms = 5
cell = torch.rand([3, 3], dtype=dtype).to(env.DEVICE)
cell = (cell + cell.T) + 5.0 * torch.eye(3).to(env.DEVICE)
Expand Down
1 change: 1 addition & 0 deletions source/tests/pt/test_permutation_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TestPermutationDenoise:
def test(
self,
):
self.model = None
natoms = 5
cell = torch.rand([3, 3], dtype=dtype).to(env.DEVICE)
cell = (cell + cell.T) + 5.0 * torch.eye(3).to(env.DEVICE)
Expand Down
1 change: 1 addition & 0 deletions source/tests/pt/test_rot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TestRot:
def test(
self,
):
self.model = None
prec = 1e-10
natoms = 5
cell = 10.0 * torch.eye(3, dtype=dtype).to(env.DEVICE)
Expand Down
1 change: 1 addition & 0 deletions source/tests/pt/test_rot_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TestRotDenoise:
def test(
self,
):
self.model = None
prec = 1e-10
natoms = 5
cell = 10.0 * torch.eye(3, dtype=dtype).to(env.DEVICE)
Expand Down
6 changes: 5 additions & 1 deletion source/tests/pt/test_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
make_stat_input,
)

from pathlib import (
Path,
)


class CheckSymmetry(DeepmdDataSystem):
def __init__(
Expand Down Expand Up @@ -69,7 +73,7 @@ def get_data(batch):

class TestRotation(unittest.TestCase):
def setUp(self):
with open(env.TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
self.config = json.load(fin)
self.rotation = special_ortho_group.rvs(3)
self.get_dataset(0)
Expand Down
5 changes: 4 additions & 1 deletion source/tests/pt/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
from deepmd.tf.utils.data_system import (
DeepmdDataSystem,
)
from pathlib import (
Path,
)

CUR_DIR = os.path.dirname(__file__)


class TestSampler(unittest.TestCase):
def setUp(self):
with open(env.TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
content = fin.read()
config = json.loads(content)
model_config = config["model"]
Expand Down
7 changes: 5 additions & 2 deletions source/tests/pt/test_saveload_se_e2_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from deepmd.tf.common import (
expand_sys_str,
)
from pathlib import (
Path,
)


def get_dataset(config):
Expand Down Expand Up @@ -60,9 +63,9 @@ def get_dataset(config):
return dataset, sampled


class TestSaveLoadDPA1(unittest.TestCase):
class TestSaveLoadSeA(unittest.TestCase):
def setUp(self):
input_json = env.TEST_CONFIG
input_json = str(Path(__file__).parent / "water/se_e2_a.json")
with open(input_json) as fin:
self.config = json.load(fin)
self.config["loss"]["starter_learning_rate"] = self.config["learning_rate"][
Expand Down
3 changes: 3 additions & 0 deletions source/tests/pt/test_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@


class TestSmooth:
def __init__(self):
self.epsilon = None

def test(
self,
):
Expand Down
3 changes: 3 additions & 0 deletions source/tests/pt/test_smooth_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@


class TestSmoothDenoise:
def __init__(self):
self.epsilon = None

def test(
self,
):
Expand Down
6 changes: 5 additions & 1 deletion source/tests/pt/test_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
DeepmdDataSystem,
)

from pathlib import (
Path,
)

CUR_DIR = os.path.dirname(__file__)


Expand All @@ -49,7 +53,7 @@ def compare(ut, base, given):

class TestDataset(unittest.TestCase):
def setUp(self):
with open(env.TEST_CONFIG) as fin:
with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin:
content = fin.read()
config = json.loads(content)
model_config = config["model"]
Expand Down
3 changes: 3 additions & 0 deletions source/tests/pt/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@


class TestDPTrain:
def __init__(self):
self.config = None

def test_dp_train(self):
trainer = get_trainer(deepcopy(self.config))
trainer.run()
Expand Down
1 change: 1 addition & 0 deletions source/tests/pt/test_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TestTrans:
def test(
self,
):
self.model = None
natoms = 5
cell = torch.rand([3, 3], dtype=dtype).to(env.DEVICE)
cell = (cell + cell.T) + 5.0 * torch.eye(3).to(env.DEVICE)
Expand Down
1 change: 1 addition & 0 deletions source/tests/pt/test_trans_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TestTransDenoise:
def test(
self,
):
self.model = None
natoms = 5
cell = torch.rand([3, 3], dtype=dtype).to(env.DEVICE)
cell = (cell + cell.T) + 5.0 * torch.eye(3).to(env.DEVICE)
Expand Down

0 comments on commit 769284a

Please sign in to comment.