Skip to content

Commit 9ae48b7

Browse files
authored
Merge pull request PSLmodels#1053 from jdebacker/ss_replace
Merging
2 parents 7c9a238 + 95bb2af commit 9ae48b7

11 files changed

Lines changed: 34 additions & 46 deletions
File renamed without changes.
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
# Use a custom matplotlib style file for plots
2222
plt.style.use("ogcore.OGcorePlots")
2323

24-
# Set verbosity
25-
ogcore.SS.VERBOSE = False
26-
ogcore.TPI.VERBOSE = False
27-
2824

2925
def main():
3026
# Define parameters to use for multiprocessing

ogcore/SS.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import warnings
1212
import logging
1313

14-
1514
if not SHOW_RUNTIME:
1615
warnings.simplefilter("ignore", RuntimeWarning)
1716

@@ -1226,27 +1225,25 @@ def SS_fsolve(guesses, *args):
12261225
+ list(error_BQ)
12271226
+ [error_TR]
12281227
)
1229-
logging.info(f"GE loop errors = ", [f"{error:.3e}" for error in errors])
1228+
error_string = [f"{error:.3e}" for error in errors]
1229+
logging.info(f"GE loop errors = {error_string}")
12301230

12311231
return errors
12321232

12331233

1234-
def run_SS(p, client=None, verbose=False):
1234+
def run_SS(p, client=None):
12351235
"""
12361236
Solve for steady-state equilibrium of OG-Core.
12371237
12381238
Args:
12391239
p (OG-Core Specifications object): model parameters
12401240
client (Dask client object): client
1241-
verbose (bool): if True, set logging to INFO level
12421241
12431242
Returns:
12441243
output (dictionary): dictionary with steady-state solution
12451244
results
12461245
12471246
"""
1248-
# Configure logging level based on verbose parameter
1249-
config.set_logging_level(verbose)
12501247
# Create list of deviation factors for initial guesses of r and TR
12511248
dev_factor_list = [
12521249
[1.00, 1.0],

ogcore/TPI.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,28 +543,22 @@ def inner_loop(guesses, outer_loop_vars, initial_values, ubi, j, ind, p):
543543
n_vec = solutions.x[p.S :]
544544
n_mat[t + ind, ind] = n_vec
545545

546-
# print('Type ', j, ' max euler error = ',
547-
# np.absolute(euler_errors).max())
548-
549546
return euler_errors, b_mat, n_mat
550547

551548

552-
def run_TPI(p, client=None, verbose=False):
549+
def run_TPI(p, client=None):
553550
"""
554551
Solve for transition path equilibrium of OG-Core.
555552
556553
Args:
557554
p (OG-Core Specifications object): model parameters
558555
client (Dask client object): client
559-
verbose (bool): if True, set logging to INFO level
560556
561557
Returns:
562558
output (dictionary): dictionary with transition path solution
563559
results
564560
565561
"""
566-
# Configure logging level based on verbose parameter
567-
config.set_logging_level(verbose)
568562
# unpack tuples of parameters
569563
initial_values, ss_vars, theta, baseline_values = get_initial_SS_values(p)
570564
(B0, b_sinit, b_splus1init, factor, initial_b, initial_n) = initial_values
@@ -1145,7 +1139,7 @@ def run_TPI(p, client=None, verbose=False):
11451139
# print 'New Value of nu:', nu
11461140
TPIiter += 1
11471141
logging.info(f"Iteration: {TPIiter}")
1148-
logging.info(f"\tDistance: {TPIdist}")
1142+
logging.info(f"Distance: {TPIdist}")
11491143

11501144
# Compute effective and marginal tax rates for all agents
11511145
num_params = len(p.mtrx_params[0][0])

ogcore/config.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
import logging
99

10-
VERBOSE = False # Default value
10+
VERBOSE = True # Default verbosity setting
1111

1212

13-
def set_logging_level(verbose=False):
13+
def set_logging_level(verbose=True):
1414
"""
1515
Set the logging level for OG-Core modules.
1616
@@ -26,13 +26,14 @@ def set_logging_level(verbose=False):
2626
level = logging.INFO if verbose else logging.WARNING
2727

2828
# Configure the root logger
29-
logging.basicConfig(
30-
level=level,
31-
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
32-
)
29+
logging.basicConfig(level=level, format="%(message)s")
3330

3431
# Also set the ogcore logger specifically
3532
logger = logging.getLogger("ogcore")
3633
logger.setLevel(level)
3734

3835
return level
36+
37+
38+
# Auto-configure when module is imported
39+
set_logging_level(verbose=VERBOSE)

ogcore/household.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
import numpy as np
99
from ogcore import tax, utils
1010
import logging
11-
12-
# Configure logging
13-
VERBOSE = False
14-
log_level = logging.INFO if VERBOSE else logging.WARNING
15-
logging.basicConfig(
16-
level=log_level, format="%(message)s" # Only show the message itself
17-
)
11+
from ogcore import config
1812

1913
"""
2014
------------------------------------------------------------------------
@@ -775,28 +769,27 @@ def constraint_checker_SS(bssmat, nssmat, cssmat, ltilde):
775769
logging.info("Checking constraints on capital, labor, and consumption.")
776770

777771
if (bssmat < 0).any():
778-
logging.info("\tWARNING: There is negative capital stock")
772+
logging.info("WARNING: There is negative capital stock")
779773
flag2 = False
780774
if (nssmat < 0).any():
781775
logging.info(
782-
"\tWARNING: Labor supply violates nonnegativity ", "constraints."
776+
"WARNING: Labor supply violates nonnegativity constraints."
783777
)
784778
flag2 = True
785779
if (nssmat > ltilde).any():
786-
logging.info("\tWARNING: Labor supply violates the ltilde constraint.")
780+
logging.info("WARNING: Labor supply violates the ltilde constraint.")
787781
flag2 = True
788782
if flag2 is False:
789783
logging.info(
790-
"\tThere were no violations of the constraints on labor",
791-
" supply.",
784+
"There were no violations of the constraints on labor supply.",
792785
)
793786
if (cssmat < 0).any():
794787
logging.info(
795-
"\tWARNING: Consumption violates nonnegativity", " constraints."
788+
"WARNING: Consumption violates nonnegativity constraints."
796789
)
797790
else:
798791
logging.info(
799-
"\tThere were no violations of the constraints on", " consumption."
792+
"There were no violations of the constraints on consumption."
800793
)
801794

802795

@@ -821,13 +814,11 @@ def constraint_checker_TPI(b_dist, n_dist, c_dist, t, ltilde):
821814
"""
822815
if (b_dist <= 0).any():
823816
logging.info(
824-
"\tWARNING: Aggregate capital is less than or equal to ",
825-
"zero in period %.f." % t,
817+
f"WARNING: Aggregate capital is less than or equal to zero in period {t}."
826818
)
827819
if (n_dist < 0).any():
828820
logging.info(
829-
"\tWARNING: Labor supply violates nonnegativity",
830-
" constraints in period %.f." % t,
821+
f"WARNING: Labor supply violates nonnegativity constraints in period {t}."
831822
)
832823
if (n_dist > ltilde).any():
833824
logging.info(

ogcore/pensions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ def SS_amount(w, n, theta, t, j, shift, method, e, p):
148148
# entry for retirement will change (it shifts back one).
149149
# The shift boolean makes sure we start replacement rates
150150
# at the correct age.
151+
if j is None:
152+
replace_rate_adjust = p.replacement_rate_adjust[-1, :]
153+
else:
154+
replace_rate_adjust = p.replacement_rate_adjust[-1, j]
151155
if shift is False:
152-
pension[p.retire[-1] :] = theta * w
156+
pension[p.retire[-1] :] = replace_rate_adjust * theta * w
153157
else:
154-
pension[p.retire[-1] - 1 :] = theta * w
158+
pension[p.retire[-1] - 1 :] = replace_rate_adjust * theta * w
155159
elif method == "TPI":
156160
length = w.shape[0]
157161
if not shift:
@@ -734,8 +738,8 @@ def deriv_DB_loop(
734738
another unit of labor supply
735739
"""
736740
d_theta = np.zeros(per_rmn)
737-
print("Year contribution: ", yr_contr)
738-
print("Average earnings years: ", avg_earn_num_years)
741+
# print("Year contribution: ", yr_contr)
742+
# print("Average earnings years: ", avg_earn_num_years)
739743
num_per_retire = S - S_ret
740744
for s in range(per_rmn):
741745
d_theta[s] = w[s] * e[s] * alpha_db * (yr_contr / avg_earn_num_years)

0 commit comments

Comments
 (0)