Skip to content

Commit b12467e

Browse files
author
Han Wang
committed
add unittests for input conversion. fix bugs
1 parent 854b89b commit b12467e

File tree

7 files changed

+229
-7
lines changed

7 files changed

+229
-7
lines changed

examples/water/train/water_se_a.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
"learning_rate" :{
2626
"type": "exp",
27-
"start_lr": 0.005,
27+
"start_lr": 0.001,
2828
"decay_steps": 5000,
2929
"decay_rate": 0.95,
3030
"_comment": "that's all"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"_comment": " model parameters",
3+
"use_smooth": true,
4+
"sel_a": [46, 92],
5+
"rcut_smth": 5.80,
6+
"rcut": 6.00,
7+
"filter_neuron": [25, 50, 100],
8+
"filter_resnet_dt": false,
9+
"axis_neuron": 16,
10+
"fitting_neuron": [240, 240, 240],
11+
"fitting_resnet_dt":true,
12+
"coord_norm": true,
13+
"type_fitting_net": false,
14+
15+
"_comment": " traing controls",
16+
"systems": ["../data/"],
17+
"set_prefix": "set",
18+
"stop_batch": 1000000,
19+
"batch_size": [1],
20+
"start_lr": 0.001,
21+
"decay_steps": 5000,
22+
"decay_rate": 0.95,
23+
24+
"start_pref_e": 0.02,
25+
"limit_pref_e": 1,
26+
"start_pref_f": 1000,
27+
"limit_pref_f": 1,
28+
"start_pref_v": 0,
29+
"limit_pref_v": 0,
30+
31+
"seed": 1,
32+
33+
"_comment": " display and restart",
34+
"_comment": " frequencies counted in batch",
35+
"disp_file": "lcurve.out",
36+
"disp_freq": 100,
37+
"numb_test": 10,
38+
"save_freq": 1000,
39+
"save_ckpt": "model.ckpt",
40+
"disp_training": true,
41+
"time_training": true,
42+
"profiling": true,
43+
"profiling_file": "timeline.json",
44+
45+
"_comment": "that's all"
46+
}
47+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"model": {
3+
"descriptor" :{
4+
"type": "se_a",
5+
"sel": [46, 92],
6+
"rcut_smth": 5.80,
7+
"rcut": 6.00,
8+
"neuron": [25, 50, 100],
9+
"axis_neuron": 16,
10+
"resnet_dt": false,
11+
"seed": 1
12+
},
13+
"fitting_net" : {
14+
"neuron": [240, 240, 240],
15+
"resnet_dt": true,
16+
"seed": 1
17+
}
18+
},
19+
20+
"learning_rate" :{
21+
"type": "exp",
22+
"decay_steps": 5000,
23+
"decay_rate": 0.95,
24+
"start_lr": 0.001
25+
},
26+
27+
"loss" :{
28+
"start_pref_e": 0.02,
29+
"limit_pref_e": 1,
30+
"start_pref_f": 1000,
31+
"limit_pref_f": 1,
32+
"start_pref_v": 0,
33+
"limit_pref_v": 0
34+
},
35+
36+
"training" : {
37+
"systems": ["../data/"],
38+
"set_prefix": "set",
39+
"stop_batch": 1000000,
40+
"batch_size": [1],
41+
42+
"seed": 1,
43+
44+
"disp_file": "lcurve.out",
45+
"disp_freq": 100,
46+
"numb_test": 10,
47+
"save_freq": 1000,
48+
"save_ckpt": "model.ckpt",
49+
"disp_training":true,
50+
"time_training":true,
51+
"profiling": true,
52+
"profiling_file":"timeline.json"
53+
}
54+
}
55+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"with_distrib": false,
3+
"_comment": " model parameters",
4+
"use_smooth": false,
5+
"sel_a": [16, 32],
6+
"sel_r": [30, 60],
7+
"rcut": 6.00,
8+
"axis_rule": [0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0],
9+
"_comment": " default rule: []",
10+
"_comment": " user defined rule: for each type provides two axes, ",
11+
"_comment": " for each axis: (a_or_r, type, idx)",
12+
"_comment": " if type < 0, exclude type -(type+1)",
13+
"_comment": " for water (O:0, H:1) it can be",
14+
"_comment": " [0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0]",
15+
"fitting_neuron": [240, 120, 60, 30, 10],
16+
17+
"_comment": " traing controls",
18+
"systems": ["../data/"],
19+
"set_prefix": "set",
20+
"stop_batch": 1000000,
21+
"batch_size": [4],
22+
"start_lr": 0.001,
23+
"decay_steps": 5000,
24+
"decay_rate": 0.95,
25+
26+
"start_pref_e": 0.02,
27+
"limit_pref_e": 8,
28+
"start_pref_f": 1000,
29+
"limit_pref_f": 1,
30+
"start_pref_v": 0,
31+
"limit_pref_v": 0,
32+
33+
"seed": 1,
34+
35+
"_comment": " display and restart",
36+
"_comment": " frequencies counted in batch",
37+
"disp_file": "lcurve.out",
38+
"disp_freq": 100,
39+
"numb_test": 10,
40+
"save_freq": 1000,
41+
"save_ckpt": "model.ckpt",
42+
"disp_training": true,
43+
"time_training": true,
44+
45+
"_comment": "that's all"
46+
}
47+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"with_distrib": false,
3+
"model":{
4+
"descriptor": {
5+
"type": "loc_frame",
6+
"sel_a": [16, 32],
7+
"sel_r": [30, 60],
8+
"rcut": 6.00,
9+
"axis_rule": [0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0]
10+
},
11+
"fitting_net": {
12+
"neuron": [240, 120, 60, 30, 10],
13+
"resnet_dt": true,
14+
"seed": 1
15+
}
16+
},
17+
18+
"learning_rate" :{
19+
"type": "exp",
20+
"decay_steps": 5000,
21+
"decay_rate": 0.95,
22+
"start_lr": 0.001
23+
},
24+
25+
"loss" : {
26+
"start_pref_e": 0.02,
27+
"limit_pref_e": 8,
28+
"start_pref_f": 1000,
29+
"limit_pref_f": 1,
30+
"start_pref_v": 0,
31+
"limit_pref_v": 0
32+
},
33+
34+
"training": {
35+
"systems": ["../data/"],
36+
"set_prefix": "set",
37+
"stop_batch": 1000000,
38+
"batch_size": [4],
39+
40+
"seed": 1,
41+
42+
"disp_file": "lcurve.out",
43+
"disp_freq": 100,
44+
"numb_test": 10,
45+
"save_freq": 1000,
46+
"save_ckpt": "model.ckpt",
47+
"disp_training":true,
48+
"time_training":true
49+
}
50+
}
51+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os,sys,json
2+
import numpy as np
3+
import unittest
4+
5+
from deepmd.compat import convert_input_v0_v1
6+
7+
class TestConvertInputV0V1 (unittest.TestCase) :
8+
def test_convert_smth(self):
9+
with open(os.path.join('compat_inputs', 'water_se_a_v0.json')) as fp:
10+
jdata0 = json.load(fp)
11+
with open(os.path.join('compat_inputs', 'water_se_a_v1.json')) as fp:
12+
jdata1 = json.load(fp)
13+
jdata = convert_input_v0_v1(jdata0, warning = False, dump = None)
14+
self.assertEqual(jdata, jdata1)
15+
16+
def test_convert_nonsmth(self):
17+
with open(os.path.join('compat_inputs', 'water_v0.json')) as fp:
18+
jdata0 = json.load(fp)
19+
with open(os.path.join('compat_inputs', 'water_v1.json')) as fp:
20+
jdata1 = json.load(fp)
21+
jdata = convert_input_v0_v1(jdata0, warning = False, dump = None)
22+
self.assertEqual(jdata, jdata1)
23+

source/train/compat.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def _smth_descriptor(jdata):
5757
seed = jdata['seed']
5858
descriptor['type'] = 'se_a'
5959
descriptor['sel'] = jdata['sel_a']
60-
descriptor['rcut'] = jdata['rcut']
6160
if j_have(jdata, 'rcut_smth') :
62-
descriptor['rcut_r_smth'] = jdata['rcut_smth']
61+
descriptor['rcut_smth'] = jdata['rcut_smth']
6362
else :
64-
descriptor['rcut_r_smth'] = descriptor['rcut']
63+
descriptor['rcut_smth'] = descriptor['rcut']
64+
descriptor['rcut'] = jdata['rcut']
6565
descriptor['neuron'] = j_must_have (jdata, 'filter_neuron')
6666
descriptor['axis_neuron'] = j_must_have_d (jdata, 'axis_neuron', ['n_axis_neuron'])
6767
descriptor['resnet_dt'] = False
@@ -128,9 +128,8 @@ def _training(jdata):
128128
training['numb_test'] = j_must_have (jdata, 'numb_test')
129129
training['save_freq'] = j_must_have (jdata, 'save_freq')
130130
training['save_ckpt'] = j_must_have (jdata, 'save_ckpt')
131-
training['display_in_training'] = j_must_have (jdata, 'disp_training')
132-
training['timing_in_training'] = j_must_have (jdata, 'time_training')
133-
training['profiling'] = False
131+
training['disp_training'] = j_must_have (jdata, 'disp_training')
132+
training['time_training'] = j_must_have (jdata, 'time_training')
134133
if j_have (jdata, 'profiling') :
135134
training['profiling'] = jdata['profiling']
136135
if training['profiling'] :

0 commit comments

Comments
 (0)