Revenue-Academy / OG-IND

Overlapping Generations Model for India
https://Revenue-Academy.github.io/OG-IND
Other
1 stars 4 forks source link

Updated Demographics.py #14

Closed rickecon closed 1 year ago

rickecon commented 2 years ago

@jdebacker. This PR:

This PR is currently not running. The demographics.py functions work. But I am getting an error with the interaction of my run script run_og_ind.py, calibrate.py, and macro_params.py.

(ogind-dev) richardevans@Richards-MacBook-Pro OG-IND % python ./examples/run_og_ind.py
Number of workers =  7
Traceback (most recent call last):
  File "/Users/richardevans/Docs/Economics/OSE/OG-IND/./examples/run_og_ind.py", line 133, in <module>
    main()
  File "/Users/richardevans/Docs/Economics/OSE/OG-IND/./examples/run_og_ind.py", line 56, in main
    p.update_specifications(updated_params)
  File "/opt/anaconda3/envs/ogind-dev/lib/python3.9/site-packages/ogcore/parameters.py", line 622, in update_specifications
    self.adjust(revision, raise_errors=raise_errors)
  File "/opt/anaconda3/envs/ogind-dev/lib/python3.9/site-packages/paramtools/parameters.py", line 257, in adjust
    return self._adjust(
  File "/opt/anaconda3/envs/ogind-dev/lib/python3.9/site-packages/paramtools/parameters.py", line 375, in _adjust
    raise self.validation_error
paramtools.exceptions.ValidationError: {
    "errors": {
        "gamma": [
            "Not a valid list."
        ],
        "schema": [
            "Unknown field: g_y"
        ]
    }
}
rickecon commented 2 years ago

@jdebacker. I fixed the resource constraint error in the steady-state computation. I had forgotten to force the final age mortality rate to be 1 in demographics.py. That is updated now, and the steady-state solves fine. The resource constraint error is now -3e-14.

GE loop errors =  [8.895661984809067e-15, 8.88872309090516e-15, -8.104628079763643e-14, 0.0, -9.768852393676752e-13, -1.0821205043143323e-14, -1.0016293350290084e-14, -1.017144701798145e-12, 5.036492056742503e-13, -8.004014118156988e-15, -8.153200337090993e-15, -5.647565748390093e-14, -8.792272465640849e-14, 7.94780907753534e-14]
Iteration: 01  Distance:  2.0508146638093e-11
SS debt =  0.6757309969151628 0.005027444226145001
IO:  (1, 1) , C:  (1,)
Foreign debt holdings =  0.17569005919794234
Foreign capital holdings =  0.09290868596459258
resource constraint:  [-3.17593174e-14]
Checking constraints on capital, labor, and consumption.
    There were no violations of the constraints on labor  supply.
    There were no violations of the constraints on  consumption.
Maximum error in labor FOC =  1.2256862191861728e-13
Maximum error in savings FOC =  9.192646643896296e-14
JUST SAVED SS output to  /Users/richardevans/Docs/Economics/OSE/OG-IND/examples/OG-IND-Example/OUTPUT_BASELINE/SS/SS_vars.pkl
jdebacker commented 1 year ago

@rickecon This looks good to me - let me know if you are ready for me to merge the PR.

rickecon commented 1 year ago

@jdebacker. This PR is ready to merge. I updated the environment.yml file to accomodate the changes to OG-Core like excluding the mkl dependency and for UN data portal pinning the dependency openssl=1.1.1. This is currently running on my machine and the output is the following:

Baseline steady-state equilibrium computation output

GE loop errors =  [-9.020562075079397e-16, -9.020562075079397e-16, 8.659739592076221e-15, 0.0, 4.1378012127779584e-13, -5.410255576876466e-14, 1.0750428325323469e-13, -1.0373646386341306e-13, 1.0850001452844538e-13, -2.8449465006019636e-15, -3.5284275501368256e-15, -2.486726102812753e-15, 3.7241043582270095e-14, -2.8005375796169574e-14]
Iteration: 01  Distance:  3.68758557108822e-12
SS debt =  0.678287753970789 0.005014720445282913
IO:  (1, 1) , C:  (1,)
Foreign debt holdings =  0.17635481603240513
Foreign capital holdings =  0.13146799786380156
resource constraint:  [-1.20771448e-14]
Checking constraints on capital, labor, and consumption.
    There were no violations of the constraints on labor  supply.
    There were no violations of the constraints on  consumption.
Maximum error in labor FOC =  1.212363542890671e-13
Maximum error in savings FOC =  1.0258460747536446e-13
JUST SAVED SS output to  /Users/richardevans/Docs/Economics/OSE/OG-IND/examples/OG-IND-Example/OUTPUT_BASELINE/SS/SS_vars.pkl

Baseline transition path equilibrium computation output (31 min, 37 sec)

Maximum debt ratio:  1.000223772068338
w diff:  5.54397445728938e-07 -9.521345245566692e-08
r diff:  1.1815272808746169e-08 -7.893437938000236e-08
r_p diff:  1.1815272808746169e-08 -7.893437938000236e-08
p_m diff:  0.0 0.0
BQ diff:  2.0845513581252417e-07 -8.28434433899905e-08
TR diff:  1.729082145518479e-07 -3.0210442200639953e-07
Iteration: 23
    Distance: 8.535244564427868e-06
Max absolute value resource constraint error: 7.229351461923716e-05
Checking time path for violations of constraints.
Max Euler error, savings:  3.764100142689131e-12
Max Euler error labor supply:  2.405187160547939e-12
Time path iteration complete.
It took 1896.6830658912659 seconds to get that part done.
run time =  1896.6831181049347

Reform steady-state equilibrium computation output

GE loop errors =  [7.355227538141662e-16, -1.5959455978986625e-16, 2.4424906541753444e-15, 4.440892098500626e-16, -5.773159728050814e-15, -3.9898639947466563e-16, 2.0261570199409107e-14, -4.3368086899420177e-16, -4.3021142204224816e-16, -4.510281037539698e-16, -4.579669976578771e-16, -4.510281037539698e-16, -5.134781488891349e-16]
Iteration: 01  Distance:  4.852423180056472e-13
SS debt =  0.6744317718024155 0.004986212378458489
IO:  (1, 1) , C:  (1,)
Foreign debt holdings =  0.17535226066862805
Foreign capital holdings =  0.10009614345333079
resource constraint:  [-1.57200641e-14]
Checking constraints on capital, labor, and consumption.
    There were no violations of the constraints on labor  supply.
    There were no violations of the constraints on  consumption.
Maximum error in labor FOC =  1.2079226507921703e-13
Maximum error in savings FOC =  7.416289804496046e-14
JUST SAVED SS output to  /Users/richardevans/Docs/Economics/OSE/OG-IND/examples/OG-IND-Example/OUTPUT_REFORM/SS/SS_vars.pkl

Reform transition path equilibrium computation output (33 min, 33 sec)

Maximum debt ratio:  1.0001730016741945
w diff:  5.521442960620959e-07 -1.1738052241305752e-07
r diff:  1.4554791157028735e-08 -7.710884700889986e-08
r_p diff:  1.4554791157028735e-08 -7.710884700196097e-08
p_m diff:  0.0 0.0
BQ diff:  2.0512112900925028e-07 -7.901936428800216e-08
TR diff:  1.643386014493764e-07 -2.966468445608772e-07
Iteration: 23
    Distance: 8.458614202795199e-06
Max absolute value resource constraint error: 7.182762147688038e-05
Checking time path for violations of constraints.
Max Euler error, savings:  3.961719841072409e-12
Max Euler error labor supply:  2.6489921367556235e-12
Time path iteration complete.
It took 2012.9107792377472 seconds to get that part done.
run time =  2012.9108307361603
Percentage changes in aggregates: Year                    Variable  2021  2022  2023  ...  2029  2030  2021-2030    SS
0                    GDP ($Y_t$) -0.70 -0.72 -0.66  ... -0.61 -0.60      -0.65 -0.57
1            Consumption ($C_t$) -0.27 -0.56 -0.44  ... -0.43 -0.45      -0.42 -0.58
2          Capital Stock ($K_t$) -1.94 -1.95 -1.91  ... -1.83 -1.82      -1.88 -1.87
3                  Labor ($L_t$) -0.07 -0.08 -0.03  ...  0.02  0.03      -0.01  0.10
4     Real interest rate ($r_t$) -0.33 -0.33 -0.32  ... -0.36 -0.36      -0.34 -0.20
5                      Wage rate -0.63 -0.63 -0.64  ... -0.63 -0.63      -0.63 -0.67

[6 rows x 13 columns]
rickecon commented 1 year ago

@jdebacker. This PR is ready.

jdebacker commented 1 year ago

Thanks @rickecon, merging.

rickecon commented 1 year ago

@jdebacker. Awesome. Thanks. It is interesting to note that an OG-IND run on the non-M1-chip-optimized Anaconda distribution takes about 50% longer than the M1 optimized (33 min instead of 21 min). The M1 optimized Python is a lot faster.