# CmdStanpy Error code -11

**URL:** <https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051>\
**Category:** General\
**Created:** [March 2, 2021, 10:03am UTC](https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051 "2021-03-02T10:03:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![evangeline](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@evangeline](https://discourse.mc-stan.org/u/evangeline)\
**Post date:** [March 2, 2021, 10:03am UTC](https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051/1 "2021-03-02T10:03:56Z")

</div>

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/', 
        save_diagnostics=True)
elapsed_time = time.time() - start_time

```

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [March 6, 2021, 5:50pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051/2 "2021-03-06T17:50:57Z")

</div>

@mitzimorris @ahartikainen

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [March 6, 2021, 9:23pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051/3 "2021-03-06T21:23:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [March 8, 2021, 8:55pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051/4 "2021-03-08T20:55:00Z")

</div>

@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](https://github.com/stan-dev/cmdstanpy/issues/357)

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](https://discourse.mc-stan.org/t/c-failure-while-compiling-cmdstanpy-model-with-reduce-sum-static/17285/11)

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.

---

<div class="post-metadata">

**Author:** ![evangeline](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@evangeline](https://discourse.mc-stan.org/u/evangeline)\
**Post date:** [March 9, 2021, 8:09am UTC](https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051/5 "2021-03-09T08:09:41Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [March 9, 2021, 8:35pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-error-code-11/21051/6 "2021-03-09T20:35:57Z")

</div>

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](https://github.com/stan-dev/stanc3/issues/847)

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](https://github.com/stan-dev/stanc3/issues/776)
