Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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: