예제 #1
0
def run_gpe_parmap_noncum(db, trait_type, traits, init_year, end_year, init_month=1, end_month=1, mark=False):
    """
    Runs the GPE over time for the given traits and time steps. At each timestep, the traits are updated via a parallel pool map function.
    """
    mapfunc1 = lambda x: TemporalGPE_NonCum(trait_type, x)
    gpes_list = parmap(mapfunc1, traits)
    current_time = datetime.now()
    for (time_0, time_1) in step_thru_qtrs(init_year, end_year, init_month, end_month):
#    for start_year, start_month in qtr_year_iter(init_year, end_year):
        # at each timestep, have threads go after a work queue with gpe updates
        logging.info("Updating GPE at time {}".format(time_0))
        logging.info("loading pops...")
        if mark:
            anc_pop, desc_pop = get_anc_dec_mark(db, time_0, time_1, limit = None)
#            anc_pop, desc_pop = load_anc_dec(start_date, indir = _mark_dir)
        else:
            anc_pop, desc_pop = get_anc_noncum(db, time_0, time_1, limit = None)
#            anc_pop, desc_pop = load_anc_dec(start_date, indir = _noncum_dir)
        logging.info("anc pop size: {}, desc pop size: {}".format(len(anc_pop), len(desc_pop)))
        def mapfunc(gpe_computer):
            logging.info("Updating trait {}...".format(gpe_computer.trait))
            gpe_computer.update(anc_pop, desc_pop)
            return gpe_computer
        gpes_list = parmap(mapfunc, gpes_list)
        nxt_time = datetime.now()
        logging.info("elapsed: {}".format(nxt_time - current_time))
        current_time = nxt_time
    gpes = {computer.trait: computer.gpes for computer in gpes_list}
    return gpes
예제 #2
0
def run_gpe_parmap(db, trait_type, traits, init_year, end_year, init_month=1, end_month=1, debug=True):
    """
    Runs the GPE over time for the given traits and time steps. At each timestep, the traits are updated via a parallel pool map function.
    """
    init_pop = load_pop(datetime(init_year, init_month, 1))
    mapfunc1 = lambda x: TemporalGPE(trait_type, x, init_pop)
    gpes_list = parmap(mapfunc1, traits)
    current_time = datetime.now()
    for start_year, start_month in qtr_year_iter(init_year, end_year):
        # at each timestep, have threads go after a work queue with gpe updates
        start_date = datetime(start_year, start_month, 1) # The date on which this time step begins.
        logging.info("Updating GPE at time {}".format(start_date))
        logging.info("loading pop...")
        nxt_pop = load_pop(start_date) # nxt_pop holds the descendant population
        logging.info("pop size: {}".format(len(nxt_pop)))
        def mapfunc(gpe_computer):
            logging.info("Updating trait {}...".format(gpe_computer.trait))
            gpe_computer.update(nxt_pop)
            return gpe_computer
        gpes_list = parmap(mapfunc, gpes_list)
        nxt_time = datetime.now()
        logging.info("elapsed: {}".format(nxt_time - current_time))
        current_time = nxt_time
    gpes = {computer.trait: computer.gpes for computer in gpes_list}
    return gpes