Skip to content

Offer each lecture's notebook for download - #87

Merged
mmcky merged 2 commits into
mainfrom
download-notebooks
Nov 25, 2026
Merged

mmcky merged 2 commits into
mainfrom
download-notebooks

Conversation

@mmcky

@mmcky mmcky commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Implements #86: dp's pages get the "Download Notebook" button the other series' sites have.

  • ci.yml and publish.yml. A quantecon/actions/build-lectures@v0 step with builder: 'jupyter' runs before Build HTML, writing the notebooks to _build/jupyter from the restored execution cache, and the Build HTML step sets html-copy-notebooks: 'true', which copies them into _build/html/_notebooks/ before the HTML build. quantecon-book-theme shows the button on a page when that folder exists while the page is rendered. This is the order QuantEcon/actions' documentation gives for building notebooks for download (docs/user/composition.md, "Formats"). Each step uploads its own failure reports (execution-reports-jupyter, execution-reports-html), so the two names don't collide.
  • _config.yml. dp is served from a sub-path, https://quantecon.github.io/lecture-dp/, and the theme's default link, /_notebooks/<page>.ipynb, is relative to the domain's root. download_nb_path: https://quantecon.github.io/lecture-dp makes each link https://quantecon.github.io/lecture-dp/_notebooks/<page>.ipynb.
  • _config.yml, a second line. tojupyter_static_file_path was ["source/_static", "_static"]; source/_static doesn't exist in dp, and since dp never ran the jupyter builder before, nothing noticed. With the builder running, sphinx-tojupyter warns about the missing folder and -W fails the notebook build (this pull request's first CI run, at 400ffa2). It is now ["_static"], as in the other five series.

Because ci.yml changes too, this pull request's own build shows the button, so the change can be checked before it reaches the live site. On the live site the button appears at the next publish-* tag. In a pull request's build the links point at the live site's address, where the notebooks arrive only after that publish.

The monorepo

sites/dp/_config.yml in QuantEcon/lectures copies this _config.yml, so a pull request there copies the new line once this has merged. sites/dp/site.yml records that dp publishes HTML only; it changes when dp's build moves to the monorepo.

Validation

Fresh builds of main and of this branch the same day, dp's way (cache.yml with no cache, then ci.yml rendering each side's own fresh cache), compared page by page, and the notebooks themselves checked against their lectures; the evidence comment follows below.

Requested by @mmcky on 2026-11-26 in the lecture monorepo's working session: "Please proceed", to "Shall I open that PR now?" (this change, as #86 sets it out).

🤖 Generated with Claude Code

https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG

mmcky and others added 2 commits November 26, 2026 08:50
ci.yml and publish.yml build the notebooks with build-lectures'
jupyter builder before the HTML build, and the HTML step copies them
into _build/html/_notebooks/ (html-copy-notebooks), so
quantecon-book-theme shows its "Download Notebook" button on every
lecture page, as on the other series' sites. dp is served from a
sub-path, so _config.yml sets download_nb_path to
https://quantecon.github.io/lecture-dp: the theme's default link,
/_notebooks/<page>.ipynb, is relative to the domain's root.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
…er series

dp's setting also listed "source/_static", which doesn't exist. dp
never ran the jupyter builder before, so it didn't matter; now
sphinx-tojupyter warns about the missing folder and -W fails the
notebook build. The other five series list "_static" alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
@mmcky

mmcky commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Validation: a full validation

dp's way, as for #81, #84 and #85: a fresh build with no cache of main and of this pull request, each executing all 51 notebooks (cache.yml), each then rendered by ci.yml, which restored that side's fresh build. This pull request's render runs its own ci.yml, so it builds the notebooks and stages them as the live publish will.

main at 3267d81, 2026-11-25 (UTC) this pull request, 2026-11-25 (UTC)
fresh build 45708022287 45708027651 at 400ffa2; 45708554719 at 0056173
render 45712893975 45712899886 at 0056173, restoring 45708027651's cache

The pull request has two fresh builds because its first CI run failed (below) and the fix was a second commit. Both builds passed; the render restored the first, which holds the same lectures: the second commit changes only a sphinx-tojupyter setting, which the cache build doesn't use.

The first CI run's failure, and the second commit. At 400ffa2 this pull request's own CI failed in the new notebook step: sphinx-tojupyter warned tojupyter_static_path entry …/lectures/source/_static does not exist, and -W makes a warning fail the build. dp's tojupyter_static_file_path listed "source/_static" as well as "_static", which had never mattered while dp built no notebooks; the other five series list "_static" alone. The second commit, 0056173, does the same, and the notebook build passes.

  • The change. On this pull request's render, _build/html/_notebooks/ holds 52 notebooks (the build log: "Staged 53 notebooks"; the 53rd is _static/lecture_specific/short_path/Graph-networkx2.ipynb, a notebook the lecture itself ships), and 55 of the 57 pages have the "Download Notebook" button, linking to https://quantecon.github.io/lecture-dp/_notebooks/<page>.ipynb. Main's render has no _notebooks/ and no button. No page's prose differs, and the launch button stays gone on both sides.
  • The buttons without a notebook. Three of the 55 are Sphinx's generated pages, genindex, search and prf-prf, which have no notebook, so their button leads nowhere. Intermediate's live site is the same (each has the button; its notebook is a 404), so this is how the theme behaves on every series, not something this pull request adds. index and index_toc have no button.
  • The notebooks match their lectures. Each of the 52 is a valid notebook (nbformat 4) whose title is its page's, and 51 have exactly as many code cells as the page shows. The exception is jv, with 9 against the page's 8: its source has a {code-block} python3, which the page shows as plain code and sphinx-tojupyter turns into a code cell. Intermediate's own jv does the same (13 on the page, 14 in its notebook).
  • The environment: all three fresh builds ran in the same image, the same digest (sha256:833e117fefbd…).
  • Build logs: no Sphinx warning on any build or render. The renders' logs differ only because this side runs build-lectures twice (notebooks, then HTML), so the action's script, which the log prints and which contains the word WARNING, appears twice; neither render logs a warning.
  • Cell outputs: the warnings and errors are the same on both sides, page by page, except one count on odu, explained in its row.
  • Packages installed inside cells: five pages run pip install in a cell (amss, calvo_machine_learn, chang_credible, chang_ramsey, odu); on each, "Successfully installed" lists the same packages at the same versions on both sides.
  • The HTML: 26 of 57 pages differ, every figure compared by content, all in their outputs: noise of the kinds in environment.yml: the Anaconda channels are defaults #81's, smoothing, smoothing_tax: take advanced's copies, linking perm_income_cons with {doc} #84's and _config.yml: remove the launch button, whose notebooks repository doesn't exist #85's comparisons.
Page What differs between main's render and this pull request's
amss %%time timings
amss2 figure 2 of 2, from a long simulation whose Markov states are drawn without a seed
amss3 figures 1 and 4 of 5, from a long simulation whose Markov states are drawn without a seed
calvo_machine_learn the progress bars of the cell's pip install
career figure 5 of 6, from qe.random.draw, which draws without a seed
chang_ramsey the progress bars of the cell's pip install
cons_news memory addresses in printed objects, and figures 3 and 4 of 4, from unseeded LSS.simulate draws
discrete_dp %timeit timings and the printed elapsed times
ifp_discrete relative speed (6.32 against 7.78)
ifp_egm the NumPy/JAX speed-up, 13.17x against 12.23x
ifp_egm_transient_shocks the NumPy/JAX speed-up, 18.26x against 18.47x
ifp_opi speed-ups, and figure 2 of 2, which plots run times
jv figures 1 and 2 of 3, from unseeded draws (np.random.beta, np.random.uniform)
lagrangian_lqdp %%timeit timings
lq_inventories figures 1, 2, 4, 5, 6, 12, 15 and 16 of 16, from simulate, which calls LQ.compute_sequence without a seed
lqcontrol figures 1, 2, 8, 9 and 10 of 10, from LQ.compute_sequence, which draws its shocks without a seed
lqramsey figures 1 to 6 of 6, from paths drawn with numpy's unseeded randn
markov_jump_lq figure 2 of 52, from compute_sequence, which draws its shocks without a seed
odu the solvers' progress lines (one converged in 34 iterations rather than 36), from unseeded draws, so one fewer line that the comparison counts as "Error" (12 against 11; no exception on either side), and its figures, from unseeded draws (np.random.beta, np.random.uniform)
perm_income figures 1 and 2 of 3, from unseeded draws (np.random.randn)
perm_income_cons figures 1 to 6 of 6, from lss.simulate, which draws without a seed
smoothing figure 1 of 2, from a simulation whose seed is itself drawn at random (np.random.randint)
status the build times
tax_smoothing_1 figures 1 to 3 of 3, from compute_sequence, which draws its shocks without a seed
tax_smoothing_2 figures 1 to 4 of 4, from compute_sequence, which draws its shocks without a seed
tax_smoothing_3 figures 1 and 2 of 2, from compute_sequence, which draws its shocks without a seed

Not tested here: publish.yml. Its two new steps are the same as ci.yml's, which this render ran; they first run at the next publish-* tag. In a pull request's build the button's links point at the live site, where the notebooks arrive with that publish.

Conclusion. The pull request adds the "Download Notebook" button and the notebooks behind it to every lecture page, and nothing else a reader would see; every other difference is output noise of the kinds this series' builds already show between runs.

@mmcky
mmcky merged commit afb26ea into main Nov 25, 2026
3 checks passed
@mmcky
mmcky deleted the download-notebooks branch November 25, 2026 22:44
mmcky added a commit to QuantEcon/lectures that referenced this pull request Nov 25, 2026
The pool follow-up to QuantEcon/lecture-dp#87: sites/dp/_config.yml takes dp's two new lines, download_nb_path (https://quantecon.github.io/lecture-dp) and tojupyter_static_file_path ["_static"]; with its site-addition lines set aside, the file is byte for byte dp's at afb26ea. sync/state.yml pins dp at afb26ea, so tonight's drift check compares like with like. dp is a consumer, so no lecture enters the pool. The pool's dp site build stays HTML only, so it shows no download button until dp's build moves to the monorepo (QuantEcon/lecture-dp#86). CI's site builds passed.

Merged on @mmcky's "Merge as recommended" in the organiser session.

Co-authored-by: Claude Opus 5.5 <[email protected]>
mmcky added a commit to QuantEcon/lectures that referenced this pull request Nov 26, 2026
…ntries; dp publishes notebooks (#98)

Three changes to the one environment and its records, in one pull request as the infrastructure organiser's review of #85 proposed (2026-11-22), so the three base sites build from an empty cache once, not twice.

## What changes

- **`plotly-orca` leaves `_base/environment-update.yml`.** It was listed for the three `!conda install … plotly-orca` lines in the series' lectures, which were removed upstream by 2026-11-20 with the other install lines that replaced a pin. No pool lecture installs or uses it now: no lecture in `lectures/` or in any series' `lectures/` at its pin mentions orca, and `tools/pool-check --installs` lists no install that would replace a pin. The list's header now says those lines were removed (it said they "are being removed"), names the three sites built with it (intro, advanced, programming) and says the GPU leg creates its base from `_base/environment.yml`.
- **A base site's cache key hashes the list's entries, not its comments.** In `site-build.yml`, the env hash of a `base` site is the sha256 of `_base/environment-update.yml`'s lines with comments (a `#` at the start of a line or after a space) and blank lines removed, and the GPU leg's image hash takes `_base/environment.yml`'s entries the same way. So an edit to a comment no longer executes every page of intro, advanced and programming again. A `series` site (dp) keeps `hashFiles` of its `environment.yml`, whole, as dp's own cache keys hash it, so dp's key is unchanged. The comments in the workflow, `sites/README.md` and `_base/README.md` say so.
- **dp publishes notebooks.** Since QuantEcon/lecture-dp#87, dp's `publish.yml` builds the notebooks as well as HTML (no PDF), so `sites/dp/site.yml` now has `publishes: [html, notebooks]`, and `sites/README.md`'s table and notes follow. Nothing reads `publishes` yet: every leg still builds HTML alone, so the pool's dp build has no "Download Notebook" button until the site build makes notebooks (the last section of QuantEcon/lecture-dp#86), which dp's shadow comparison will show.

## What the entries filter does, checked locally

| Input | Result |
|---|---|
| main's list against this branch's | the entries differ in one line, `- plotly::plotly-orca==1.3.1` |
| this branch's list against a copy with one comment reworded | the same hash |
| `_base/environment.yml`, main against this branch | the same entries (only its comment changed) |

Local runs on this branch: `tools/pool-check` clean (the list has 39 packages; the pool's lectures install 29 of them), the tool tests 330 passed and 1 skipped, and `tools/site-matrix` gives dp `publishes: ["html", "notebooks"]` with its `series` key inputs unchanged.

## What to expect from this pull request's builds

The list's entries change, so intro, advanced and programming find no cache under their new keys and execute every page in the environment without `plotly-orca`: that is this change's test. dp's key is unchanged, so it restores main's cache. After the merge, main's push builds the three again from an empty cache and saves, and later runs restore.

Copilot: not requested (Matt, 2026-11-22).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
mmcky added a commit to QuantEcon/lectures that referenced this pull request Nov 26, 2026
…rve them at _notebooks/ (#104)

For QuantEcon/project-monorepo#77 ("with HTML, PDF and notebooks"): the notebooks. A site whose `site.yml` publishes notebooks now gets them, as its series' own publish does: the `jupyter` builder, strict, with the notebooks served at `_build/html/_notebooks/`, where quantecon-book-theme links each page's "Download Notebook" button. All four sites built today publish notebooks: dp since QuantEcon/lecture-dp#87, and intro, advanced and programming throughout. A release from the pool (#103) needs them, as does dp's shadow comparison.

## The order, and why it differs from the series'

The series build the notebooks first, then the HTML with `html-copy-notebooks`. Here that order would break the cache. On a cold build the notebook build would execute every page, the HTML build would then take every page from the cache, and the execution report, which reads the HTML build, would count 0 executed, so main would never save its cache.

The theme shows the button when `_build/html/_notebooks/` is a folder as it renders a page (`os.path.isdir(app.outdir / "_notebooks")`, quantecon-book-theme 0.22.2). So:
1. make that folder;
2. build the HTML, as now: it executes the pages, and the report counts them;
3. write the execution report;
4. build the notebooks, strict, from the cache the HTML build filled (after the report, because this build rewrites the environment the report reads);
5. copy each notebook under `_build/jupyter` into `_build/html/_notebooks/` at the same path, as build-lectures' `html-copy-notebooks` does.

The site gets the same files and the same buttons as the series' order would give it.

Each new step runs only for a site that publishes notebooks. The notebook build has its own failure artefact, `execution-reports-<key>-notebooks`.

## What to expect from this pull request's builds

The keys don't change, so every site restores its cache, and the notebook build takes every page from it. Each site's HTML gains the button and `_notebooks/`. I'll compare the result with the series' own sites (dp's 52 notebooks, as in QuantEcon/lecture-dp#87's comparison) and post it here.

actionlint is clean. Copilot: not requested (Matt, 2026-11-22).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01WT8bMZxoF4m8xKRb8BcHnG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant