Skip to content

Commit c09f30d

Browse files
authored
ENH: Fix for bringing code in from a file (#16)
* use ifp as a test case' * update lecture files to new syntax for executable code from file * install myst_nb from the branch * remove debug cell at the top of lecture * install mysb_nb from branch for testing * add mathjax cdn address * update sources lecture-python (9ae923d) using tomyst (b06cacb) * fix for newline bug in wald_friedman * update config for latest sphinxcontrib-bibtex (#84) * update environment for testing from branch mystnb:code-from-file * upload build folder as an artifact * fix path * update timeout for exection to 10min * migrate from :file: to :load: (myst-nb) * remove install of myst_nb from branch and include latest jupyter-book master install
1 parent 0055b87 commit c09f30d

File tree

10 files changed

+46
-19
lines changed

10 files changed

+46
-19
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ jobs:
3232
shell: bash -l {0}
3333
run: |
3434
jb build lectures --path-output ./
35+
- name: Save Build as Artifact
36+
uses: actions/upload-artifact@v1
37+
with:
38+
name: _build
39+
path: _build
3540
- name: Preview Deploy to Netlify
3641
uses: nwtgck/[email protected]
3742
with:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
lectures/_build
1+
_build/
2+
lectures/_build/

lectures/_config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ description: This website presents a set of lectures on quantitative economic mo
55

66
execute:
77
execute_notebooks: "cache"
8-
timeout: 60
8+
timeout: 600
9+
10+
bibtex_bibfiles:
11+
- _static/quant-econ.bib
912

1013
bibtex_bibfiles:
1114
- _static/quant-econ.bib
@@ -50,6 +53,7 @@ sphinx:
5053
og_logo_url: https://assets.quantecon.org/img/qe-og-logo.png
5154
description: This website presents a set of lectures on quantitative economic modeling, designed and written by Thomas J. Sargent and John Stachurski.
5255
keywords: Python, QuantEcon, Quantitative Economics, Economics, Sloan, Alfred P. Sloan Foundation, Tom J. Sargent, John Stachurski
56+
mathjax_path: https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
5357
rediraffe_redirects:
5458
index_toc.md: intro.md
5559
tojupyter_static_file_path: ["source/_static", "_static"]

lectures/cake_eating_numerical.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ where $u$ is the CRRA utility function.
7272
The analytical solutions for the value function and optimal policy were found
7373
to be as follows.
7474

75-
```{literalinclude} _static/lecture_specific/cake_eating_numerical/analytical.py
75+
```{code-cell} python3
76+
:load: _static/lecture_specific/cake_eating_numerical/analytical.py
7677
```
7778

7879
Our first aim is to obtain these analytical solutions numerically.

lectures/coleman_policy_iter.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ As in our {doc}`previous study <optgrowth_fast>`, we continue to assume that
267267

268268
This will allow us to compare our results to the analytical solutions
269269

270-
```{literalinclude} _static/lecture_specific/optgrowth/cd_analytical.py
270+
```{code-cell} python3
271+
:load: _static/lecture_specific/optgrowth/cd_analytical.py
271272
```
272273

273274
As discussed above, our plan is to solve the model using time iteration, which
@@ -278,7 +279,8 @@ For this we need access to the functions $u'$ and $f, f'$.
278279
These are available in a class called `OptimalGrowthModel` that we
279280
constructed in an {doc}`earlier lecture <optgrowth_fast>`.
280281

281-
```{literalinclude} _static/lecture_specific/optgrowth_fast/ogm.py
282+
```{code-cell} python3
283+
:load: _static/lecture_specific/optgrowth_fast/ogm.py
282284
```
283285

284286
Now we implement a method called `euler_diff`, which returns
@@ -374,7 +376,8 @@ Here is a function called `solve_model_time_iter` that takes an instance of
374376
`OptimalGrowthModel` and returns an approximation to the optimal policy,
375377
using time iteration.
376378

377-
```{literalinclude} _static/lecture_specific/coleman_policy_iter/solve_time_iter.py
379+
```{code-cell} python3
380+
:load: _static/lecture_specific/coleman_policy_iter/solve_time_iter.py
378381
```
379382

380383
Let's call it:
@@ -439,7 +442,8 @@ Compute and plot the optimal policy.
439442

440443
We use the class `OptimalGrowthModel_CRRA` from our {doc}`VFI lecture <optgrowth_fast>`.
441444

442-
```{literalinclude} _static/lecture_specific/optgrowth_fast/ogm_crra.py
445+
```{code-cell} python3
446+
:load: _static/lecture_specific/optgrowth_fast/ogm_crra.py
443447
```
444448

445449
Let's create an instance:

lectures/egm_policy_iter.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ where
160160

161161
This will allow us to make comparisons with the analytical solutions
162162

163-
```{literalinclude} _static/lecture_specific/optgrowth/cd_analytical.py
163+
```{code-cell} python3
164+
:load: _static/lecture_specific/optgrowth/cd_analytical.py
164165
```
165166

166167
We reuse the `OptimalGrowthModel` class
167168

168-
```{literalinclude} _static/lecture_specific/optgrowth_fast/ogm.py
169+
```{code-cell} python3
170+
:load: _static/lecture_specific/optgrowth_fast/ogm.py
169171
```
170172

171173
### The Operator
@@ -216,7 +218,8 @@ grid = og.grid
216218

217219
Here's our solver routine:
218220

219-
```{literalinclude} _static/lecture_specific/coleman_policy_iter/solve_time_iter.py
221+
```{code-cell} python3
222+
:load: _static/lecture_specific/coleman_policy_iter/solve_time_iter.py
220223
```
221224

222225
Let's call it:

lectures/ifp.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ start to iterate.
475475
The following function iterates to convergence and returns the approximate
476476
optimal policy.
477477

478-
```{literalinclude} _static/lecture_specific/coleman_policy_iter/solve_time_iter.py
478+
```{code-cell} python3
479+
:load: _static/lecture_specific/coleman_policy_iter/solve_time_iter.py
479480
```
480481

481482
Let's carry this out using the default parameters of the `IFP` class:
@@ -518,7 +519,8 @@ In this case, our income fluctuation problem is just a cake eating problem.
518519
We know that, in this case, the value function and optimal consumption policy
519520
are given by
520521

521-
```{literalinclude} _static/lecture_specific/cake_eating_numerical/analytical.py
522+
```{code-cell} python3
523+
:load: _static/lecture_specific/cake_eating_numerical/analytical.py
522524
```
523525

524526
Let's see if we match up:

lectures/markov_perf.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ Consider the previously presented duopoly model with parameter values of:
431431

432432
From these, we compute the infinite horizon MPE using the preceding code
433433

434-
```{literalinclude} _static/lecture_specific/markov_perf/duopoly_mpe.py
434+
```{code-cell} python3
435+
:load: _static/lecture_specific/markov_perf/duopoly_mpe.py
435436
```
436437

437438
Running the code produces the following output.

lectures/optgrowth.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,8 @@ whether our code works for this particular case.
624624

625625
In Python, the functions above can be expressed as:
626626

627-
```{literalinclude} _static/lecture_specific/optgrowth/cd_analytical.py
627+
```{code-cell} python3
628+
:load: _static/lecture_specific/optgrowth/cd_analytical.py
628629
```
629630

630631
Next let's create an instance of the model with the above primitives and assign it to the variable `og`.
@@ -700,7 +701,8 @@ We are clearly getting closer.
700701
We can write a function that iterates until the difference is below a particular
701702
tolerance level.
702703

703-
```{literalinclude} _static/lecture_specific/optgrowth/solve_model.py
704+
```{code-cell} python3
705+
:load: _static/lecture_specific/optgrowth/solve_model.py
704706
```
705707

706708
Let's use this function to compute an approximate solution at the defaults.

lectures/optgrowth_fast.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ In particular, the algorithm is unchanged, and the only difference is in the imp
103103

104104
As before, we will be able to compare with the true solutions
105105

106-
```{literalinclude} _static/lecture_specific/optgrowth/cd_analytical.py
106+
```{code-cell} python3
107+
:load: _static/lecture_specific/optgrowth/cd_analytical.py
107108
```
108109

109110
## Computation
@@ -125,7 +126,8 @@ class.
125126

126127
This is where we sacrifice flexibility in order to gain more speed.
127128

128-
```{literalinclude} _static/lecture_specific/optgrowth_fast/ogm.py
129+
```{code-cell} python3
130+
:load: _static/lecture_specific/optgrowth_fast/ogm.py
129131
```
130132

131133
The class includes some methods such as `u_prime` that we do not need now
@@ -186,7 +188,8 @@ def T(v, og):
186188

187189
We use the `solve_model` function to perform iteration until convergence.
188190

189-
```{literalinclude} _static/lecture_specific/optgrowth/solve_model.py
191+
```{code-cell} python3
192+
:load: _static/lecture_specific/optgrowth/solve_model.py
190193
```
191194

192195
Let's compute the approximate solution at the default parameters.
@@ -317,7 +320,8 @@ value function iteration, the JIT-compiled code is usually an order of magnitude
317320

318321
Here's our CRRA version of `OptimalGrowthModel`:
319322

320-
```{literalinclude} _static/lecture_specific/optgrowth_fast/ogm_crra.py
323+
```{code-cell} python3
324+
:load: _static/lecture_specific/optgrowth_fast/ogm_crra.py
321325
```
322326

323327
Let's create an instance:

0 commit comments

Comments
 (0)