Repository navigation
mccall_q: draw from a seeded Generator, as intermediate's copy does - #78
Conversation
The code change of QuantEcon/lecture-python.myst#959 (merged 2026-07-31), applied to dp's copy of the lecture. The Q-learning code called np.random.random() inside a numba jitclass, which np.random.seed(123) in the Python namespace does not reach, so the page's results changed from build to build. It now creates rng = np.random.default_rng(123) and passes it to every method that draws. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL
Validation: a full validationAs for dp's last upgrade (#75): a fresh build with no cache of main and of this pull request, each executing all 51 notebooks in
mccall_q now gives the same results on every build. This pull request's own CI run when it opened, 45012239888, executed mccall_q independently of the fresh build above. The two executions agree:
Against main. mccall_q's Q-learning results differ, as they must, since they now come from the seeded Generator rather than an unseeded stream:
The other three figures, which do not depend on the draws, are byte-identical. Build logs. No Sphinx warning on either side. The rest of the HTML. 19 of 57 pages differ in all. Besides mccall_q, there are 17 pages of output noise, the same as between any two builds: unseeded draws, timings and solver printouts. There is also the status page, with its build times. The warnings in the cell outputs are the same on both sides. odu's solver prints one more "Error at iteration" progress line, because its unseeded draws converged in a few more iterations, as they vary between any two builds. |
There was a problem hiding this comment.
🔵 Needs a closer look
Regenerated Q-learning plots were unavailable for inspection, so a subject-matter reviewer must confirm that the seeded results still support the lecture’s convergence and quit/no-quit comparisons.
No open issues 🎉
What changed in this PR
Makes the McCall Q-learning lecture’s results and figures reproducible across builds by adopting the seeded random generator used in the upstream lecture.
Changes:
- Replaces global NumPy seeding with
np.random.default_rng(123). - Passes the generator through Q-learning methods and callers, using it for wage-offer and exploration draws.
| File | Description |
|---|---|
lectures/mccall_q.md |
Threads a seeded generator through Q-learning execution and plotting code. |
Review effort: Balanced (adaptive)
Addendum: the new figures against intermediate's published pageintermediate's copy of this lecture has drawn from the same seeded Generator since QuantEcon/lecture-python.myst#959. Its published page, https://python.quantecon.org/mccall_q.html, read on 2026-11-22, can therefore be compared with this pull request's build.
Only the legend differs: intermediate has since moved it below the plot and rounds the errors to two places, a change this pull request does not bring. What the prose says. The text after the first |
Validation correction: pages whose only difference is a figureThe evidence comment above says 19 of 57 pages differ. The comparison behind it compared a figure only when the page wraps it in a link, and this series doesn't, so a page whose only difference is a figure wasn't counted. With every figure now compared by content, 30 of 57 pages differ. The 11 added pages differ only in figures:
This pull request's own pages. mccall_q, the page it changes: figures 3, 5 and 6 differ from main's because they are now drawn from the seeded generator, and the other three are byte-identical, as the evidence comment says. This pull request's two executions of the lecture give byte-identical figures. None of the added pages is one this pull request changes, and each also differs when the same main build is compared with the build of #81, which changes only the conda channel's name and installs the same packages. The conclusion doesn't change: no other page's prose differs. |
What
The code change of QuantEcon/lecture-python.myst#959 (merged 2026-07-31), applied as it stands to dp's copy of mccall_q. The Q-learning code calls
np.random.random()inside a numba jitclass, whichnp.random.seed(123)in the Python namespace does not reach. So the page's Q-learning results, and the figures drawn from them, change from build to build. intermediate's copy has drawn from a seeded Generator since QuantEcon/lecture-python.myst#959; dp's copy, which dp republishes from intermediate, did not follow.np.random.seed(123)rng = np.random.default_rng(123)np.random.random()(twice)rng.random()draw_offer_index(self),temp_diff(self, qtable, state, accept),run_one_epoch(self, qtable, max_times=20000),run_epochs(N, qlmc, qtable)rng, and every call passes it onThe patch is QuantEcon/lecture-python.myst#959's diff, which applies to dp's copy with no change. dp's copy differs from intermediate's in other ways too, which this leaves alone: intermediate has since renumbered the lecture (Job Search X), changed its headings to sentence case, corrected some typos, changed the legend of the
plot_epochsfigures, guarded its progress prints withn % max(1, N // 10), and dropped a repeated VFI computation. None of these affects the draws.This is part of reporting lecture fixes upstream to each lecture's source of truth (QuantEcon/project-monorepo#77).
Validation
Done on 2026-11-22, a full validation: fresh builds with no cache of this pull request and of main, every notebook executed, both green. The evidence is in the comment below.
This changes lecture content, so it needs a person's review.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL