Skip to content

Commit

Permalink
[DO NOT MERGE]
Browse files Browse the repository at this point in the history
  • Loading branch information
talumbau committed Feb 29, 2024
1 parent ff2eb25 commit a5a2e02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
22 changes: 18 additions & 4 deletions ogcore/SS.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# imports
from re import VERBOSE
import numpy as np
import time
import scipy.optimize as opt
from dask import delayed, compute
import dask.multiprocessing
Expand Down Expand Up @@ -35,6 +36,19 @@
------------------------------------------------------------------------
"""

def time_logger(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
pid = os.getpid()
print(f"SS {func.__name__} ZZZ: {pid} execution time: {end_time - start_time} seconds")
return result
return wrapper

@time_logger
def root_finder(*args, **kwargs):
return opt.root(*args, **kwargs)

def euler_equation_solver(guesses, *args):
"""
Expand Down Expand Up @@ -240,7 +254,7 @@ def inner_loop(outer_loop_vars, p, client):
scattered_p,
)
lazy_values.append(
delayed(opt.root)(
delayed(root_finder)(
euler_equation_solver,
guesses * 0.9,
args=euler_params,
Expand Down Expand Up @@ -1214,7 +1228,7 @@ def run_SS(p, client=None):
+ list(BQguess)
+ [TRguess, factorguess]
)
sol = opt.root(
sol = root_finder(
SS_fsolve,
guesses,
args=ss_params_baseline,
Expand Down Expand Up @@ -1342,7 +1356,7 @@ def run_SS(p, client=None):
+ list(BQguess)
+ [TR_ss]
)
sol = opt.root(
sol = root_finder(
SS_fsolve,
guesses,
args=ss_params_reform,
Expand Down Expand Up @@ -1371,7 +1385,7 @@ def run_SS(p, client=None):
+ list(BQguess)
+ [TRguess]
)
sol = opt.root(
sol = root_finder(
SS_fsolve,
guesses,
args=ss_params_reform,
Expand Down
22 changes: 19 additions & 3 deletions ogcore/TPI.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# imports
import numpy as np
import pickle
import time
import scipy.optimize as opt
from dask import delayed, compute
import dask.multiprocessing
Expand All @@ -25,6 +26,21 @@
ENFORCE_SOLUTION_CHECKS = True


def time_logger(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
pid = os.getpid()
print(f"TPI {func.__name__} ZZZ: {pid} execution time: {end_time - start_time} seconds")
return result
return wrapper

@time_logger
def root_finder(*args, **kwargs):
return opt.root(*args, **kwargs)


def get_initial_SS_values(p):
"""
Get values of variables for the initial period and the steady state
Expand Down Expand Up @@ -373,7 +389,7 @@ def inner_loop(guesses, outer_loop_vars, initial_values, ubi, j, ind, p):
n_mat = np.zeros((p.T + p.S, p.S))
euler_errors = np.zeros((p.T, 2 * p.S))

solutions = opt.root(
solutions = root_finder(
firstdoughnutring,
[guesses_b[0, -1], guesses_n[0, -1]],
args=(
Expand Down Expand Up @@ -426,7 +442,7 @@ def inner_loop(guesses, outer_loop_vars, initial_values, ubi, j, ind, p):
[temp_mtry[i][j] for j in range(num_params)] for i in range(s + 2)
]

solutions = opt.root(
solutions = root_finder(
twist_doughnut,
list(b_guesses_to_use) + list(n_guesses_to_use),
args=(
Expand Down Expand Up @@ -479,7 +495,7 @@ def inner_loop(guesses, outer_loop_vars, initial_values, ubi, j, ind, p):
for s in range(p.S)
]

solutions = opt.root(
solutions = root_finder(
twist_doughnut,
list(b_guesses_to_use) + list(n_guesses_to_use),
args=(
Expand Down

0 comments on commit a5a2e02

Please sign in to comment.