Skip to content

Commit

Permalink
run all using dask
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed Feb 20, 2024
1 parent 023f868 commit 4c048f4
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 11 deletions.
81 changes: 81 additions & 0 deletions code/run_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from estimark.calibration.options import (
all_replications,
high_resource,
low_resource,
medium_resource,
)
from estimark.estimation import estimate
import dask
from dask.distributed import Client, progress


# Ask the user which replication to run, and run it:
def run_replication():

client = Client(threads_per_worker=10, n_workers=20)

lazy_results = []

for i in range(1, 6):
which_model = str(i)
which_replication = "1"
for k in range(1, 5):
subjective_markets = str(k)

replication_specs = {}

if which_model == "1" or which_model == "":
replication_specs["agent_name"] = "IndShock"
elif which_model == "2":
replication_specs["agent_name"] = "Portfolio"
elif which_model == "3":
replication_specs["agent_name"] = "WarmGlow"
elif which_model == "4":
replication_specs["agent_name"] = "WarmGlowPortfolio"
elif which_model == "5":
replication_specs["agent_name"] = "WealthPortfolio"
else:
print("Invalid model choice.")
return

print("Model: ", replication_specs["agent_name"])

if which_replication == "q":
return

elif which_replication == "1" or which_replication == "":
print("Running low-resource replication...")
replication_specs.update(**low_resource)

elif which_replication == "2":
print("Running medium-resource replication...")
replication_specs.update(**medium_resource)

elif which_replication == "3":
print("Running high-resource replication...")
replication_specs.update(**high_resource)

elif which_replication == "4":
print("Running all replications...")
replication_specs.update(**all_replications)

else:
print("Invalid replication choice.")
return

if subjective_markets == "2" or subjective_markets == "4":
replication_specs["subjective_stock_market"] = True
print("Adding subjective stock market beliefs...")

if subjective_markets == "3" or subjective_markets == "4":
replication_specs["subjective_labor_market"] = True
print("Adding subjective labor market beliefs...")

lazy_result = dask.delayed(estimate)(**replication_specs)
lazy_results.append(lazy_result)

dask.compute(*lazy_results)


if __name__ == "__main__":
run_replication()
2 changes: 2 additions & 0 deletions code/tables/IndShockSub(Labor)Market_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9826952870424113,3.7682894584977236
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DiscFacAdj,CRRA
0.9900216884662436,4.1368574835978205
0.990059541559503,4.128239153345464
Expand Down
2 changes: 2 additions & 0 deletions code/tables/IndShockSub(Stock)Market_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9628905096680382,1.442713138370085
Expand Down
2 changes: 1 addition & 1 deletion code/tables/IndShock_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DiscFacAdj,CRRA
0.9552205116274122,1.3759978446748666
0.9561845217685123,1.3419829066995432
Expand Down
2 changes: 2 additions & 0 deletions code/tables/PortfolioSub(Labor)Market_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9909618480820204,5.986965941730887
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DiscFacAdj,CRRA
0.9911742480356607,6.034052128020187
0.9911787852759087,6.03407974974687
Expand Down
2 changes: 2 additions & 0 deletions code/tables/PortfolioSub(Stock)Market_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9913555579379695,6.010819574001086
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9756576356903954,8.845926577241347
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DiscFacAdj,CRRA
0.9756577076244863,8.846001517130244
0.9756558075814038,8.846028566854438
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9756576356903954,8.845926577241347
Expand Down
2 changes: 1 addition & 1 deletion code/tables/WarmGlowPortfolio_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DiscFacAdj,CRRA
0.9273982467678095,1.4720190125393666
0.9756570720304689,8.846018147853837
Expand Down
2 changes: 2 additions & 0 deletions code/tables/WarmGlowSub(Labor)Market_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9791782282367655,4.231669394199844
Expand Down
2 changes: 2 additions & 0 deletions code/tables/WarmGlowSub(Stock)Market_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.9861734987743034,4.425678459697778
Expand Down
2 changes: 1 addition & 1 deletion code/tables/WarmGlow_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DiscFacAdj,CRRA
0.9530437585281377,1.386246664352366
0.9861338473449703,4.436057123654957
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.8407456786079042,7.526834053433991
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DiscFacAdj,CRRA
0.6902949988467191,5.143158466987802
Expand Down
2 changes: 1 addition & 1 deletion code/tables/WealthPortfolio_estimate_results.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DiscFacAdj,CRRA
0.6772594280853925,5.019468591453271
0.6741600851429033,5.044372293670781
Expand Down
8 changes: 4 additions & 4 deletions code/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ def test_medium_resource():

def test_portfolio_low_resource():
print("Running medium-resource replication...")
estimate(**low_resource, estimation_agent="Portfolio")
estimate(**low_resource, agent_name="Portfolio")


def test_warmglow_low_resource():
print("Running medium-resource replication...")
estimate(**low_resource, estimation_agent="WarmGlow")
estimate(**low_resource, agent_name="WarmGlow")


def test_warmglowportfolio_low_resource():
print("Running medium-resource replication...")
estimate(**low_resource, estimation_agent="WarmGlowPortfolio")
estimate(**low_resource, agent_name="WarmGlowPortfolio")


def test_wealthportfolio_low_resource():
print("Running medium-resource replication...")
estimate(**low_resource, estimation_agent="WealthPortfolio")
estimate(**low_resource, agent_name="WealthPortfolio")
7 changes: 7 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ channels:
- conda-forge
dependencies:
- python=3.10
- jupyter
- jupyterlab
- black
- ruff
- nbqa
- dask
- pip
- pip:
- git+https://github.com/econ-ark/HARK@master
- black[jupyter]

0 comments on commit 4c048f4

Please sign in to comment.