diagnose: the error argument is sent as epsilon; the output directory is never removed
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 62/100
Research direction
The bug is in cmdstanpy/model.py, in CmdStanModel.diagnose: the error branch appends epsilon= instead of error=, and the output directory from tempfile.mkdtemp under _TMPDIR is never removed. Start by reading the log_prob tests, which check the logged command and are the model for a new test. Done means the command carries error=, and the entry count under _TMPDIR is unchanged after calls on both the success and failure paths. Check with #869 first, since the issue says the cleanup approach was agreed there.
Written by the indexing model from the issue text.
Description
Summary
CmdStanModel.diagnose (cmdstanpy develop at the time of writing, also 1.3.0) has two bugs:
- The
errorargument is sent asepsilon. CmdStan never receiveserror=, and when both arguments are given,epsilonappears twice on the command line. - 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 forlog_probin #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)passesepsilon=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 thelog_probtests 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.
- Dominant language
- Python
- Stars
- 198
- Forks
- 82
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stan-dev/cmdstanpy
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
laplace_sample: expose CmdStan's diagnostic_file (the Hessian at the mode)Possibly taken @atarutin claimed this 4 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Release 2.0Open
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
feature
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
All issues in stan-dev/cmdstanpy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
task
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
danparshall/claude_researcher#87 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
datajoint/datajoint-python#1586 ·
Maintainers usually reply within 1 day
-
1D intercept of length 1 is accepted as `fix_params` in population GLM with more than 1 unitPossibly taken @dhvani7014 claimed this today. Openbug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
flatironinstitute/nemos#642 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
uniswap-python/uniswap-python#487 ·