Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Log root finding #904

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading