🌐 [translation-sync] [rs_inventory_q.md] Update np.random → Generator API - #215
🌐 [translation-sync] [rs_inventory_q.md] Update np.random → Generator API#215mmcky wants to merge 2 commits into
Conversation
✅ Deploy Preview for astonishing-narwhal-a8fc64 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Translation Quality ReviewVerdict: PASS | Model: claude-sonnet-5 | Date: 2026-07-31 📝 Translation Quality
Summary: 改动章节(模拟最优策略、实现、可视化学习随时间的演变)的翻译整体质量很高,准确传达了原文的技术含义,数学公式和代码块完整无误,术语使用规范且与术语表保持一致。仅发现一处关于步数表达本地化的细微建议,属于风格层面,不影响理解或准确性。未发现任何语法错误或格式问题。 数学公式、代码块与变量名在改动章节中均完整保留,未出现公式或代码损坏 术语翻译(如'贪婪策略'、'延续值'、'确定性等价物')在改动章节中保持一致,且符合术语表标准 对Q-learning更新规则、乐观初始化等复杂技术内容的翻译准确且流畅,逻辑清晰易懂 Suggestions:
🔍 Diff Quality
Summary: The target document correctly mirrors the source's refactor of random number generation (np.random.seed -> rng-based) and a minor blank-line/spacing adjustment near the Value Function Iteration section, with no unrelated changes. This review was generated automatically by action-translation review mode. |
There was a problem hiding this comment.
Pull request overview
This automated translation-sync PR updates the Chinese lecture rs_inventory_q.md to match upstream changes that migrate random number generation from legacy np.random.* usage toward the NumPy Generator API, and refreshes the translation state metadata accordingly.
Changes:
- Updated simulation and Q-learning code cells to use
np.random.default_rng(...)/Generatormethods instead ofnp.random.seed(...)and global RNG calls. - Adjusted function signatures and call sites to pass an RNG object through simulation/Q-learning code.
- Updated translation sync state (
source-sha, sync date, model, tool version, mode).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lectures/rs_inventory_q.md | Updates RNG usage in code cells (np.random → Generator API) and minor formatting/spacing adjustments. |
| .translate/state/rs_inventory_q.md.yml | Updates translation sync metadata (source SHA, synced-at date, model, tool version, mode). |
Suppressed comments (6)
lectures/rs_inventory_q.md:378
- This call site constructs a
np.random.default_rng(...)and passes it into a@numba.jit(nopython=True)function. If you keepsim_inventoriesin nopython mode, it should receive a primitiveseed(or pre-generated shocks), not aGeneratorobject.
X = sim_inventories(ts_length, σ, model.p,
np.random.default_rng(sim_seed), X_init=K // 2)
lectures/rs_inventory_q.md:710
- Same issue as above: passing
np.random.default_rng(...)into a nopython-jitted function is likely to break compilation. Pass aseedinstead (or pre-generate the random draws outside the jitted function).
X_opt = sim_inventories(ts_length, σ_star, model.p,
np.random.default_rng(sim_seed), X_init)
lectures/rs_inventory_q.md:720
- Same issue as above: passing a NumPy
Generatorinto a nopython-jitted function is likely to fail. Pass aseedinstead (or pass in pre-generated draws).
X = sim_inventories(ts_length, σ_snap, model.p,
np.random.default_rng(sim_seed), X_init)
lectures/rs_inventory_q.md:599
- After changing the kernel to use a
seed(and removingrng), this draw should usenp.random.geometricso the function remains nopython-compilable.
d = rng.geometric(p) - 1
lectures/rs_inventory_q.md:641
q_learning_rsnow creates aGeneratorand passes it into the nopython-jitted kernel. If the kernel is kept in nopython mode, pass the integerseedthrough instead.
if snapshot_steps is None:
snapshot_steps = np.array([], dtype=np.int64)
rng = np.random.default_rng(seed)
return q_learning_rs_kernel(K, p, c, κ, β, γ, n_steps, X_init,
ε_init, ε_min, ε_decay, q_init, snapshot_steps, rng)
lectures/rs_inventory_q.md:621
- These calls to
rng.random()/rng.integers(...)won’t work in a nopython-jitted kernel whenrngis a NumPyGenerator. Usenp.random.random()/np.random.randint(...)inside the kernel (or remove nopython).
if rng.random() < ε:
a = rng.integers(0, K - x + 1)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @numba.jit(nopython=True) | ||
| def sim_inventories(ts_length, σ, p, X_init=0, seed=0): | ||
| def sim_inventories(ts_length, σ, p, rng, X_init=0): | ||
| """模拟策略 σ 下的库存动态。""" | ||
| np.random.seed(seed) | ||
| X = np.zeros(ts_length, dtype=np.int32) | ||
| X[0] = X_init |
| @numba.jit(nopython=True) | ||
| def q_learning_rs_kernel(K, p, c, κ, β, γ, n_steps, X_init, | ||
| ε_init, ε_min, ε_decay, q_init, snapshot_steps, seed): | ||
| np.random.seed(seed) | ||
| ε_init, ε_min, ε_decay, q_init, snapshot_steps, rng): | ||
| q = np.full((K + 1, K + 1), q_init) # 乐观初始化 | ||
| n = np.zeros((K + 1, K + 1)) # 用于学习率的访问计数 |
Automated Translation Sync
This PR contains automated translations from QuantEcon/lecture-python.myst.
Source PR
#1013 - [rs_inventory_q.md] Update np.random → Generator API
Files Updated
lectures/rs_inventory_q.md.translate/state/rs_inventory_q.md.ymlDetails
This PR was created automatically by the translation action.