|
| 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