Skip to content

[optgrowth_fast/ogm_crra.py] Update np.random → Generator API#963

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

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

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_crra.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_CRRA.__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_CRRA(rng).
  • Within this repository, no lecture appears to :load:/reference optgrowth_fast/ogm_crra.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 (the same pattern was checked in the companion ogm.py PR).

Note for reviewers

While migrating I noticed a pre-existing bug unrelated to this change: u_prime_inv is defined as def u_prime_inv(c): (missing self) yet its body references self.γ, so calling it would raise NameError. I have left it untouched to keep this PR focused on the random API migration, but I'm happy to fix it here (or in a separate PR) if you'd prefer — just let me know.

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

Commit: 84d292f


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