Skip to content

Commit ffbf6c5

Browse files
committed
cleanup; start to tests move scheme compiling
1 parent ddc6a17 commit ffbf6c5

5 files changed

Lines changed: 90 additions & 16 deletions

File tree

‎paths_cli/compiling/schemes.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
default=None)
1717

1818

19-
build_spring_shooting_scheme = SchemeCompilerPlugin(
19+
SPRING_SHOOTING_PLUGIN = SchemeCompilerPlugin(
2020
builder=Builder('openpathsampling.SpringShootingMoveScheme'),
2121
parameters=[
2222
NETWORK_PARAMETER,
@@ -32,23 +32,23 @@ def __init__(self, scheme_class, default_global_strategy):
3232
self.scheme_class = scheme_class
3333
self.default_global_strategy = default_global_strategy
3434

35-
def __call__(self, dct):
35+
def __call__(self, **dct):
3636
from openpathsampling import strategies
3737
if self.default_global_strategy:
3838
global_strategy = [strategies.OrganizeByMoveGroupStrategy()]
3939
else:
4040
global_strategy = []
4141

4242
builder = Builder(self.scheme_class)
43-
strategies = dct.pop('strategies', []) + global_strategy
44-
scheme = builder(dct)
43+
strategies = global_strategy + dct.pop('strategies', [])
44+
scheme = builder(**dct)
4545
for strat in strategies:
4646
scheme.append(strat)
4747
# self.logger.debug(f"strategies: {scheme.strategies}")
4848
return scheme
4949

5050

51-
build_one_way_shooting_scheme = SchemeCompilerPlugin(
51+
ONE_WAY_SHOOTING_SCHEME_PLUGIN = SchemeCompilerPlugin(
5252
builder=BuildSchemeStrategy('openpathsampling.OneWayShootingMoveScheme',
5353
default_global_strategy=False),
5454
parameters=[
@@ -60,7 +60,7 @@ def __call__(self, dct):
6060
name='one-way-shooting',
6161
)
6262

63-
build_scheme = SchemeCompilerPlugin(
63+
MOVESCHEME_PLUGIN = SchemeCompilerPlugin(
6464
builder=BuildSchemeStrategy('openpathsampling.MoveScheme',
6565
default_global_strategy=True),
6666
parameters=[

‎paths_cli/compiling/strategies.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def _group_parameter(group_name):
1515
description="the group name for these movers")
1616

1717
# TODO: maybe this moves into shooting once we have the metadata?
18-
SP_SELECTOR_PARAMETER = Parameter('selector', shooting_selector_compiler)
18+
SP_SELECTOR_PARAMETER = Parameter('selector', shooting_selector_compiler,
19+
default=None)
1920

2021
ENGINE_PARAMETER = Parameter('engine', compiler_for('engine'),
2122
description="the engine for moves of this "

‎paths_cli/compiling/volumes.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# TODO: extra function for volumes should not be necessary as of OPS 2.0
99
def cv_volume_build_func(**dct):
10-
# TODO: this should take dict, not kwargs
1110
import openpathsampling as paths
1211
cv = dct['cv']
1312
builder = paths.CVDefinedVolume

‎paths_cli/param_core.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ def get(self, name):
115115
storage = Storage(name, self.mode)
116116
return storage
117117

118-
@classmethod
119-
def cleanup(cls):
120-
if cls.has_simstore_patch:
121-
import openpathsampling as paths
122-
from openpathsampling.experimental.storage.monkey_patches \
123-
import unpatch
124-
paths = unpatch(paths)
125-
126118

127119
class OPSStorageLoadNames(AbstractLoader):
128120
"""Simple loader that expects its input to be a name or index.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import pytest
2+
3+
from paths_cli.compiling.schemes import *
4+
import openpathsampling as paths
5+
6+
from unittest.mock import patch
7+
from openpathsampling.tests.test_helpers import make_1d_traj
8+
from paths_cli.tests.compiling.utils import mock_compiler
9+
10+
_COMPILERS_LOC = 'paths_cli.compiling.root_compiler._COMPILERS'
11+
12+
@pytest.fixture
13+
def tps_compilers_and_traj(tps_network_and_traj, flat_engine):
14+
network, traj = tps_network_and_traj
15+
compilers = {
16+
'network': mock_compiler('network', None, {'tps_network': network}),
17+
'engine': mock_compiler('engine', None,
18+
{'flat_engine': flat_engine}),
19+
}
20+
return compilers, traj
21+
22+
@pytest.fixture
23+
def tis_compilers_and_traj(tps_network_and_traj, tis_network, flat_engine):
24+
_, traj = tps_network_and_traj
25+
compilers = {
26+
'network': mock_compiler('network', None,
27+
{'tis_network': tis_network}),
28+
'engine': mock_compiler('engine', None,
29+
{'flat_engine': flat_engine}),
30+
}
31+
return compilers, traj
32+
33+
def test_build_spring_shooting_scheme(tps_compilers_and_traj):
34+
paths.InterfaceSet._reset()
35+
36+
compilers, traj = tps_compilers_and_traj
37+
dct = {'network': 'tps_network', 'k_spring': 0.5, 'delta_max': 100,
38+
'engine': 'flat_engine'}
39+
with patch.dict(_COMPILERS_LOC, compilers):
40+
scheme = SPRING_SHOOTING_PLUGIN(dct)
41+
42+
assert isinstance(scheme, paths.SpringShootingMoveScheme)
43+
# smoke test that it can build its tree and load init conds
44+
scheme.move_decision_tree()
45+
_ = scheme.initial_conditions_from_trajectories(traj)
46+
47+
48+
@pytest.mark.parametrize('network', ['tps', 'tis'])
49+
def test_build_one_way_shooting_scheme(network, tps_compilers_and_traj,
50+
tis_compilers_and_traj):
51+
paths.InterfaceSet._reset()
52+
compilers, traj = {'tps': tps_compilers_and_traj,
53+
'tis': tis_compilers_and_traj}[network]
54+
dct = {'network': f"{network}_network", 'engine': 'flat_engine'}
55+
with patch.dict(_COMPILERS_LOC, compilers):
56+
scheme = ONE_WAY_SHOOTING_SCHEME_PLUGIN(dct)
57+
58+
assert isinstance(scheme, paths.OneWayShootingMoveScheme)
59+
# smoke test that it can build its tree and load init conds
60+
scheme.move_decision_tree()
61+
_ = scheme.initial_conditions_from_trajectories(traj)
62+
63+
64+
def test_movescheme_plugin(tis_compilers_and_traj, flat_engine):
65+
paths.InterfaceSet._reset()
66+
compilers, traj = tis_compilers_and_traj
67+
68+
dct = {'network': 'tis_network',
69+
'strategies': [
70+
{'type': ''},
71+
{'type': ''},
72+
{'type': ''},
73+
{'type': ''},
74+
]}
75+
pytest.skip()
76+
with patch.dict(_COMPILERS_LOC, compilers):
77+
scheme = MOVESCHEME_PLUGIN(dct)
78+
79+
assert isinstance(scheme, paths.MoveScheme)
80+
# smoke test that it can build its tree and load init conds
81+
scheme.move_decision_tree()
82+
_ = scheme.initial_conditions_from_trajectories(traj)

0 commit comments

Comments
 (0)