stan-dev / stan-dev/cmdstanr

Errors re-rendering quarto html with cached chunks and cmdstanr.

Open
#1,012 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #1176 by @avehtari — closed without merging
bug
Dominant language
R
Stars
160
Forks
69
Avg merge
1d 19h
Merged PRs (30d)
15

Description

Describe the bug

Quarto fails to re-render to html following trivial changes to code chunks that use cmdstanr objects.

processing file: 01_data-exclusions.qmd
  |............................................... |  98% [model_1_postsum]    
Quitting from lines  at lines 616-637 [model_1_postsum] (01_data-exclusions.qmd)
Error in `read_cmdstan_csv()`:
! Assertion on 'files' failed: File does not exist: '/var/folders/ms/m90tgryx74362fqn7d65tl7w0000gn/T/Rtmp5yoGqf/model_8cda69ac3b06c9b214d4a12ede85f4f8-202407191622-1-7cf94c.csv'.
Backtrace:
 1. fit01$draws(variables = c("a_bar", "sigma", "p"), format = "df")
 2. private$read_csv_(...)
 3. cmdstanr::read_cmdstan_csv(...)
 4. cmdstanr:::assert_file_exists(files, access = "r", extension = "csv")
 5. checkmate::makeAssertion(files, res, .var.name, add)
 6. checkmate:::mstop(...)
                                                                                                                
Execution halted

To Reproduce

Turn on Quarto cache in the header:

...
execute:
   cache: true
...

Read in a stan model from file using the chunk options:

```{cmdstan file = "path/to/stan/model.stan", output.var = 'm01'}
``

Sample:

``` {r}
fit01 <- m01$sample( [...] )
``

Write some code to summarise the model output or whatever.

Render to html.

Make a small change to anything that calls the model fit object fit01. In my case it will happen if I just add an empty line after an unedited chunk.

Try to render to html again.

Error occurs.

Expected behavior
The document is rendered after making small changes without the need to clear the cache and refit all models etc,

Operating system
MacOs 14.0

CmdStanR version number
0.7.1

Additional context
None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the Quarto cache settings, the cmdstan chunk that creates m01, and the R code calling fit01$sample() and fit01$draws(). Compare a second HTML render after a trivial edit, and consider the issue done when cached CmdStanR objects remain usable without clearing the cache or refitting models.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.