Repository navigation
Read no warmup draws from fixed_param CSV files - #1343
Merged
Merged
Conversation
Draft
2 tasks done
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v1.0 #1343 +/- ##
==========================================
- Coverage 94.00% 93.16% -0.85%
==========================================
Files 19 19
Lines 9232 7346 -1886
==========================================
- Hits 8679 6844 -1835
+ Misses 553 502 -51 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jgabry
approved these changes
Nov 17, 2026
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
The CmdStan fixed_param sampler writes no warmup draws, even when
save_warmup = true.read_cmdstan_csv()did not handle this case. For a CSV file withalgorithm = fixed_paramandsave_warmup = true, it took the firstceiling(iter_warmup / thin)rows as warmup draws. The post-warmup draws then did not include these rows. If the file had no more rows than this number, the post-warmup draws were NULL.as_cmdstan_fit()gave the same wrong draws.cmdstanr sets
save_warmup = FALSEfor fixed_param, so fits run by cmdstanr do not have this problem. CmdStan accepts fixed_param withsave_warmup=1. With CmdStan 2.40.0,num_warmup=10 num_samples=5 save_warmup=1 algorithm=fixed_paramwrites 5 rows. The CSV header hassave_warmup = trueandalgorithm = fixed_param. In the Stan services code,stan::services::sample::fixed_param()has no warmup argument and callsgenerate_transitions()only for the sampling iterations.For a model without parameters and the default algorithm, the CSV header has
algorithm = hmc. CmdStan 2.40.0 then writes the warmup rows: a cmdstanr run withsave_warmup = TRUE, 20 warmup and 10 sampling iterations gave 30 rows. This PR does not change that case.Changes
read_cmdstan_csv()reads no warmup draws whenalgorithm = fixed_param, and setsmetadata$save_warmupto 0. Thus$draws(inc_warmup = TRUE)on a fit fromas_cmdstan_fit()stops with an error, as it does for a fixed_param fit that cmdstanr ran.read_cmdstan_csv()states that it reads no warmup draws for fixed_param.Tests
The new test in
tests/testthat/test-csv.Rruns fixed_param with cmdstanr and changessave_warmup = falsetosave_warmup = truein copies of the CSV files. Then it compares the output ofread_cmdstan_csv()andas_cmdstan_fit()for these copies with the original fit.I ran the tests at commit
9db49d7eon Triton (Linux) with R 4.5.3, CmdStan 2.40.0-rc0 (it reports version 2.39.0) and testthat 3.3.2:test-csv.Rtest-fit-mcmc.Rtest-model-sample.RI also ran
test-csv.RwithR/csv.Rfromv1.0and the new test, on my Linux workstation with R 4.6.2 and CmdStan 2.40.0. Only the new test fails:metadata$save_warmupis 1.read_cmdstan_csv()(the test has 30 warmup iterations and 20 rows).$draws()on the fit fromas_cmdstan_fit()gives an error.I did not edit
NEWS.md. Please add an item if you want one.Not changed
$draws(inc_warmup = TRUE)says "Please rerun the model with save_warmup = TRUE". For fixed_param, a rerun withsave_warmup = TRUEgives no warmup draws. This PR does not change the message.check_csv_metadata_matches()still comparesiter_warmupwhensave_warmup = 1. Two fixed_param CSV files withsave_warmup = trueand a differentnum_warmup(iter_warmupin the metadata) have the same number of rows. But they give the error "do not match in the number of output samples". Only CSV files that cmdstanr did not write have this case, and I did not change it.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):
Aalto University
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:
This PR was assisted by Claude