CmdStanpy Error code -11

When I tried to sample my model with CmdStanpy, it suddenly appeared error code -11. I tried to print something in the model but there is nothing. This maybe means that the sampling did not even start. Is there any idea about what the error is?

import os

import time

start_time = time.time()
fit = model.sample(data=lg_data_stan, inits=0.1, chains=4, max_treedepth=10, adapt_delta=0.9,
        iter_warmup=1000, save_warmup=True, iter_sampling=1000, thin=2, show_progress=True, output_dir= path + '/output/', 
elapsed_time = time.time() - start_time

@mitzimorris @ahartikainen

CmdStanPy doesn’t stream the sampler output to the console; just messages for when each chain starts and finishes. the console output is captured and saved to an output file.

so lack of console output doesn’t indicate whether or not the sampler failed to start.
again, the -11 error code is the result of treating a signed int as an unsigned char.
the signed int return code is 127 + 11 = 138 - perhaps an out-of-memory error?

what exactly is in data=lg_data_stan ?
what platform are you running on?
if you can share model and details about the data, that would help debug your problem.
as for CmdStanPy, we’ll work on better error handling, error messages.


@evangeline - working on improving CmdStanPy error handling - issue is when subprocess throws error, try to get system message; make sure error code prints correctly · Issue #357 · stan-dev/cmdstanpy · GitHub

also, noticed that previously, error code -11 was reported and the solution was to rebuild CmdStan - C++ failure while compiling cmdstanpy model with reduce_sum_static - #11 by rok_cesnovar

it’s necessary to recompile CmdStan whenever there’s an software update to your C++ toolchain. this is because CmdStan pre-compiles as much of the world as it can beforehand (headers and libraries). when you recompile a Stan model, the system can’t link the newly compiled Stan model with the precompiled bits, resulting in some kind of system error.

whatever the cause of the error, more info would be useful so that we can robustify the code and add more troubleshooting info to the docs.


Thank you so much for your nice help! I reviewed my code of the model and found a bug about the for loop. The dimension of matrix used in loop is larger than the dimension of data I input. Now I have solved the problem.
Thanks again!

The Stanc compiler should generate code that checks for these kinds of errors to prevent segfaults and instead pinpoint the line in the program where the indexing error occurs. filed a bug report on the compiler: Compiler allows out-of-bounds indexing, Stan programs seg-faulting · Issue #847 · stan-dev/stanc3 · GitHub

update: evidently the Stanc3 compiler doesn’t do this - it’s a known bug - Indexing out-of-bounds not always handled properly · Issue #776 · stan-dev/stanc3 · GitHub