Skip to content

Lectures run as used: aiyagari_jax and ifp_egm_jax in float32 and float64 - #3

Merged
mmcky merged 5 commits into
mainfrom
lectures-as-used
Oct 25, 2026
Merged

mmcky merged 5 commits into
mainfrom
lectures-as-used

Conversation

@mmcky

@mmcky mmcky commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Adds lectures/: whole QuantEcon lectures run as a reader or a CI build runs them. Every code cell runs in order in one fresh process, with compile time counted, timed per cell, in float64 as written or switched to float32. The first use answers project-compute's question before a card purchase (its research file, §5): on a TITAN RTX, is float64 bound by bandwidth or by FP64 arithmetic?

What it adds

Path What it is
lectures/run_lecture.py Runs any MyST lecture's code cells through IPython in one process, timing each cell. --dtype float32 rewrites the lecture's jax_enable_x64 line; --record keeps chosen values for comparing precisions
lectures/aiyagari_jax/ The scaling script for the lecture's own household operators (asset grids of 200 to 10,000), two diagnostics for the float32 slowdown, and the summaries. Its README has the method and the commands
lectures/results/qe-wharton1-gpu/2026-10-25/aiyagari_jax/ 12 whole-lecture runs (the card and its host CPU, both precisions, three each), 12 scaling runs, the diagnostics' output and the package list
lectures/ifp_egm_jax/ The second float64 lecture project-compute asked for: a check of the JAX solve at the lecture's grid, the EGM operator at savings grids of 200 to 50,000, the summary and a README
lectures/results/qe-wharton1-gpu/2026-10-25/ifp_egm_jax/ 12 solve checks and 12 scaling runs (the card and its host CPU, both precisions, three each), 6 whole-lecture runs in float64, and the package list
lectures/results/qe-mini1/2026-10-25/ The same CPU runs on qe-mini1's M6, with state.txt recording the machine before, during and after
lectures/mac_set.sh, lectures/compare_hosts.py The Mac's driver, which pauses its agents and resumes them on exit, and a side-by-side comparison of the three devices
.gitignore *.json stays ignored, except under lectures/results/

How it was run

On qe-wharton1-gpu on 2026-10-25, with nothing else running:

  • the TITAN RTX at 0b:00.0, and the Threadripper beside it;
  • driver 595.91.07, jax[cuda13] 0.12.0.1, preallocation off;
  • aiyagari_jax and ifp_egm_jax from lecture-jax at 4b939ec, unchanged apart from the precision line.

The same CPU runs were made on qe-mini1's M6, with its agents and the console's animated wallpaper paused (SIGSTOP) and resumed afterwards. While paused, the Mac idled at under 2% CPU.

What it shows, in brief

aiyagari_jax, the whole lecture:

float64 float32
Whole lecture on the card 90.7 s 1,086 s
Whole lecture on the CPU 27.0 s 261 s
  • At the lecture's own size, float64 costs nothing, and the CPU runs the lecture 3.4× faster than the card. Its time goes to launching small kernels and syncing in Python loops.
  • The float32 slowdown is the lecture's stopping rule, not the hardware. At the two highest interest rates, float32 can't bring the change in values below 1e-4, so those solves run to the 10,000-loop cap.
  • At grids of 1,000 to 10,000 points, the lecture's Bellman step is 3.3× to 8.2× slower in float64 on the card. It recomputes log(c) over every (a, z, a′), so it is bound by FP64 arithmetic. The same step over stored rewards is about 2×.

ifp_egm_jax:

  • Its EGM operator is not FP64-bound. It is 1.0× slower in float64 at the lecture's grid and 1.5× to 1.9× at savings grids of 5,000 to 50,000. Float32 converges, to within 1.6e-4 of float64's policy.
  • Neither lecture, at its own size, gives the card a precision-dependent load. On ifp_egm_jax, the JAX solve takes 4.95 s warm on the card in either precision, against 3.2 s on the CPU.

The M6 against the card:

  • As written, the M6 runs both lectures fastest: aiyagari_jax in 5.1 s against the card's 90.7 s, and ifp_egm_jax's JAX solve in 0.38 s against 4.95 s.
  • The card overtakes it only on grids 5 to 25 times the lectures' size.
  • Float64 costs the M6 about 1.3×.

The interpretation is written up in project-benchmarks-jax's findings/.

Notes

🤖 Generated with Claude Code

mmcky and others added 2 commits October 25, 2026 13:54
…1-gpu

Adds lectures/, for whole QuantEcon lectures run as a reader or a CI
build runs them: every code cell in one fresh process, compile time
counted, timed per cell, in float64 as written or switched to float32.

- lectures/run_lecture.py runs any MyST lecture that way.
- lectures/aiyagari_jax/ answers project-compute's question before a
  card purchase: on a TITAN RTX, is float64 bound by bandwidth or by
  FP64 arithmetic? It has the scaling script for the lecture's own
  household operators (asset grids of 200 to 10,000), two diagnostics
  for the float32 slowdown, and the summaries.
- lectures/results/qe-wharton1-gpu/2026-10-25/aiyagari_jax/ holds the
  runs: 12 whole-lecture runs (card and CPU, both precisions, three
  each), 12 scaling runs, the diagnostics' output and the environment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
.gitignore drops every *.json as a benchmark output, which left the 24
aiyagari_jax runs out of the previous commit. Let lectures/results/
through; other JSON stays ignored.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 25, 2026 02:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The scripts are coupled to an external lecture file and a GPU/JAX runtime that cannot be re-executed here, and they reference the precision/ directory from the still-unmerged PR #2, so a human should give final sign-off.

1 open issue
What changed in this PR

This PR adds a new lectures/ area that runs whole QuantEcon lectures "as used" — every code cell executed in order in one fresh IPython process, timed per cell, in float64 as written or rewritten to float32. Its first application answers project-compute's pre-purchase question for the aiyagari_jax lecture on a TITAN RTX (is float64 bound by bandwidth or FP64 arithmetic), and commits the raw results, diagnostics, and summariser scripts. It complements the per-kernel precision/ suite (PR #2) by measuring what a reader actually waits for.

Changes:

  • Adds run_lecture.py (generic cell-by-cell lecture timer with --dtype/--record/--env-info) plus aiyagari_jax/ scaling + diagnostic + summariser scripts.
  • Commits 12 whole-lecture runs, 12 scaling runs, diagnostics, and the package list under lectures/results/qe-wharton1-gpu/2026-10-25/.
  • Updates .gitignore to keep result JSON under lectures/results/ while still ignoring other *.json, and documents the harness in three READMEs.
File Description
lectures/​run_lecture.py Runs MyST cells via IPython, rewrites jax_enable_x64 for float32, records expressions, writes per-cell timings
lectures/​aiyagari_jax/​aiyagari_scale.py Times household operators across asset grids; adds a stored-reward greedy variant (self-checked vs get_greedy)
lectures/​aiyagari_jax/​hpi_check.py /​ bicgstab_check.py Diagnostics for the float32 slowdown (HPI loop counts; bicgstab convergence vs cap)
lectures/​aiyagari_jax/​summarise_runs.py /​ summarise_scale.py /​ policy_gap.py Build the markdown tables and fidelity checks from results
lectures/​results/​.../​* Committed run/scale JSON, logs, diagnostics, environment.txt
README.md, lectures/​README.md, lectures/​aiyagari_jax/​README.md Document the harness and reproduction steps
.gitignore Re-include lectures/results/**/*.json under the global *.json ignore

I verified both summarisers run cleanly on the committed data, the .gitignore negation behaves as intended (git check-ignore), and the headline numbers match the PR narrative. The one issue found is a documentation gap: the only documented run_lecture.py command records just "K_star", while summarise_runs.py also requires K_vals.tolist(), np.asarray(σ_star).ravel().tolist(), and str(household.a_grid.dtype).

Review effort: Balanced

Comment thread lectures/README.md Resolved
The second float64 lecture project-compute asked for. Its EGM operator
interpolates instead of searching a dense choice grid.

- lectures/ifp_egm_jax/: the JAX-solve check at the lecture's grid,
  the operator at savings grids of 200 to 50,000, the summary, the
  drivers and a README.
- lectures/results/qe-wharton1-gpu/2026-10-25/ifp_egm_jax/: 12 solve
  checks and 12 scaling runs (the card and its host CPU, both
  precisions, three each), and 6 whole-lecture runs in float64.
- The aiyagari_jax drivers, and README rows for them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mmcky mmcky changed the title Lectures run as used: aiyagari_jax in float32 and float64 on qe-wharton1-gpu Lectures run as used: aiyagari_jax and ifp_egm_jax in float32 and float64 Oct 25, 2026
mmcky and others added 2 commits October 25, 2026 15:06
- lectures/results/qe-mini1/2026-10-25/: aiyagari_jax as used and at
  scale, and ifp_egm_jax's solve check, operator scaling and float64
  runs as used, on the M6's CPU, three runs each. state.txt records the
  machine before, during and after.
- lectures/mac_set.sh, the driver: it pauses qe-mini1's agents and the
  console's animated wallpaper (SIGSTOP), and resumes them (SIGCONT) on
  exit. It also gives Remote Control its terminal back, which this run
  did by hand.
- lectures/compare_hosts.py sets the TITAN RTX, its host's Threadripper
  and the M6 side by side.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… patterns

- Each lecture's README now has a "Reproducing a run" section with the
  exact run_lecture.py and scaling commands, including the --record set
  its summary script reads. lectures/README.md says so beside its
  one-value example, as Copilot pointed out.
- mac_set.sh anchors each pgrep -f pattern to the start of its target's
  command line. Unanchored, the patterns also matched any shell whose
  command mentioned them, such as the one that launched a driver. That
  shell was then paused with the agents, as happened to a Phase 0
  launch on 2026-10-25.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants