Ejemplo n.º 1
0
    def test_recycle(self):
        segments = [
            self.segment(0.0, 1.5, weight=0.5),
            self.segment(0.0, 0.5, weight=0.5)
        ]
        tstate = TargetState('recycle', [1.5], 0)
        istate = InitialState(0, 0, 0, pcoord=[0.0])

        self.we_driver.new_iteration(initial_states=[istate],
                                     target_states=[tstate])
        n_needed = self.we_driver.assign(segments)
        assert n_needed == 0
        self.we_driver.construct_next()

        n_recycled = len(list(self.we_driver.recycling_segments))
        assert n_recycled == 1

        assert len(self.we_driver.next_iter_binning[0]) == 4
        assert len(self.we_driver.next_iter_binning[1]) == 0
        assert abs(
            sum(seg.weight for seg in self.we_driver.next_iter_binning[0]) -
            1.0) < 4 * EPS
        assert numpy.allclose(
            [seg.weight for seg in self.we_driver.next_iter_binning[0]],
            [0.25 for _i in xrange(4)])
        assert segments[0].endpoint_type == Segment.SEG_ENDPOINT_RECYCLED
Ejemplo n.º 2
0
    def pre_we(self):
        starttime = time.time()
        segments = self.sim_manager.segments.values()
        bin_mapper = self.system.bin_mapper
        self.find_mappers()

        # For now, assume one wexploreMapper
        wexploreMapper = self.wexploreMappers[0]['base_mapper']

        final_pcoords = np.empty((len(segments), self.system.pcoord_ndim), dtype=self.system.pcoord_dtype)

        for iseg, segment in enumerate(segments):
            final_pcoords[iseg] = segment.pcoord[-1,:]

        hash_init = wexploreMapper.last_graph
        kwargs = {'add_bins': True, 'n_regions': self.system.n_regions}
        assignments = bin_mapper.assign(final_pcoords, **kwargs)

        # Re-assign segments to new bins if bin_mapper changes
        if wexploreMapper.last_graph != hash_init:
            # The mapper has updated; force an update to the system mapper.
            bin_mapper.refresh_mappers()
            self.target_counts()

            # Reset we_driver internal data structures.  This includes sending in the target states,
            # as the bins have changed (we also need to feed in the initial states).
            target_states = []
            tstates = self.system.tstates
            tstates_strio = cStringIO.StringIO('\n'.join(tstates).replace(',', ' '))
            target_states.extend(TargetState.states_from_file(tstates_strio, self.system.pcoord_dtype))
            initial_states = []
            self.data_manager.save_target_states(target_states)
            #self.sim_manager.report_target_states(target_states)
            for key,value in self.we_driver.avail_initial_states.iteritems():
                initial_states.append(value)
            self.we_driver.new_iteration(target_states=target_states, initial_states=initial_states)

            # Re-assign segments
            self.we_driver.assign(segments)

        # Reset target counts to account for new iteration.
        self.target_counts(coords=final_pcoords, startup=False)

        endtime = time.time()

        # Report level statistics
        s = 1
        westpa.rc.pstatus('--wexplore-stats--------------------')
        westpa.rc.pstatus('wallclock time: {:.3f} s'.format(endtime - starttime))
        westpa.rc.pstatus('')
        for li, level in enumerate(wexploreMapper.level_indices):
            s *= wexploreMapper.n_regions[li]
            westpa.rc.pstatus('Level {}: {} cells ({} max)'.format(li, len(level), s))
        westpa.rc.pstatus('------------------------------------')
        westpa.rc.pflush()
Ejemplo n.º 3
0
system = westpa.rc.get_system_driver()
sim_manager = westpa.rc.get_sim_manager()
propagator = westpa.rc.get_propagator()
data_manager = westpa.rc.get_data_manager()
h5file = data_manager.we_h5filename

data_manager.system = system
we_driver = westpa.rc.get_we_driver()

with work_manager:
    if work_manager.is_master:    
        # Process target states
        target_states = []
        if args.tstate_file:
            target_states.extend(TargetState.states_from_file(args.tstate_file, system.pcoord_dtype))
        if args.tstates:
            tstates_strio = cStringIO.StringIO('\n'.join(args.tstates).replace(',', ' '))
            target_states.extend(TargetState.states_from_file(tstates_strio, system.pcoord_dtype))
            del tstates_strio
                    
        # Process basis states
        basis_states = []
        if args.bstate_file:
            basis_states.extend(BasisState.states_from_file(args.bstate_file))
        if args.bstates:
            for bstate_str in args.bstates:
                fields = bstate_str.split(',')
                label=fields[0]
                probability=float(fields[1])
                try:
Ejemplo n.º 4
0
system = westpa.rc.get_system_driver()
sim_manager = westpa.rc.get_sim_manager()
propagator = westpa.rc.get_propagator()
data_manager = westpa.rc.get_data_manager()
h5file = data_manager.we_h5filename

data_manager.system = system
we_driver = westpa.rc.get_we_driver()

with work_manager:
    if work_manager.is_master:
        # Process target states
        target_states = []
        if args.tstate_file:
            target_states.extend(
                TargetState.states_from_file(args.tstate_file,
                                             system.pcoord_dtype))
        if args.tstates:
            tstates_strio = io.StringIO('\n'.join(args.tstates).replace(
                ',', ' '))
            target_states.extend(
                TargetState.states_from_file(tstates_strio,
                                             system.pcoord_dtype))
            del tstates_strio

        # Process basis states
        basis_states = []
        if args.bstate_file:
            basis_states.extend(BasisState.states_from_file(args.bstate_file))
        if args.bstates:
            for bstate_str in args.bstates:
                fields = bstate_str.split(',')
Ejemplo n.º 5
0
     n_iter = data_manager.current_iteration
         
     assert args.mode in ('show', 'replace', 'append')
     if args.mode == 'show':
 
         basis_states = data_manager.get_basis_states(n_iter)
         if basis_states:
             bstate_file = sys.stdout if not args.bstate_file else open(args.bstate_file, 'wt')
             bstate_file.write('# Basis states for iteration {:d}\n'.format(n_iter))
             BasisState.states_to_file(basis_states, bstate_file)
         
         target_states = data_manager.get_target_states(n_iter)
         if target_states:
             tstate_file = sys.stdout if not args.tstate_file else open(args.tstate_file, 'wt')
             tstate_file.write('# Target states for iteration {:d}\n'.format(n_iter))
             TargetState.states_to_file(target_states, tstate_file)
             
     elif args.mode == 'replace':
         seg_index = data_manager.get_seg_index(n_iter)
         if (seg_index['status'] == Segment.SEG_STATUS_COMPLETE).any():
             print('Iteration {:d} has completed segments; applying new states to iteration {:d}'.format(n_iter,n_iter+1))
             n_iter += 1
         
         basis_states = []
         if args.bstate_file:
             basis_states.extend(BasisState.states_from_file(args.bstate_file))
         if args.bstates:
             for bstate_str in args.bstates:
                 fields = bstate_str.split(',')
                 label=fields[0]
                 probability=float(fields[1])