Skip to content

🌐 [translation-sync] [inventory_q.md] Update np.random → Generator API - #217

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

🌐 [translation-sync] [inventory_q.md] Update np.random → Generator API#217
mmcky wants to merge 2 commits into
mainfrom
translation-sync-2026-07-31T23-19-35-pr-1012

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

#1012 - [inventory_q.md] Update np.random → Generator API

Files Updated

  • ✏️ lectures/inventory_q.md
  • ✏️ .translate/state/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.

Copilot AI review requested due to automatic review settings July 31, 2026 23:19
@mmcky mmcky added the action-translation PRs created by QuantEcon/action-translation label Jul 31, 2026
Copilot AI review requested due to automatic review settings July 31, 2026 23:19
@mmcky mmcky added automated Automated sync PR opened by action-translation action-translation PRs created by QuantEcon/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 e4918fe
🔍 Latest deploy log https://app.netlify.com/projects/astonishing-narwhal-a8fc64/deploys/6a6d2d8cb4c870000813fac5
😎 Deploy Preview https://deploy-preview-217--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: WARN | Model: claude-sonnet-5 | Date: 2026-07-31
Routing: editor — verdict WARN (auto-merge requires PASS); 1 syntax error(s); 1 blocker finding(s); 1 major finding(s); 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 8/10
Overall 8.9/10

Summary: The translation of the changed sections (Simulating the optimal policy, Implementation, Visualizing learning over time) is accurate, fluent, and terminologically consistent with the glossary. There is one critical LaTeX delimiter error in 'The Q-table and the role of the max' section (technically outside the strictly listed changed sections but adjacent) that would break rendering — however checking the officially modified sections list, this issue falls just outside them, so it's flagged as a minor formatting note for completeness. Overall the translation quality is high with natural academic register and correct technical terminology throughout the three modified sections. Technical concepts such as Q-factor Bellman equation, off-policy learning, optimistic initialization, and epsilon-greedy exploration are translated accurately and consistently with standard RL terminology Code comments and docstrings are fully and naturally translated into Chinese while preserving code functionality Mathematical notation and equations are preserved correctly throughout, with only one minor delimiter slip

⚠️ Markdown Syntax Errors (CRITICAL)

  • 🔴 经理在时间 $t+1 实际采取 哪个动作是一个单独的决策。 — missing closing $ delimiter after $t+1, causing broken math rendering

Suggestions:

  • [major · formatting] lectures/inventory_q.md — ### The Q-table and the role of the max: Math delimiter error: '经理在时间 $t+1 实际采取 哪个动作是一个单独的决策' has an unclosed inline math expression ($t+1 is not closed with a second $), which will break rendering. The original English text is 'Which action the manager actually takes at time $t+1$ is a separate decision.' → 经理在时间 $t+1$ 实际采取 哪个动作是一个单独的决策。
  • [minor · terminology] lectures/inventory_q.md — ### Implementation, code comment '接下来我们运行 $n$ = 500 万步': The English text states 'run n = 5 million steps' but the code sets n = 5_000_000, which matches '500万'. This is actually correct, just double-checked for consistency - no issue found here upon closer review.
  • [minor · fluency] lectures/inventory_q.md — ### The Q-table and the role of the max: The phrase '因为更新目标中的 $\max$ 总是指向 $q^$,无论经理如何选择动作' slightly reorders the English 'Because the max in the update target always points toward q regardless of how the manager selects actions' — acceptable but could be smoother by keeping the reason clause together. → 因为无论经理如何选择动作,更新目标中的 $\max$ 始终指向 $q^*$

🔍 Diff Quality

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

Summary: The RNG refactor (seed-based globals to explicit rng objects) was correctly and completely mirrored in the target document at matching positions, with translated docstrings and unchanged heading metadata.


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 translation-sync PR updates the Chinese inventory_q lecture to match upstream changes that migrate simulation and Q-learning code from legacy np.random.* calls toward the newer RNG/Generator-style API, and refreshes the translation state metadata accordingly.

Changes:

  • Updated inventory simulation and Q-learning code cells to use np.random.default_rng() / rng.* APIs and propagate seeds via RNG objects.
  • Adjusted plotting helper signature to accept a seed parameter for reproducible time series plots.
  • Updated .translate/state/inventory_q.md.yml sync metadata (source SHA, model, tool version, timestamps).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lectures/inventory_q.md Replaces legacy np.random.* usage with Generator-style RNG usage in simulation and Q-learning code cells.
.translate/state/inventory_q.md.yml Updates translation-sync state metadata to reflect the new upstream source and tool/model versions.
Suppressed comments (7)

lectures/inventory_q.md:386

  • plot_ts 这里将 np.random.default_rng(seed) 传入 @numba.jit(nopython=True)sim_inventories,会触发 Numba 对 Generator 对象的类型推断/编译问题。若 sim_inventories 改回 seed 参数(见上条建议),这里也应按新签名传递 seed
def plot_ts(ts_length=200, fontsize=10, seed=0):
    X = sim_inventories(ts_length, σ_star, p, np.random.default_rng(seed))
    fig, ax = plt.subplots()

lectures/inventory_q.md:710

  • 这里同样把 np.random.default_rng(sim_seed) 作为实参传给 @numba.jit(nopython=True)sim_inventories。如果 sim_inventories 使用 seed(更兼容 Numba nopython),请改为传 seed=sim_seed
# 最优策略
X_opt = sim_inventories(ts_length, σ_star, p,
                        np.random.default_rng(sim_seed), X_init)
axes[0].plot(X_opt, alpha=0.7)

lectures/inventory_q.md:720

  • 循环内同样将 Generator 传入 @numba.jit(nopython=True)sim_inventories。如果按建议改回 seed 参数,请在此处也改为 seed=sim_seed,以保持“所有面板使用相同需求序列”的设定。
for i in range(n_snaps):
    σ_snap = snapshots[i]
    X = sim_inventories(ts_length, σ_snap, p,
                        np.random.default_rng(sim_seed), X_init)
    axes[i + 1].plot(X, alpha=0.7)

lectures/inventory_q.md:591

  • 这里使用 rng.geometric 会要求 Numba 支持 np.random.Generator 方法调用。若按建议改回 seed + np.random.*,这里应使用 np.random.geometric
        # === 抽取 D_{t+1} 并观察结果 ===
        d = rng.geometric(p) - 1
        reward = min(x, d) - c * a - κ * (a > 0)

lectures/inventory_q.md:582

  • 这里使用 rng.integers 会要求 Numba 支持 np.random.Generator 方法调用。若按建议改回 seed + np.random.*,这里应使用 np.random.randint
    x = X_init
    a = rng.integers(0, K - x + 1)

lectures/inventory_q.md:612

  • ε-贪婪分支里调用了 rng.random() / rng.integers()。若按建议改回 seed + np.random.*(以保持 Numba nopython 兼容),这里应改为 np.random.random() / np.random.randint()
        x = x_next
        if rng.random() < ε:
            a = rng.integers(0, K - x + 1)
        else:

lectures/inventory_q.md:631

  • q_learning 包装函数当前创建 rng = np.random.default_rng(seed) 并传入 @numba.jit(nopython=True) 的 kernel。若 kernel 改回接收 seed 并在内部 np.random.seed(seed)(更兼容 Numba nopython),这里应去掉 rng 并直接传 seed
    K = len(x_values) - 1
    if snapshot_steps is None:
        snapshot_steps = np.array([], dtype=np.int64)
    rng = np.random.default_rng(seed)
    return q_learning_kernel(K, p, c, κ, β, n_steps, X_init,
                             ε_init, ε_min, ε_decay, q_init, snapshot_steps, rng)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lectures/inventory_q.md
Comment on lines 368 to 372
@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 thread lectures/inventory_q.md
Comment on lines 569 to 571
def q_learning_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)
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request August 1, 2026 00:00 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