Repository navigation
Problem types: Phase 1's harness, in NumPy, Numba and JAX - #24
Conversation
A new problems/ folder: P1 (value function iteration), P3 (the endogenous grid method), P4 (Monte Carlo) and P7 (a Kalman filter), each with a lecture's model and written in NumPy, Numba and JAX, timed as used in a fresh process per cell on numpy, numba, numba-parallel, jax-cpu and jax-gpu. Each solve runs to the lecture's tolerance, records its iterations, and is checked against NumPy's answer in float64. P7 sweeps the work in each step: filters batched with vmap, and the state size. precision/env_info.py now records Numba's version and NUMBA_ settings. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMbJUx63ms5Evcjx1Un
There was a problem hiding this comment.
🟡 Changes recommended
An unresolved finding remains, flagging the captured T_START timestamp in problems/run_cell.py as unused dead code that should be removed to avoid confusion.
1 open issue
What changed in this PR
This PR adds Phase 1 of the problem-type benchmark harness from issue #5, in a new problems/ folder. It implements four QuantEcon problem types (P1 value function iteration, P3 endogenous grid method, P4 Monte Carlo wealth dynamics, P7 Kalman filter), each written idiomatically in NumPy, Numba and JAX, and timed across problem sizes and backends (numpy, numba, numba-parallel, jax-cpu, jax-gpu). The design closely mirrors the existing precision/ harness: one fresh process per cell, cold/warm times kept apart, result dtype asserted, and every answer checked against the NumPy float64 baseline. No measured runs are included yet.
Changes:
- New
problems/suite:spec.py(JAX/Numba-free problem catalog), one module per problem (vfi,egm,wealth,kalman) with shared inputs + per-stack builders, pluscommon.py(Tauchen chain, answer sampling). - New driver/runtime:
run_cell.py(times one cell in isolation),run_suite.py(per-size backend sweeps with timeout/memory skipping),summarise.py(markdown tables + disagreement/iteration flags), and pinnedconstraints.txt. - Documentation and env plumbing:
problems/README.md, a top-level README entry, andprecision/env_info.pyextended to recordnumba/llvmliteversions andNUMBA_flags.
I verified that the three stacks for each problem are mathematically consistent (VFI Bellman indexing, EGM interpolation/expectation, Kalman gain/log-likelihood shapes, wealth Kesten update), that dtype is preserved across float32/float64 paths, and that the harness wires model/BUILDERS/sample and result-row keys together correctly. The only concrete issue found is minor (dead code).
| File | Description |
|---|---|
problems/spec.py |
Problem catalog (sizes, sweeps, precisions, memory estimates, answer checks); JAX/Numba-free for planning. |
problems/common.py |
Shared Tauchen discretisation and fixed-position answer sampling. |
problems/vfi.py |
P1 value function iteration in NumPy/Numba/JAX. |
problems/egm.py |
P3 endogenous grid method; column-wise interp in Numba to match NumPy. |
problems/wealth.py |
P4 Monte Carlo wealth dynamics; shared aggregate path, per-stack shocks. |
problems/kalman.py |
P7 batched Kalman filter log-likelihood; batch/state sweeps. |
problems/run_cell.py |
Times one cell in a fresh process; asserts result dtype. Unused T_START leftover flagged. |
problems/run_suite.py |
Driver: per-size backend sweeps, memory/timeout skipping, JSONL output. |
problems/summarise.py |
Markdown tables of warm/cold times; flags answer and iteration disagreements. |
problems/constraints.txt |
Pinned jax/numpy/scipy/numba/llvmlite releases for cross-platform comparability. |
problems/README.md |
Documents problems, backends, running, method and output. |
README.md |
Adds problems/ to the repo structure and a category section. |
precision/env_info.py |
Records numba/llvmlite versions and NUMBA_ env flags. |
Review effort: Balanced
Copilot's review: import_s is timed around the stack's import, and the driver's process_s covers the whole process, so the start time was unused. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMbJUx63ms5Evcjx1Un

Phase 1 of #5's harness, in a new
problems/folder: P1, P3, P4 and P7, each written in NumPy, Numba and JAX and timed as used across problem sizes. The design is recorded on #5. Nothing has run on a measured machine yet. The platform runs wait forqe-wharton1-gputo be free and for a plan for the M6 to be agreed.vfi, value function iterationopt_savings_1egm, the endogenous grid methodifp_egm_jaxwealth, Monte Carlowealth_dynamics_jaxkalman, a sequential recursionprecision/'s Kalman filtervmap; 2 to 200 statesThe backends are
numpy,numba(parallel=False),numba-parallel,jax-cpuandjax-gpu.What's in it
problems/spec.pyproblems/vfi.py,egm.py,wealth.py,kalman.pyproblems/run_cell.pyproblems/run_suite.pyprecision/run_matrix.py. Each size runs every backend before the next size starts, and once a backend times out its larger sizes are skippedproblems/summarise.pyproblems/constraints.txtprecision/env_info.pynumba,llvmliteandNUMBA_settingsChecked on
qe-mini1, as development runs rather than measurementsqe-wharton1-gpu, with the card, I estimate 2.5 to 3 h, since its single-threaded cells will be slower.@then fails on the mixed dtypes. Each Numba version now takes its constants in the cell's precision.np.interpsearches the grid afresh for every point, and ran 7× slower than NumPy at 20,000 points. It now interpolates each column in one call, as NumPy does.Not tested:
jax-gpu, since there's no GPU here. It runs the same JAX code asjax-cpu, underprecision/'s GPU environment settings, and its first run will be on the TITAN RTX.🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMbJUx63ms5Evcjx1Un