Skip to content

Commit abe4a76

Browse files
committed
update timer and install
1 parent 52ae152 commit abe4a76

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lectures/aiyagari.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ kernelspec:
2626
:depth: 2
2727
```
2828

29-
In addition to what's included in base Anaconda, we need to install JAX.
29+
In addition to what's included in base Anaconda, we need to install JAX
3030

3131
```{code-cell} ipython3
32-
:tags: [skip-execution]
33-
34-
!pip install --upgrade jax
32+
!pip install quantecon jax
3533
```
3634

3735
## Overview
@@ -58,7 +56,7 @@ The Aiyagari model has been used to investigate many topics, including
5856
We use the following imports:
5957

6058
```{code-cell} ipython3
61-
import time
59+
import quantecon as qe
6260
import matplotlib.pyplot as plt
6361
import numpy as np
6462
import jax
@@ -450,7 +448,9 @@ print(f"Interest rate: {r}, Wage: {w}")
450448
```
451449

452450
```{code-cell} ipython3
453-
%time σ_star = howard_policy_iteration(household, prices, verbose=True)
451+
with qe.Timer():
452+
σ_star = howard_policy_iteration(
453+
household, prices, verbose=True).block_until_ready()
454454
```
455455

456456
The next plot shows asset accumulation policies at different values of the exogenous state
@@ -624,10 +624,10 @@ def compute_equilibrium(firm, household,
624624
firm = create_firm()
625625
household = create_household()
626626
print("\nComputing equilibrium capital stock")
627-
start = time.time()
628-
K_star, n = compute_equilibrium(firm, household, K0=6.0)
629-
elapsed = time.time() - start
630-
print(f"Computed equilibrium {K_star:.5} in {n} iterations and {elapsed} seconds")
627+
with qe.Timer():
628+
K_star, n = compute_equilibrium(
629+
firm, household, K0=6.0).block_until_ready()
630+
print(f"Computed equilibrium {K_star:.5} in {n} iterations")
631631
```
632632

633633
This convergence is not very fast, given how quickly we can solve the household problem.
@@ -715,10 +715,10 @@ def compute_equilibrium_bisect(firm, household, a=1.0, b=20.0):
715715
firm = create_firm()
716716
household = create_household()
717717
print("\nComputing equilibrium capital stock using bisection")
718-
start = time.time()
719-
K_star = compute_equilibrium_bisect(firm, household)
720-
elapsed = time.time() - start
721-
print(f"Computed equilibrium capital stock {K_star:.5} in {elapsed} seconds")
718+
with qe.Timer():
719+
K_star = compute_equilibrium_bisect(
720+
firm, household).block_until_ready()
721+
print(f"Computed equilibrium capital stock {K_star:.5}")
722722
```
723723

724724
The bisection method is faster than the damped iteration scheme.

0 commit comments

Comments
 (0)