def _make_null_mover_step(mccycle, path_sim_mover, null_mover): empty_sample_set = paths.SampleSet([]) change = paths.PathSimulatorMoveChange( mover=path_sim_mover, subchange=null_mover.move(empty_sample_set)) step = paths.MCStep(mccycle=mccycle, active=empty_sample_set, change=change) return step
def _make_acceptance_mock_step(mccycle, accepted, path_sim_mover, move_type, mover_sig, submover_num=None): root_mover = path_sim_mover.mover chooser_names = {m.name[:-7].lower(): m for m in root_mover.movers} chooser = chooser_names[move_type] sig_to_mover = { frozenset(m.ensemble_signature[0]): m for m in chooser.movers } # group_mover = chooser.movers[mover_num] group_mover = sig_to_mover[frozenset(mover_sig)] Change = { True: paths.AcceptedSampleMoveChange, False: paths.RejectedSampleMoveChange }[accepted] # foo here is because we need non-empty samples to show that we're # actually accepted or not (WHY?!?!?) if submover_num is not None: submover = group_mover.movers[submover_num] submover_change = Change(samples=['foo'], mover=submover) group_mover_change = paths.RandomChoiceMoveChange( subchange=submover_change, mover=group_mover) else: submover_change = None group_mover_change = Change(samples=['foo'], mover=group_mover) chooser_change = paths.RandomChoiceMoveChange(subchange=group_mover_change, mover=chooser) root_mover_change = paths.RandomChoiceMoveChange(subchange=chooser_change, mover=root_mover) path_sim_change = paths.PathSimulatorMoveChange( subchange=root_mover_change, mover=path_sim_mover) step = paths.MCStep(mccycle=mccycle, active=paths.SampleSet([]), change=path_sim_change) return step
def run(self, step_info_list): """ Parameters ---------- step_info_list : list of tuple (replica, trial_trajectory, shooting_point_index, accepted) or (replica, one_way_trial_segment, shooting_point_index, accepted, direction) """ mcstep = None if self.step == 0: if self.storage is not None: self.storage.save(self.scheme) self.save_initial_step() for step_info in step_info_list: self.step += 1 if len(step_info ) == 4 and not self.mover.pre_joined: # pragma: no-cover raise RuntimeError( "Shooting trial trajectories not pre-joined: " + "step_info must be (replica, trial_segment, " + "shooting_pt_idx, accepted, direction)") replica = step_info[0] trial_trajectory = step_info[1] shooting_point_index = step_info[2] accepted = step_info[3] direction = None if len(step_info) == 5: direction = step_info[4] input_sample = self.sample_set[replica] if shooting_point_index < 0: shooting_point_index += len(input_sample.trajectory) shooting_point = input_sample.trajectory[shooting_point_index] subchange = self.mover.move(input_sample, trial_trajectory, shooting_point, accepted, direction) change = paths.PathSimulatorMoveChange( subchange=subchange, mover=self._path_sim_mover, details=paths.MoveDetails(step=self.step)) samples = change.results new_sampleset = self.sample_set.apply_samples(samples) mcstep = paths.MCStep(simulation=self, mccycle=self.step, previous=self.sample_set, active=new_sampleset, change=change) if self.storage is not None: self.storage.steps.save(mcstep) if self.step % self.save_frequency == 0: self.sample_set.sanity_check() self.sync_storage() self.sample_set = new_sampleset self.sync_storage()