def _get_data(sp, force_new=False): "get solution data from file, or create if necessary" with get_h5_data_file() as f: existed, grp = get_h5_data_group("odu") if force_new or not existed: if existed: grp.v._f_remove() grp.phi_vfi._f_remove() grp.phi_pfi._f_remove() grp.new_v._f_remove() v, phi_vfi, phi_pfi, new_v = _new_solution(sp, f, grp) return v, phi_vfi, phi_pfi, new_v # if we made it here, the group exists and we should try to read # existing solutions try: # Try reading data v = grp.v[:] phi_vfi = grp.phi_vfi[:] phi_pfi = grp.phi_pfi[:] new_v = grp.new_v[:] except: # doesn't exist. Let's create it v, phi_vfi, phi_pfi, new_v = _new_solution(sp, f, grp) return v, phi_vfi, phi_pfi, new_v
def _get_vf_guess(jv, force_new=False): with get_h5_data_file() as f: # See if the jv group already exists group_existed = True try: jv_group = f.getNode("/jv") except: # doesn't exist group_existed = False jv_group = f.create_group("/", "jv", "data for jv.py tests") if force_new or not group_existed: # group doesn't exist, or forced to create new data. # This function updates f in place and returns v_vfi, c_vfi, c_pfi V = _new_solution(jv, f, jv_group) return V # if we made it here, the group exists and we should try to read # existing solutions try: # Try reading vfi if sys.version_info[0] == 2: V = jv_group.V[:] else: # python 3 V = jv_group.V_py3[:] except: # doesn't exist. Let's create it V = _new_solution(jv, f, jv_group) return V
def _get_vfi_pfi_guesses(cp, force_new=False): """ load precomputed vfi/pfi solutions, or compute them if requested or we can't find old ones """ # open the data file with get_h5_data_file() as f: # See if the ifp group already exists group_existed = True try: ifp_group = f.getNode("/ifp") except: # doesn't exist group_existed = False ifp_group = f.create_group("/", "ifp", "data for ifp.py tests") if force_new or not group_existed: # group doesn't exist, or forced to create new data. # This function updates f in place and returns v_vfi, c_vfi, c_pfi v_vfi, c_vfi, c_pfi = _new_solutions(cp, f, ifp_group) # We have what we need, so return return v_vfi, c_pfi # if we made it here, the group exists and we should try to read # existing solutions try: # read in vfi # Try reading vfi c_vfi = ifp_group.c_vfi[:] v_vfi = ifp_group.v_vfi[:] except: # doesn't exist. Let's create it v_vfi, c_vfi = _new_solutions(cp, f, ifp_group, which="vfi") try: # read in pfi # Try reading pfi c_pfi = ifp_group.c_pfi[:] except: # doesn't exist. Let's create it c_pfi = _new_solutions(cp, f, ifp_group, which="pfi") return v_vfi, c_pfi
def _get_price_data(tree, force_new=False): "get price data from file, or create if necessary" with get_h5_data_file() as f: existed, grp = get_h5_data_group("lucastree") if force_new or not existed: if existed: grp.prices._f_remove() prices = _new_solution(tree, f, grp) return prices # if we made it here, the group exists and we should try to read # existing solutions try: # Try reading vfi prices = grp.prices[:] except: # doesn't exist. Let's create it prices = _new_solution(tree, f, grp) return prices
def _get_data(gm, force_new=False): "get solution data from file, or create if necessary" with get_h5_data_file() as f: existed, grp = get_h5_data_group("optgrowth") if force_new or not existed: if existed: grp.w._f_remove() v = _new_solution(gm, f, grp) return v # if we made it here, the group exists and we should try to read # existing solutions try: # Try reading data v = grp.v[:] except: # doesn't exist. Let's create it v = _new_solution(gm, f, grp) return v