[optgrowth_fast/ogm_crra.py] Update np.random → Generator API#963
Open
Chihiro2000GitHub wants to merge 1 commit into
Open
[optgrowth_fast/ogm_crra.py] Update np.random → Generator API#963Chihiro2000GitHub wants to merge 1 commit into
Chihiro2000GitHub wants to merge 1 commit into
Conversation
40 tasks
📖 Netlify Preview Ready!Preview URL: https://pr-963--sunny-cactus-210e3e.netlify.app Commit: Build Info
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates legacy NumPy random API usage in
_static/lecture_specific/optgrowth_fast/ogm_crra.pyas part of QuantEcon/meta#299. The legacy global random-state calls are replaced with an explicitnp.random.default_rng()generator.Details
@jitclassOptimalGrowthModel_CRRA.__init__. Following the QuantEcon jitclass convention,rngis passed in as an argument (not stored as a class attribute), andnp.random.seed(seed)/np.random.randn(shock_size)are replaced withrng.standard_normal(shock_size).seedparameter is dropped from the constructor; reproducibility now comes from the caller creatingrng = np.random.default_rng(seed)and passing it in. This changes the__init__signature (rngadded,seedremoved), so call sites must construct withOptimalGrowthModel_CRRA(rng).:load:/referenceoptgrowth_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 constructrngand pass it in.rng.standard_normal(shock_size)call and passing aGeneratorinto the@jitclasscompile, run, and remain reproducible under Numba 0.62.1 (the same pattern was checked in the companionogm.pyPR).Note for reviewers
While migrating I noticed a pre-existing bug unrelated to this change:
u_prime_invis defined asdef u_prime_inv(c):(missingself) yet its body referencesself.γ, so calling it would raiseNameError. 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.