stan-dev / stan-dev/rstan

stan() (occasionally) returns nothing with no errors

Open
#520 3 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:

Running code such as model_fit <- stan() occasionally results in no assignment / output, despite Stan appearing to run normally. In fact the variable model_fit does not exist in the environment.

Description:

I call rstan::stan() with multiple chains from within Rstudio, and assign it to some variable. Upon the completion of the sampling process, either the assignment doesn't occur, or something goes awry in the return process.

This might have something to do with:

  • The long runtime of my model (and the fact I run said long model from within an Rstudio session, as opposed to calling Rscript on the fitter.R file)
  • The enterprise environment in which I run Stan

I realise that this issue is going to be practically impossible to track down (and might even be specific to my environment), but I would feel remiss not to mention it here. (I'm also somewhat irked as I just lost a model that ran for 90,000 seconds :/ ).

Reproducible Steps:

I have attached the stan model with which I encountered the issue, as well as a script to generate data. (Unable to share data in R code detailed below), and the script used to fit the model.

2018-04-18_double-tanh-log-time-series.zip

I'm going to keep trying to reproduce this, and will update this thread if I can find something that breaks consistently.

Current Output:

If applicable, any relevant output from RStan.

Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> setwd(".../projects/2018-04-18_double-tanh-log-time-series/")
> library(rstan)
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.17.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
> library(ddcurves2)
Loading required package: Rcpp
> stan_dat <- list(n_depths = length(Crux_KP150_Phs1$depths),
+                  n_times = nrow(Crux_KP150_Phs1$density_mat),
+                  depths = Crux_KP150_Phs1$depths,
+                  densities = Crux_KP150_Phs1$density_mat)
> prefit <- stan(file = "../../projects/ddcurves2/src/stan_files/double_tanh_time_series.stan",
+                chains = 0, 
+                data = stan_dat)
DIAGNOSTIC(S) FROM PARSER:
WARNING: left-hand side variable (name=beta_orig) occurs on right-hand side of assignment, causing inefficient deep copy to avoid aliasing.

In file included from C:/Program Files/R/R-3.4.3/library/BH/include/boost/config.hpp:39:0,
                 from C:/Program Files/R/R-3.4.3/library/BH/include/boost/math/tools/config.hpp:13,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math/rev/core/var.hpp:7,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math/rev/core.hpp:12,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from filea2fc75ef7c06.cpp:8:
C:/Program Files/R/R-3.4.3/library/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined
 #  define BOOST_NO_CXX11_RVALUE_REFERENCES
 ^
<command-line>:0:0: note: this is the location of the previous definition
In file included from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math/rev/core.hpp:44:0,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Program Files/R/R-3.4.3/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from filea2fc75ef7c06.cpp:8:
C:/Program Files/R/R-3.4.3/library/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:17: warning: 'void stan::math::set_zero_all_adjoints()' defined but not used [-Wunused-function]
     static void set_zero_all_adjoints() {
                 ^
the number of chains is less than 1; sampling not done
> phi_prime <- rbeta(6, 6, 1)
> kappa_prime <- (1 - phi_prime) * log(c(1023, 1.1, 50, 42, 100, 45))
> init_sub <- list(beta_prime_t0 = log(rlnorm(6, meanlog = log(c(1023, 1.1, 50, 42, 100, 45)), sdlog = 0.001)),
+                  phi_prime = phi_prime,
+                  kappa_prime = kappa_prime,
+                  beta_prime_sigma = rlnorm(6, meanlog = log(c(0.18, 0.12, 26.1, 8.09, 12.6, 6.65)), sdlog = 0.002),
+                  innovations_prime = array(0, dim = c(737 - 1, 6)), 
+                  sigma_curve = rlnorm(1, meanlog = log(0.1), sdlog = 0.2))
> model_fit <- stan(fit = prefit,
+                   data = stan_dat,
+                   iter = 120,
+                   warmup = 100,
+                   save_warmup = FALSE,
+                   chains = 3,
+                   cores = 3,
+                   control = list(adapt_delta = 0.95,
+                                  max_treedepth = 20),
+                   verbose = TRUE,
+                   refresh = 1
+                   )

CHECKING DATA AND PREPROCESSING FOR MODEL 'double_tanh_time_series' NOW.

COMPILING MODEL 'double_tanh_time_series' NOW.

STARTING SAMPLER FOR MODEL 'double_tanh_time_series' NOW.
Loading required namespace: rstudioapi

> saveRDS(model_fit,
+         file = paste0("../../results/",
+                       format(Sys.time(), "%F_%H-%M-%S"),
+                       "_double-tanh-time-series-log-test.rds"))
Error in saveRDS(model_fit, file = paste0("../../results/", format(Sys.time(),  : 
  object 'model_fit' not found

I have attached the stanprogress file from the tempdir(), which indicates that stan seemed to run and complete normally.
filea2fc2f677584_StanProgress.txt

Expected Output:

model_fit to exist as a stanfit object, with samples. Or an error that indicates that the return process / assignment failed.

RStan Version:
[1] ‘2.17.3’
R Version:
[1] "R version 3.4.3 (2017-11-30)"
Operating System:

Windows 7 Enterprise, SP1.

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 with the attached Stan model, data-generation script, fitting script, and the StanProgress file; reproduce the run from fitter.R in RStudio using rstan 2.17.3 on Windows. Compare whether the long multi-chain run creates the assigned model_fit object or surfaces an error, and document a consistent reproduction or a clear reason the assignment is lost.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.