stan-dev / stan-dev/rstan

report where cached compiled model was obtained from if `verbose=TRUE`

Open
#957 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

Currently, even if verbose=TRUE, the function stan_model does not report whether a precompiled model was found, or from where. This makes debugging segfaults induced by loading a previously built but incompatible model difficult.

Description:

I encountered this after I had run some code with auto_write=TRUE on our cluster with R 3.6.3, then later ran the same code with R 4.0.2; the result was a segfault, and - foolishly - it took me quite a while to figure out that the problem was a .rds file. In the course of tracking this down, I had set auto_write=FALSE and then run it with stan_model(..., verbose=TRUE), expecting it would tell me if it was obtaining a cached model, but it did not. Additional verbosity wouldn't have avoided the problem entirely (I needed to rtm), but it would have helped.

Reproducible Steps:

Run

library(rstan)
rstan_options(auto_write = TRUE)

schools_data <- list(
  J = 8,
  y = c(28,  8, -3,  7, -1,  1, 18, 12),
  sigma = c(15, 10, 16, 11,  9, 11, 10, 18)
)
model <- stan_model(file="schools.stan", verbose=TRUE)
fit <- stan( file = "schools.stan", data = schools_data,
             chains = 1, warmup = 100, iter = 200, cores = 1, refresh = 0)

twice; once under R 3.6.3 and then again under R 4.0.2. The result is a segfault (of course), but more importantly, stan_model only outputs:

TRANSLATING MODEL 'schools' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model 'schools'.

 *** caught segfault ***
address 0x2aaabf663008, cause 'invalid permissions'
Expected Output:

Perhaps this expression could be extended to include something like

if (verbose) message(sprintf("reloading compiled Stan model from %s", file.rds))

Also, this line might include

if (verbose) messge(sprintf("reloading compiled Stan model from stanfit object %s", i))

and this line might include

if (verbose) messge(sprintf("reloading compiled Stan model from stanmodel object %s", i))

Contributor guide

No contributing guide indexed for this repository

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

Start in rstan/rstan/R/rstan.R at the stan_model cache-loading paths referenced in the issue, including the branches for cached files and existing stanfit or stanmodel objects. Run the provided schools.stan example with verbose=TRUE and confirm that each cached-model source is reported before loading.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
developer-experience
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.