Skip to content

[uncertainty_traps.md] Update np.random → Generator API - #1011

Merged
kp992 merged 1 commit into
mainfrom
update-rng-uncertainty-traps
Jul 31, 2026
Merged

[uncertainty_traps.md] Update np.random → Generator API#1011
kp992 merged 1 commit into
mainfrom
update-rng-uncertainty-traps

Conversation

@Chihiro2000GitHub

Copy link
Copy Markdown
Contributor

Summary

This PR migrates legacy NumPy random API usage in uncertainty_traps.md as part of QuantEcon/meta#299.

The three np.random.randn(...) calls are replaced with draws from an explicit generator rng = np.random.default_rng(), which is created in the solution block and passed into gen_aggregates.

Related PRs and issues

I checked for open PRs and issues related to this lecture. No open PR modifies uncertainty_traps.md, and no open issue concerns this migration.

Details

  • UncertaintyTrapEcon.gen_aggregates now takes rng as an argument, and its two draws use rng.standard_normal(...).
  • In the solution to Exercise 2, rng = np.random.default_rng() is created before the simulation loop, np.random.randn(sim_length)rng.standard_normal(sim_length), and the two econ.gen_aggregates() call sites pass rng.
  • The whole lecture now draws from that single generator, so no hidden global random state remains.
  • No fixed seed was introduced, since the lecture did not seed before. The lecture already tells the reader that the output varies from run to run.
  • The lecture contains no Numba (@jit, @njit, @jitclass, parallel=True, prange) code.
  • A full local build completed successfully and uncertainty_traps.md executed without errors.

Note for reviewers

gen_aggregates now takes rng as an argument, so its two call sites changed as well. Happy to give the class its own generator instead if you would rather keep the signature unchanged.

Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-1011--sunny-cactus-210e3e.netlify.app

Commit: c4e96a3

📚 Changed Lectures


Build Info

@kp992
kp992 merged commit b90d96d into main Jul 31, 2026
1 check passed
@kp992
kp992 deleted the update-rng-uncertainty-traps branch July 31, 2026 23:18
@mmcky

mmcky commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-python.zh-cn
Translation PR: QuantEcon/lecture-python.zh-cn#214
Files synced (1):

  • lectures/uncertainty_traps.md

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.

3 participants