2. I'd like to figure out a simpler policy for RStan user
error reporting than having them run through Stan command
line. It just seems like too much of an installation and
manual reading exercise for an error report.
> set_cppo('debug')
mode debug for compiling C++ code is set
>
> scode <- '
+ parameters {
+ real y[1];
+ }
+
+ model {
+ y[2] ~ normal(0, 1);
+ }
+ '
>
> library(rstan)
> a <- stan(model_code = scode, iter = 10, chains = 1)
TRANSLATING MODEL 'scode' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'scode' NOW.
SAMPLING FOR MODEL 'scode' NOW (CHAIN 1).
Error in sampler$call_sampler(args_list[[i]]) :
INDEX OPERATOR [] OUT OF BOUNDS; index=2; lower bound=1; upper bound=1; index position=1; y
error occurred during calling the sampler; sampling not done
>
Last, just a reminder: when set_cppo set the mode as debug, it would stay in that mode. So remember to change that back to 'fast' mode if 'debug' mode is not needed any more.
Ben--
In RStan, if we set_cppo('debug'), R would not crash for this example. set_cppo('debug') would not set -DNDEBUG flag. By default, Stan does not set this flag.
Ben--
--
I am afraid not. In detail, at most I can do is to pass -DDEBUG. Then the flag used would be-DNDEBUG -DDEBUGI do not know what would happen for gcc and specific C++ code if both of them are defined.
parameters { real y[1];}model { y[2] ~ normal(0, 1);}goodrich@CYBERPOWERPC:/tmp/SU/oob$ gdb ./oobGNU gdb (GDB) 7.4.1-debianCopyright (C) 2012 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type "show copying"and "show warranty" for details.This GDB was configured as "x86_64-linux-gnu".For bug reporting instructions, please see:Reading symbols from /tmp/SU/oob/oob...done.(gdb) catch throwCatchpoint 1 (throw)(gdb) runStarting program: /tmp/SU/oob/oob [Thread debugging using libthread_db enabled]Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".STAN SAMPLING COMMANDdata = (specified model requires no data)init = random initializationinit tries = 1samples = samples.csvappend_samples = 0save_warmup = 0seed = 2890366062 (randomly generated)chain_id = 1 (default)iter = 2000warmup = 1000thin = 1 (default)equal_step_sizes = 0leapfrog_steps = -1max_treedepth = 10epsilon = -1epsilon_pm = 0delta = 0.5gamma = 0.05
Program received signal SIGSEGV, Segmentation fault.0x0000000000411df7 in stan::agrad::var::val (this=0x7fffffffcda0) at src/stan/agrad/agrad.hpp:415415 return vi_->val_;(gdb) bt#0 0x0000000000411df7 in stan::agrad::var::val (this=0x7fffffffcda0) at src/stan/agrad/agrad.hpp:415#1 0x0000000000412396 in boost::math::isnan<stan::agrad::var> (v=...) at src/stan/agrad/error_handling.hpp:70#2 0x000000000040e7db in stan::math::(anonymous namespace)::not_nan<stan::agrad::var, double, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>, false>::check (function=0x49477c "stan::prob::normal_log(%1%)", y=..., name=0x48ca0f "Random variable", result=0x7fffffffcf48) at src/stan/math/error_handling.hpp:101#3 0x000000000042f5c3 in stan::math::check_not_nan<stan::agrad::var, double, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> > (function=0x49477c "stan::prob::normal_log(%1%)", y=..., name=0x48ca0f "Random variable", result=0x7fffffffcf48) at src/stan/math/error_handling.hpp:149#4 0x0000000000424c58 in stan::prob::normal_log<true, stan::agrad::var, int, int, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> > (y=..., mu=@0x7fffffffd10c: 0, sigma=@0x7fffffffd108: 1) at src/stan/prob/distributions/univariate/continuous/normal.hpp:63#5 0x000000000041c2ff in stan::prob::normal_log<true, stan::agrad::var, int, int> (y=..., mu=@0x7fffffffd10c: 0, sigma=@0x7fffffffd108: 1) at src/stan/prob/distributions/univariate/continuous/normal.hpp:137#6 0x0000000000417a51 in oob_model_namespace::oob_model::log_prob (this=0x7fffffffd610, params_r__=..., params_i__=..., pstream__=0x0) at /tmp/SU/oob/oob.cpp:101#7 0x00000000004170a3 in stan::model::prob_grad_ad::grad_log_prob (this=0x7fffffffd610, params_r=..., params_i=..., gradient=..., output_stream=0x0) at src/stan/model/prob_grad_ad.hpp:44#8 0x000000000040ba73 in stan::mcmc::leapfrog (model=..., z=..., x=..., m=..., g=..., epsilon=1, error_msgs=0x0, output_msgs=0x0) at src/stan/mcmc/util.hpp:67---Type <return> to continue, or q <return> to quit---#9 0x000000000043a760 in stan::mcmc::hmc_base<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >::find_reasonable_parameters (this=0x7fffffffd770) at src/stan/mcmc/hmc_base.hpp:64#10 0x00000000004309e8 in stan::mcmc::hmc_base<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >::hmc_base (this=0x7fffffffd770, model=..., epsilon=-1, epsilon_pm=0, epsilon_adapt=true, delta=0.5, gamma=0.050000000000000003, rand_int=..., params_r=0x7fffffffddf0, params_i=0x7fffffffde10) at src/stan/mcmc/hmc_base.hpp:153#11 0x0000000000425eaf in stan::mcmc::nuts_diag<boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >::nuts_diag (this=0x7fffffffd770, model=..., maxdepth=10, epsilon=-1, epsilon_pm=0, epsilon_adapt=true, delta=0.5, gamma=0.050000000000000003, base_rng=..., params_r=0x7fffffffddf0, params_i=0x7fffffffde10) at src/stan/mcmc/nuts_diag.hpp:127#12 0x000000000041e251 in stan::gm::nuts_command<oob_model_namespace::oob_model> (argc=1, argv=0x7fffffffe2b8) at src/stan/gm/command.hpp:479#13 0x000000000040e6ae in main (argc=1, argv=0x7fffffffe2b8) at /tmp/SU/oob/oob.cpp:206
goodrich@CYBERPOWERPC:/tmp/SU/oob$ gdb ./oobGNU gdb (GDB) 7.4.1-debianCopyright (C) 2012 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type "show copying"and "show warranty" for details.This GDB was configured as "x86_64-linux-gnu".For bug reporting instructions, please see:Reading symbols from /tmp/SU/oob/oob...done.(gdb) catch throwCatchpoint 1 (throw)(gdb) runStarting program: /tmp/SU/oob/oob [Thread debugging using libthread_db enabled]Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".Catchpoint 1 (exception thrown), 0x00007ffff791db90 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6(gdb) bt#0 0x00007ffff791db90 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6#1 0x0000000000408221 in stan::math::(anonymous namespace)::raise_range_error (max=1, i=2, msg=0x48d2c8 "y", idx=1) at src/stan/math/matrix.hpp:156#2 0x00000000004082a2 in stan::math::(anonymous namespace)::check_range (max=1, i=2, msg=0x48d2c8 "y", idx=1) at src/stan/math/matrix.hpp:166#3 0x000000000041c58c in stan::math::get_base1<stan::agrad::var> (x=..., i=2, error_msg=0x48d2c8 "y", idx=1) at src/stan/math/matrix.hpp:192#4 0x0000000000417c68 in oob_model_namespace::oob_model::log_prob (this=0x7fffffffd610, params_r__=..., params_i__=..., pstream__=0x6e81a0) at /tmp/SU/oob/oob.cpp:101#5 0x00000000004172cd in stan::model::prob_grad_ad::grad_log_prob (this=0x7fffffffd610, params_r=..., params_i=..., gradient=..., output_stream=0x6e81a0) at src/stan/model/prob_grad_ad.hpp:44#6 0x000000000041d9a8 in stan::gm::nuts_command<oob_model_namespace::oob_model> (argc=1, argv=0x7fffffffe2b8) at src/stan/gm/command.hpp:374#7 0x000000000040e75a in main (argc=1, argv=0x7fffffffe2b8) at /tmp/SU/oob/oob.cpp:206
Ben--
--
On a side note, is it possible to fork() and trap the segfault when it's run in R?
Or run the model in a separate process with an exec() call?
In theory it should be possible unless R has some restriction on calling exec(). The only problem is that it makes communicating back to R a little more complicated and it take some work to make it cross platform.