1010
1111_COMPILERS_LOC = 'paths_cli.compiling.root_compiler._COMPILERS'
1212
13-
14- def check_unidirectional_tis (results , state_A , state_B , cv ):
15- assert len (results ) == 1
16- trans_info = results ['trans_info' ]
17- assert len (trans_info ) == 1
18- assert len (trans_info [0 ]) == 3
19- trans = trans_info [0 ]
20- assert isinstance (trans , tuple )
21- assert trans [0 ] == state_A
22- assert trans [2 ] == state_B
23- assert isinstance (trans [1 ], paths .VolumeInterfaceSet )
24- ifaces = trans [1 ]
25- assert ifaces .cv == cv
26- assert ifaces .minvals == float ("-inf" )
27- np .testing .assert_allclose (ifaces .maxvals ,
28- [0 , np .pi / 10.0 , np .pi / 5.0 ])
29-
30-
31- def test_mistis_trans_info (cv_and_states ):
13+ @pytest .fixture
14+ def unidirectional_tis_compiler (cv_and_states ):
3215 cv , state_A , state_B = cv_and_states
33- dct = {
34- 'transitions' : [{
35- 'initial_state' : "A" ,
36- 'final_state' : "B" ,
37- 'interfaces' : {
38- 'cv' : 'cv' ,
39- 'minvals' : 'float("-inf")' ,
40- 'maxvals' : "np.array([0, 0.1, 0.2]) * np.pi"
41- }
42- }]
43- }
44- patch_base = 'paths_cli.compiling.networks'
45- compiler = {
46- 'cv' : mock_compiler ('cv' , named_objs = {'cv' : cv }),
47- 'volume' : mock_compiler ('volume' , named_objs = {
48- "A" : state_A , "B" : state_B
49- }),
50- }
51- with mock .patch .dict (_COMPILERS_LOC , compiler ):
52- results = mistis_trans_info (dct )
53-
54- check_unidirectional_tis (results , state_A , state_B , cv )
55- paths .InterfaceSet ._reset ()
56-
57-
58- def test_tis_trans_info (cv_and_states ):
59- cv , state_A , state_B = cv_and_states
60- dct = {
61- 'initial_state' : "A" ,
62- 'final_state' : "B" ,
63- 'interfaces' : {
64- 'cv' : 'cv' ,
65- 'minvals' : 'float("-inf")' ,
66- 'maxvals' : 'np.array([0, 0.1, 0.2]) * np.pi' ,
67- }
68- }
69-
70- compiler = {
16+ return {
7117 'cv' : mock_compiler ('cv' , named_objs = {'cv' : cv }),
7218 'volume' : mock_compiler ('volume' , named_objs = {
7319 "A" : state_A , "B" : state_B
7420 }),
21+ 'interface_set' : mock_compiler (
22+ 'interface_set' ,
23+ type_dispatch = {
24+ 'volume-interface-set' : VOLUME_INTERFACE_SET_PLUGIN
25+ }
26+ ),
7527 }
76- with mock .patch .dict (_COMPILERS_LOC , compiler ):
77- results = tis_trans_info (dct )
7828
79- check_unidirectional_tis (results , state_A , state_B , cv )
80- paths .InterfaceSet ._reset ()
29+ # def check_unidirectional_tis(results, state_A, state_B, cv):
30+ # assert len(results) == 1
31+ # trans_info = results['trans_info']
32+ # assert len(trans_info) == 1
33+ # assert len(trans_info[0]) == 3
34+ # trans = trans_info[0]
35+ # assert isinstance(trans, tuple)
36+ # assert trans[0] == state_A
37+ # assert trans[2] == state_B
38+ # assert isinstance(trans[1], paths.VolumeInterfaceSet)
39+ # ifaces = trans[1]
40+ # assert ifaces.cv == cv
41+ # assert ifaces.minvals == float("-inf")
42+ # np.testing.assert_allclose(ifaces.maxvals,
43+ # [0, np.pi / 10.0, np.pi / 5.0])
44+
45+
46+ # def test_mistis_trans_info(cv_and_states, mistis_dict,
47+ # unidirectional_tis_compiler):
48+ # cv, state_A, state_B = cv_and_states
49+ # patch_base = 'paths_cli.compiling.networks'
50+ # with mock.patch.dict(_COMPILERS_LOC, unidirectional_tis_compiler):
51+ # results = mistis_trans_info(mistis_dict)
52+
53+ # check_unidirectional_tis(results, state_A, state_B, cv)
54+ # paths.InterfaceSet._reset()
55+
56+
57+ # def test_tis_trans_info(cv_and_states):
58+ # cv, state_A, state_B = cv_and_states
59+ # dct = {
60+ # 'initial_state': "A",
61+ # 'final_state': "B",
62+ # 'cv': 'cv',
63+ # 'minvals': 'float("-inf")',
64+ # 'maxvals': 'np.array([0, 0.1, 0.2]) * np.pi',
65+ # }
66+
67+ # compiler = {
68+ # 'cv': mock_compiler('cv', named_objs={'cv': cv}),
69+ # 'volume': mock_compiler('volume', named_objs={
70+ # "A": state_A, "B": state_B
71+ # }),
72+ # 'interface_set': mock_compiler(
73+ # 'interface_set',
74+ # type_dispatch={
75+ # 'volume-interface-set': VOLUME_INTERFACE_SET_PLUGIN
76+ # }
77+ # ),
78+ # }
79+ # with mock.patch.dict(_COMPILERS_LOC, compiler):
80+ # results = tis_trans_info(dct)
81+
82+ # check_unidirectional_tis(results, state_A, state_B, cv)
83+ # paths.InterfaceSet._reset()
8184
8285
8386def test_build_tps_network (cv_and_states ):
@@ -86,17 +89,50 @@ def test_build_tps_network(cv_and_states):
8689 dct = yaml .load (yml , yaml .FullLoader )
8790 compiler = {
8891 'volume' : mock_compiler ('volume' , named_objs = {"A" : state_A ,
89- "B" : state_B }),
92+ "B" : state_B }),
9093 }
9194 with mock .patch .dict (_COMPILERS_LOC , compiler ):
92- network = build_tps_network (dct )
95+ network = TPS_NETWORK_PLUGIN (dct )
9396 assert isinstance (network , paths .TPSNetwork )
9497 assert len (network .initial_states ) == len (network .final_states ) == 1
9598 assert network .initial_states [0 ] == state_A
9699 assert network .final_states [0 ] == state_B
97100
98- def test_build_mistis_network ():
99- pytest .skip ()
100101
101- def test_build_tis_network ():
102- pytest .skip ()
102+ def test_build_mistis_network (cv_and_states , unidirectional_tis_compiler ):
103+ cv , state_A , state_B = cv_and_states
104+ mistis_dict = {
105+ 'interface_sets' : [{
106+ 'initial_state' : "A" ,
107+ 'final_state' : "B" ,
108+ 'cv' : 'cv' ,
109+ 'minvals' : 'float("-inf")' ,
110+ 'maxvals' : "np.array([0, 0.1, 0.2]) * np.pi"
111+ }]
112+ }
113+
114+ with mock .patch .dict (_COMPILERS_LOC , unidirectional_tis_compiler ):
115+ network = MISTIS_NETWORK_PLUGIN (mistis_dict )
116+
117+ assert isinstance (network , paths .MISTISNetwork )
118+ assert len (network .sampling_transitions ) == 1
119+ assert len (network .transitions ) == 1
120+ assert list (network .transitions ) == [(state_A , state_B )]
121+
122+ def test_build_tis_network (cv_and_states , unidirectional_tis_compiler ):
123+ cv , state_A , state_B = cv_and_states
124+ tis_dict = {
125+ 'initial_state' : "A" ,
126+ 'final_state' : "B" ,
127+ 'cv' : "cv" ,
128+ 'minvals' : 'float("inf")' ,
129+ 'maxvals' : "np.array([0, 0.1, 0.2]) * np.pi" ,
130+ }
131+
132+ with mock .patch .dict (_COMPILERS_LOC , unidirectional_tis_compiler ):
133+ network = TIS_NETWORK_PLUGIN (tis_dict )
134+
135+ assert isinstance (network , paths .MISTISNetwork )
136+ assert len (network .sampling_transitions ) == 1
137+ assert len (network .transitions ) == 1
138+ assert list (network .transitions ) == [(state_A , state_B )]
0 commit comments