def test_apply_strategy(self): if self.scheme.movers == {}: print "Full support of MoveStrategy implemented?" print "Time to remove legacy from tests." else: self.scheme.movers = {} shoot_strat_1 = OneWayShootingStrategy( ensembles=self.scheme.network.sampling_transitions[0].ensembles, replace=False ) shoot_strat_2 = OneWayShootingStrategy( ensembles=( [self.scheme.network.sampling_transitions[0].ensembles[-1]] + self.scheme.network.sampling_transitions[1].ensembles ), replace=False ) shoot_strat_3 = OneWayShootingStrategy(replace=True) self.scheme.apply_strategy(shoot_strat_1) assert_items_equal(self.scheme.movers.keys(), ['shooting']) assert_equal(len(self.scheme.movers['shooting']), 3) self.scheme.apply_strategy(shoot_strat_2) assert_items_equal(self.scheme.movers.keys(), ['shooting']) assert_equal(len(self.scheme.movers['shooting']), 7) old_movers = copy.copy(self.scheme.movers['shooting']) self.scheme.apply_strategy(shoot_strat_3) assert_items_equal(self.scheme.movers.keys(), ['shooting']) assert_equal(len(self.scheme.movers['shooting']), 7) new_movers = self.scheme.movers['shooting'] for (o, n) in zip(old_movers, new_movers): assert_equal(o is n, False) shoot_strat_3.replace_signatures = True self.scheme.apply_strategy(shoot_strat_3) assert_equal(len(self.scheme.movers['shooting']), 6) self.scheme.movers = {} shoot_strat_1.set_replace(True) self.scheme.apply_strategy(shoot_strat_1) assert_equal(len(self.scheme.movers['shooting']), 3) old_movers = copy.copy(self.scheme.movers['shooting']) shoot_strat_3.replace_signatures = False self.scheme.apply_strategy(shoot_strat_3) assert_equal(len(self.scheme.movers['shooting']), 6) new_movers = self.scheme.movers['shooting'] for (o, n) in zip(old_movers, new_movers): assert_equal(o is n, False)
def test_sanity_check_duplicated_movers(self): ensemble_subset = self.scheme.network.sampling_transitions[0].ensembles self.scheme.append( [OneWayShootingStrategy(), OrganizeByMoveGroupStrategy()]) root = self.scheme.move_decision_tree() self.scheme.movers['foo'] = [self.scheme.movers['shooting'][0]] self.scheme.sanity_check()
def test_sanity_check_unused_sampling(self): ensemble_subset = self.scheme.network.sampling_transitions[0].ensembles self.scheme.append([ OneWayShootingStrategy(ensembles=ensemble_subset), OrganizeByMoveGroupStrategy() ]) root = self.scheme.move_decision_tree() self.scheme.sanity_check()
def test_sanity_check_sane(self): self.scheme.append([ NearestNeighborRepExStrategy(), OneWayShootingStrategy(), OrganizeByMoveGroupStrategy() ]) root = self.scheme.move_decision_tree() self.scheme.sanity_check()
def test_sanity_check_choice_prob_fails(self): self.scheme.append([NearestNeighborRepExStrategy(), OneWayShootingStrategy(), OrganizeByMoveGroupStrategy()]) root = self.scheme.move_decision_tree() key0 = self.scheme.choice_probability.keys()[0] self.scheme.choice_probability[key0] = 0.0 self.scheme.sanity_check()
def test_append_groups_same_custom_level(self): shootstrat = OneWayShootingStrategy() repexstrat = NearestNeighborRepExStrategy() defaultstrat = OrganizeByMoveGroupStrategy() assert_equal(len(list(self.scheme.strategies.keys())), 0) self.scheme.append([shootstrat, repexstrat, defaultstrat], 60) strats = self.scheme.strategies assert_equal(len(list(strats.keys())), 1) assert_items_equal(strats[60], [shootstrat, repexstrat, defaultstrat])
def test_append_group_different_custom_levels(self): shootstrat = OneWayShootingStrategy() repexstrat = NearestNeighborRepExStrategy() defaultstrat = OrganizeByMoveGroupStrategy() assert_equal(len(list(self.scheme.strategies.keys())), 0) self.scheme.append([shootstrat, repexstrat, defaultstrat], [45, 55, 65]) strats = self.scheme.strategies assert_equal(len(list(strats.keys())), 3) for (k, v) in [(45, shootstrat), (55, repexstrat), (65, defaultstrat)]: assert_in(v, strats[k])
def setup(self): self.HAS_TQDM = paths.progress.HAS_TQDM paths.progress.HAS_TQDM = False paths.InterfaceSet._reset() cvA = paths.FunctionCV(name="xA", f=lambda s: s.xyz[0][0]) cvB = paths.FunctionCV(name="xB", f=lambda s: -s.xyz[0][0]) state_A = paths.CVDefinedVolume(cvA, float("-inf"), -0.5).named("A") state_B = paths.CVDefinedVolume(cvB, float("-inf"), -0.5).named("B") interfaces_A = paths.VolumeInterfaceSet(cvA, float("-inf"), [-0.5, -0.3]) network = paths.MISTISNetwork([(state_A, interfaces_A, state_B)]) self.scheme = MoveScheme(network) self.scheme.append(OneWayShootingStrategy()) self.scheme.append(NearestNeighborRepExStrategy()) self.scheme.append(OrganizeByMoveGroupStrategy()) root_mover = self.scheme.move_decision_tree() path_sim_mover = paths.PathSimulatorMover(root_mover, None) null_mover = paths.IdentityPathMover(counts_as_trial=False) ens_0 = network.sampling_ensembles[0] ens_1 = network.sampling_ensembles[1] # acc repex ens1-2 # acc fwd ens1 # acc bkwd ens2 # rej bkwd ens1 # rej repex ens1-2 step_info = [(1, True, path_sim_mover, 'repex', [ens_0, ens_1], None), (2, True, path_sim_mover, 'shooting', [ens_0], 0), (3, True, path_sim_mover, 'shooting', [ens_1], 1), (4, False, path_sim_mover, 'shooting', [ens_0], 1), (5, False, path_sim_mover, 'repex', [ens_0, ens_1], None)] self.steps = [_make_acceptance_mock_step(*info) for info in step_info] self.null_mover_6 = _make_null_mover_step(6, path_sim_mover, null_mover) self.null_mover_change_key = [(None, str([path_sim_mover, [None]]))] acceptance_empty = MoveAcceptanceAnalysis(self.scheme) acceptance = MoveAcceptanceAnalysis(self.scheme) acceptance.add_steps(self.steps) acceptance_null = MoveAcceptanceAnalysis(self.scheme) acceptance_null.add_steps(self.steps + [self.null_mover_6]) self.analysis = { 'empty': acceptance_empty, 'normal': acceptance, 'with_null': acceptance_null }
def test_append_groups_default_levels(self): shootstrat = OneWayShootingStrategy() repexstrat = NearestNeighborRepExStrategy() defaultstrat = OrganizeByMoveGroupStrategy() assert_equal(len(list(self.scheme.strategies.keys())), 0) self.scheme.append([shootstrat, repexstrat, defaultstrat]) strats = self.scheme.strategies assert_equal(len(list(strats.keys())), 3) pairs = [(levels.MOVER, shootstrat), (levels.SIGNATURE, repexstrat), (levels.GLOBAL, defaultstrat)] for (k, v) in pairs: assert_in(v, strats[k])
def test_select_movers(self): self.scheme.append([ OneWayShootingStrategy(), NearestNeighborRepExStrategy(), OrganizeByMoveGroupStrategy() ]) root = self.scheme.move_decision_tree() some_shooters = self.scheme.movers['shooting'][0:2] movers = self.scheme._select_movers('shooting') assert_equal(movers, self.scheme.movers['shooting']) movers = self.scheme._select_movers(some_shooters) assert_equal(movers, some_shooters) movers = self.scheme._select_movers(some_shooters[0]) assert_equal(movers, [some_shooters[0]])
def test_apply_strategy(self): if self.scheme.movers == {}: print("Full support of MoveStrategy implemented?") print("Time to remove legacy from tests.") else: self.scheme.movers = {} shoot_strat_1 = OneWayShootingStrategy( ensembles=self.scheme.network.sampling_transitions[0].ensembles, replace=False ) shoot_strat_2 = OneWayShootingStrategy( ensembles=( [self.scheme.network.sampling_transitions[0].ensembles[-1]] + self.scheme.network.sampling_transitions[1].ensembles ), replace=False ) shoot_strat_3 = OneWayShootingStrategy(replace=True) self.scheme.apply_strategy(shoot_strat_1) assert_items_equal(list(self.scheme.movers.keys()), ['shooting']) assert_equal(len(self.scheme.movers['shooting']), 3) self.scheme.apply_strategy(shoot_strat_2) assert_items_equal(list(self.scheme.movers.keys()), ['shooting']) assert_equal(len(self.scheme.movers['shooting']), 7) old_movers = copy.copy(self.scheme.movers['shooting']) self.scheme.apply_strategy(shoot_strat_3) assert_items_equal(list(self.scheme.movers.keys()), ['shooting']) assert_equal(len(self.scheme.movers['shooting']), 7) new_movers = self.scheme.movers['shooting'] for (o, n) in zip(old_movers, new_movers): assert_equal(o is n, False) shoot_strat_3.replace_signatures = True self.scheme.apply_strategy(shoot_strat_3) assert_equal(len(self.scheme.movers['shooting']), 6) self.scheme.movers = {} shoot_strat_1.set_replace(True) self.scheme.apply_strategy(shoot_strat_1) assert_equal(len(self.scheme.movers['shooting']), 3) old_movers = copy.copy(self.scheme.movers['shooting']) shoot_strat_3.replace_signatures = False self.scheme.apply_strategy(shoot_strat_3) assert_equal(len(self.scheme.movers['shooting']), 6) new_movers = self.scheme.movers['shooting'] for (o, n) in zip(old_movers, new_movers): assert_equal(o is n, False)
def test_n_steps_for_trials(self): self.scheme.append([ OneWayShootingStrategy(), NearestNeighborRepExStrategy(), OrganizeByMoveGroupStrategy() ]) # we should have 6 shooters and 4 repex movers, but default strategy # means that have the probability of selecting repex; so we get # a shooting move 75% of the time root = self.scheme.move_decision_tree() some_shooters = self.scheme.movers['shooting'][0:2] assert_almost_equal(self.scheme.n_steps_for_trials('shooting', 100), old_div(400.0, 3.0)) assert_almost_equal(self.scheme.n_steps_for_trials(some_shooters, 100), 400.0) assert_almost_equal( self.scheme.n_steps_for_trials(some_shooters[0], 100), 800.0)
def test_move_decision_tree(self): shoot = OneWayShootingStrategy() repex = NearestNeighborRepExStrategy() default = OrganizeByMoveGroupStrategy() self.scheme.append([default, shoot, repex]) assert_equal(self.scheme.root_mover, None) root = self.scheme.move_decision_tree() assert_not_equal(self.scheme.root_mover, None) assert_equal(len(root.movers), 2) names = ['ShootingChooser', 'RepexChooser'] name_dict = {root.movers[i].name: i for i in range(len(root.movers))} for name in names: assert_in(name, list(name_dict.keys())) assert_equal(len(root.movers[name_dict['ShootingChooser']].movers), 6) assert_equal(len(root.movers[name_dict['RepexChooser']].movers), 4) new_root = self.scheme.move_decision_tree() assert_is(new_root, root) new_root = self.scheme.move_decision_tree(rebuild=True) assert_is_not(new_root, root)
def test_select_movers_no_choice_probability(self): self.scheme.append( [OneWayShootingStrategy(), OrganizeByMoveGroupStrategy()]) movers = self.scheme._select_movers('shooting')