Skip to content

🌐 [translation-sync] [rs_inventory_q.md] Update np.random → Generator API - #215

Open
mmcky wants to merge 2 commits into
mainfrom
translation-sync-2026-07-31T23-19-10-pr-1013
Open

🌐 [translation-sync] [rs_inventory_q.md] Update np.random → Generator API#215
mmcky wants to merge 2 commits into
mainfrom
translation-sync-2026-07-31T23-19-10-pr-1013

Conversation

@mmcky

@mmcky mmcky commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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.yml

Details

  • Source Language: en
  • Target Language: zh-cn
  • Model: claude-sonnet-5

This PR was created automatically by the translation action.

@mmcky
mmcky requested review from Copilot July 31, 2026 23:19
@mmcky mmcky added action-translation PRs created by QuantEcon/action-translation automated Automated sync PR opened by action-translation labels Jul 31, 2026
@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploy Preview for astonishing-narwhal-a8fc64 ready!

Name Link
🔨 Latest commit aeb1653
🔍 Latest deploy log https://app.netlify.com/projects/astonishing-narwhal-a8fc64/deploys/6a6d2d7326561400087c2e3b
😎 Deploy Preview https://deploy-preview-215--astonishing-narwhal-a8fc64.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

Copy link
Copy Markdown

✅ Translation Quality Review

Verdict: PASS | Model: claude-sonnet-5 | Date: 2026-07-31
Routing: editor — 1 minor finding(s) in gating categories (accuracy/terminology/syntax/diff-check/other)


📝 Translation Quality

Criterion Score
Accuracy 9/10
Fluency 9/10
Terminology 9/10
Formatting 9/10
Overall 9/10

Summary: 改动章节(模拟最优策略、实现、可视化学习随时间的演变)的翻译整体质量很高,准确传达了原文的技术含义,数学公式和代码块完整无误,术语使用规范且与术语表保持一致。仅发现一处关于步数表达本地化的细微建议,属于风格层面,不影响理解或准确性。未发现任何语法错误或格式问题。 数学公式、代码块与变量名在改动章节中均完整保留,未出现公式或代码损坏 术语翻译(如'贪婪策略'、'延续值'、'确定性等价物')在改动章节中保持一致,且符合术语表标准 对Q-learning更新规则、乐观初始化等复杂技术内容的翻译准确且流畅,逻辑清晰易懂

Suggestions:

  • [minor · terminology] lectures/rs_inventory_q.md — ### 运行 Q-learning: 英文原文写 'We run n = 5 million steps',译文将其转换为'我们运行 n = 500 万步',数字表达方式做了本地化调整(用中文习惯的'万'为单位),这属于合理适配但与原文数字表述形式不完全对应,可考虑保留阿拉伯数字'5,000,000'或明确写出'500万'的等价关系以避免歧义。 → 我们运行 n = 5,000,000(500 万)步
  • [nit · fluency] lectures/rs_inventory_q.md — ### 实现方案 numbered list: 列表项开头'2. 在每一步:'与其后的子列表项之间的层级关系在中文里读起来略显生硬,但整体可理解,无需修改,仅作为风格提示。

🔍 Diff Quality

Check Status
Scope Correct
Position Correct
Structure Preserved
Heading-map Correct
Overall 10/10

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(...) / Generator methods instead of np.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 keep sim_inventories in nopython mode, it should receive a primitive seed (or pre-generated shocks), not a Generator object.
    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 a seed instead (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 Generator into a nopython-jitted function is likely to fail. Pass a seed instead (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 removing rng), this draw should use np.random.geometric so the function remains nopython-compilable.
        d = rng.geometric(p) - 1

lectures/rs_inventory_q.md:641

  • q_learning_rs now creates a Generator and passes it into the nopython-jitted kernel. If the kernel is kept in nopython mode, pass the integer seed through 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 when rng is a NumPy Generator. Use np.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.

Comment on lines 355 to 359
@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
Comment on lines 577 to 581
@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)) # 用于学习率的访问计数
@github-actions

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request July 31, 2026 23:49 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action-translation PRs created by QuantEcon/action-translation automated Automated sync PR opened by action-translation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants