def basinhopping():
    logger.info('Eon version %s', version())
    # First of all, does the root directory even exist?
    if not os.path.isdir(config.path_root):
        logger.critical("Root directory does not exist")
        sys.exit(1)

    # load metadata
    bhstates = BHStates()

    if os.path.isfile("wuid.dat"):
        wuid_file = open("wuid.dat")
        wuid = int(wuid_file.readline().strip())
        wuid_file.close()
    else:
        wuid = 0

    # get communicator
    comm = communicator.get_communicator()

    # Register all the results. There is  no need to ever discard found
    # processes like we do with akmc. There is no confidence to calculate.
    register_results(comm, bhstates)

    wuid = make_searches(comm, wuid, bhstates)

    wuid_file = open("wuid.dat","w")
    wuid_file.write("%i\n" % wuid)
    wuid_file.close()

    io.save_prng_state()
Example #2
0
def basinhopping():
    logger.info('Eon version %s', version())
    # First of all, does the root directory even exist?
    if not os.path.isdir(config.path_root):
        logger.critical("Root directory does not exist")
        sys.exit(1)

    # load metadata
    bhstates = BHStates()

    if os.path.isfile("wuid.dat"):
        wuid_file = open("wuid.dat")
        wuid = int(wuid_file.readline().strip())
        wuid_file.close()
    else:
        wuid = 0

    # get communicator
    comm = communicator.get_communicator()

    # Register all the results. There is  no need to ever discard found
    # processes like we do with akmc. There is no confidence to calculate.
    register_results(comm, bhstates)

    wuid = make_searches(comm, wuid, bhstates)

    wuid_file = open("wuid.dat", "w")
    wuid_file.write("%i\n" % wuid)
    wuid_file.close()

    io.save_prng_state()
Example #3
0
def parallelreplica():
    logger.info('Eon version: %s', version())
    # First of all, does the root directory even exist?
    if not os.path.isdir(config.path_root):
        logger.critical("Root directory does not exist")
        sys.exit(1)

    # load metadata
    start_state_num, time, wuid = get_pr_metadata()
    logger.info("Simulation time: %e s", time)
    states = get_statelist()
    current_state = states.get_state(start_state_num)

    # get communicator
    comm = communicator.get_communicator()

    # Register all the results. There is no need to ever discard processes
    # like we do with akmc. There is no confidence to calculate.
    num_registered, transition, sum_spdup = register_results(
        comm, current_state, states)

    if num_registered >= 1:
        avg_spdup = sum_spdup / num_registered
        logger.info("Total speedup: %f", avg_spdup)

    if transition:
        current_state, previous_state = step(time, current_state, states,
                                             transition)
        time += transition['time']

    logger.info("Time in current state: %e s", current_state.get_time())
    logger.info("Simulation time: %e s", time)
    wuid = make_searches(comm, current_state, wuid)

    # Write out metadata. XXX:ugly
    metafile = os.path.join(config.path_results, 'info.txt')
    parser = ConfigParser.RawConfigParser()
    write_pr_metadata(parser, current_state.number, time, wuid)
    parser.write(open(metafile, 'w'))
    io.save_prng_state()
def parallelreplica():
    logger.info('Eon version: %s', version())
    # First of all, does the root directory even exist?
    if not os.path.isdir(config.path_root):
        logger.critical("Root directory does not exist")
        sys.exit(1)

    # load metadata
    start_state_num, time, wuid = get_pr_metadata()
    logger.info("Simulation time: %e s", time)
    states = get_statelist() 
    current_state = states.get_state(start_state_num)

    # get communicator
    comm = communicator.get_communicator()

    # Register all the results. There is no need to ever discard processes
    # like we do with akmc. There is no confidence to calculate.
    num_registered, transition, sum_spdup = register_results(comm, current_state, states)
   
    if num_registered >= 1:
        avg_spdup = sum_spdup/num_registered
        logger.info("Total speedup: %f",avg_spdup)

    if transition:
        current_state, previous_state = step(time, current_state, states, transition)
        time += transition['time']

    logger.info("Time in current state: %e s", current_state.get_time()) 
    logger.info("Simulation time: %e s", time)
    wuid = make_searches(comm, current_state, wuid)

    # Write out metadata. XXX:ugly
    metafile = os.path.join(config.path_results, 'info.txt')
    parser = ConfigParser.RawConfigParser() 
    write_pr_metadata(parser, current_state.number, time, wuid)
    parser.write(open(metafile, 'w'))
    io.save_prng_state()
Example #5
0
File: akmc.py Project: HaoLiSky/EON
def akmc(config, steps=0):
    """Poll for status of AKMC clients and possibly make KMC steps.

    Returns the number of KMC steps in the current run at the end of
    this function. The argument "steps" gives the number of KMC steps
    done before calling this function, defaulting to zero.

    """
    #log version information
    logger.info('Eon version %s', version())
    # Here's what this does:
    # 1) Read in the state of our calculation from last time
    # 2) Initialize necessary data structures (statelist, communicator, displace)
    # 3) Get any results that have come in
    # 4) Possibly take a KMC step
    # 5) Make new work units
    # 6) Write out the state of the simulation

    # First of all, does the root directory even exist?
    if not os.path.isdir(config.path_root):
        logger.critical("Root directory does not exist, as such the " \
                        "reactant cannot exist. Exiting...")
        sys.exit(1)

    # If we are saving debug results, create the directory if it does not exist.
    if config.debug_keep_all_results:
        rp = os.path.join(config.path_root,config.debug_results_path)
        if not os.path.isdir(rp):
            os.mkdir(rp)

    # Define constants. 
    kT = config.main_temperature/11604.5 #in eV

    # Load metadata, the state list, and the current state.
    start_state_num, time, previous_state_num, first_run, previous_temperature = get_akmc_metadata()

    if first_run:
        previous_temperature = config.main_temperature

    # Did the temperature change? Then the existing superbasins are invalid now.
    if abs(previous_temperature - config.main_temperature) > 1e-6:
        # Remove superbasin data.
        if os.path.isdir(config.sb_path):
            shutil.rmtree(config.sb_path)
        state_dirs = os.listdir(config.path_states)
        for state_dir in state_dirs:
            if state_dir == 'state_table':
                continue
            superbasin_file = os.path.join(config.path_states, state_dir, config.sb_state_file)
            if os.path.isfile(superbasin_file):
                os.remove(superbasin_file)
        # Keep the new temperature.
        previous_temperature = config.main_temperature

    states = get_statelist(kT) 
    current_state = states.get_state(start_state_num)
    if previous_state_num == -1:
        previous_state = current_state
    else:
        previous_state = states.get_state(previous_state_num)

    # If the Novotny-based superbasining scheme is being used, initialize it.
    if config.sb_on:
        superbasining = get_superbasin_scheme(states)
        sb = superbasining.get_containing_superbasin(current_state)
        # If we are exploring states in a superbasin, we will always
        # explore the state with the lowest confidence.
        if sb:
            explore_state = sb.get_lowest_confidence_state()
            previous_state = explore_state # TODO: perhaps there is a better value for previous_state?
        else:
            explore_state = current_state
    else:
        superbasining = None
        sb = None
        explore_state = current_state

    state_explorer = explorer.get_minmodexplorer()(states, previous_state,
                                                   explore_state, superbasin=sb)
    state_explorer.explore()

    # Take a KMC step, if it's time.
    current_state, previous_state, time, steps = kmc_step(current_state, states, time, kT, superbasining, steps)

    # Write out metadata.
    metafile = os.path.join(config.path_results, 'info.txt')
    parser = ConfigParser.RawConfigParser() 

    if previous_state.number != current_state.number:
        previous_state_num = previous_state.number

    write_akmc_metadata(parser, current_state.number, time, previous_state_num, previous_temperature)

    parser.write(open(metafile, 'w')) 

    io.save_prng_state()

    return steps