Repository navigation
Fix diagnose: send error= argument and remove its output directory - #873
Merged
WardBrian merged 2 commits intoOct 26, 2026
Merged
Conversation
The error argument was passed to CmdStan as epsilon=<error>. The output directory was created with mkdtemp and never removed; it is now a TemporaryDirectory. Closes stan-dev#871 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013imjkuZ1miKJ7HzHWg6Ku2
WardBrian
reviewed
Oct 26, 2026
| cmdstanpy_tmp = set(os.listdir(_TMPDIR)) | ||
|
|
||
| with caplog.at_level(logging.DEBUG, logger="cmdstanpy"): | ||
| for _ in range(3): |
Member
There was a problem hiding this comment.
Why does it need to run 3 times?
Contributor
Author
There was a problem hiding this comment.
It doesn't. I copied the loop from the log_prob test in #869, where the bug was temporary directories piling up across calls. Here a single call already shows the directory is removed, so the test now calls diagnose once, in both the success and the failure case.
One call is enough to show its output directory is removed. The repeated calls were copied from the log_prob test, where directories accumulated across calls. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013imjkuZ1miKJ7HzHWg6Ku2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Submission Checklist
Summary
Closes #871.
CmdStanModel.diagnosehad two defects.errorargument was sent to CmdStan asepsilon=<error>, so CmdStan never receivederror=, and passing both arguments putepsilonon the command line twice. It now sendserror=<error>.tempfile.mkdtemp(prefix=self.name, dir=_TMPDIR)and never removed. It is now atempfile.TemporaryDirectory(prefix=self.name, dir=_TMPDIR)in the samewithstatement as the JSON inputs, as in Remove log_prob's temporary output directory when the call returns #869. It is still nested under_TMPDIR. The output is read inside thewithblock, so the returned DataFrame is unchanged.Tests (
test/test_model.py):test_diagnose_error_argumentchecks that the logged command carrieserror=and a singleepsilon=.test_diagnose_removes_output_dircallsdiagnosethree times on the success path and on theRuntimeErrorpath, and asserts that the entries of_TMPDIRare unchanged and that the output was written under_TMPDIR.Testing
Python 3.12,
pip install -e ".[all,test]":pytest test/test_model.py test/test_log_prob.py: 33 passed, 2 failed. The failures aretest_compile_forceandtest_model_paths. They fail the same way without this change (my sandbox cannot write to/and has a read-only compile path), so they are unrelated.pytest test/test_model.py -k diagnosewithout themodel.pychange: the 3 new tests fail (test_diagnose_error_argument,test_diagnose_removes_output_dir[False],[True]); the existingtest_diagnosepasses.AI disclosure, per the Stan AI Contribution Policy: this change was prepared with Claude Code (Anthropic).
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):
Aleksandr Tarutin
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:
🤖 Generated with Claude Code
https://claude.ai/code/session_013imjkuZ1miKJ7HzHWg6Ku2