Skip to content

[optgrowth_fast/ogm.py] Update np.random → Generator API#962

Open
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-optgrowth-fast-ogm
Open

[optgrowth_fast/ogm.py] Update np.random → Generator API#962
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-optgrowth-fast-ogm

Conversation

@Chihiro2000GitHub

@Chihiro2000GitHub Chihiro2000GitHub commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR migrates legacy NumPy random API usage in _static/lecture_specific/optgrowth_fast/ogm.py as part of QuantEcon/meta#299. The legacy global random-state calls are replaced with an explicit np.random.default_rng() generator.

Details

  • The random draw sits inside the @jitclass OptimalGrowthModel.__init__. Following the QuantEcon jitclass convention, rng is passed in as an argument (not stored as a class attribute), and np.random.seed(seed) / np.random.randn(shock_size) are replaced with rng.standard_normal(shock_size).
  • The seed parameter is dropped from the constructor; reproducibility now comes from the caller creating rng = np.random.default_rng(seed) and passing it in. This changes the __init__ signature (rng added, seed removed), so call sites must construct with OptimalGrowthModel(rng).
  • Within this repository, no lecture appears to :load:/reference optgrowth_fast/ogm.py, so there are no in-repo call sites to update here. Any external call sites (e.g. in other lecture repos) will need to construct rng and pass it in.
  • Verified locally that the sized rng.standard_normal(shock_size) call and passing a Generator into the @jitclass compile, run, and remain reproducible under Numba 0.62.1.

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-962--sunny-cactus-210e3e.netlify.app

Commit: e3360fd


Build Info

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