Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

diagnose: the error argument is sent as epsilon; the output directory is never removed

未关闭 适合新手
#871 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

该缺陷位于 cmdstanpy/model.py 中的 CmdStanModel.diagnose:error 分支追加的是 epsilon= 而不是 error=,并且通过 tempfile.mkdtemp 在 _TMPDIR 下创建的输出目录从未被删除。请先阅读 log_prob 的测试,它们检查记录的命令,可作为新测试的范例。完成的标准是:命令中包含 error=,并且在成功和失败两条路径上调用后,_TMPDIR 下的条目数保持不变。请先查看 #869,因为该 issue 称清理方案已在那里达成一致。

由索引模型根据 Issue 内容生成。

描述

Summary

CmdStanModel.diagnose (cmdstanpy develop at the time of writing, also 1.3.0) has two bugs:

  1. The error argument is sent as epsilon. CmdStan never receives error=, and when both arguments are given, epsilon appears twice on the command line.
  2. Each call leaves a temporary output directory under _TMPDIR, removed only at interpreter exit. This is the same pattern as #867, which is being fixed for log_prob in #869.
Where

cmdstanpy/model.py, CmdStanModel.diagnose, on develop:

if epsilon is not None:
    cmd.append(f"epsilon={epsilon}")
if error is not None:
    cmd.append(f"epsilon={error}")      # should be f"error={error}"
...
output_dir = tempfile.mkdtemp(prefix=self.name, dir=_TMPDIR)   # never removed

CmdStan 2.40.0's argument tree accepts both sub-arguments under diagnose test=gradient (output of <model> diagnose help-all):

gradient
  Valid subarguments: epsilon, error
  epsilon=<double>   Finite difference step size     Defaults to 1e-6
  error=<double>     Error threshold                 Defaults to 1e-6
Effect
  • diagnose(error=x) silently sets the finite-difference step to x, and the error threshold stays at its default 1e-6. The gradient check then judges against a threshold the caller did not ask for, using a step size the caller did not ask for.
  • diagnose(epsilon=a, error=b) passes epsilon=a epsilon=b.
  • The output directory accumulates in long-running processes, as described in #867.
Suggested fix
  • Send f"error={error}".
  • Scope the output directory with tempfile.TemporaryDirectory(prefix=self.name, dir=_TMPDIR), the approach agreed on #869.
  • Add a test asserting that the command carries error= (the logged command, as the log_prob tests do) and that _TMPDIR's entry count is unchanged after calls on both the success path and the failure path.

We can fold this into #869, or open a separate PR, whichever you prefer.

Versions

cmdstanpy develop (also 1.3.0), CmdStan 2.40.0, Python 3.12, Linux x86_64.

主要语言
Python
星标
198
派生
82
平均合并
4 天 11 小时
30 天内合并 PR
3

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

stan-dev/cmdstanpy 的其他 Issue

查看 stan-dev/cmdstanpy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。