# Pystan crushes with exit code 139 (interrupted by signal 11: SIGSEGV)

**URL:** <https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306>\
**Category:** General\
**Created:** [June 30, 2020, 12:08pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306 "2020-06-30T12:08:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerpa](https://avatars.discourse-cdn.com/v4/letter/n/85e7bf/32.png) [@nerpa](https://discourse.mc-stan.org/u/nerpa)\
**Post date:** [June 30, 2020, 12:08pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/1 "2020-06-30T12:08:30Z")

</div>

That’s a bit scary, but suddenly all of my models that were working previously, started to crush once the sampling is done:

`Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)`

How can I solve it??

---

<div class="post-metadata">

**Author:** ![nerpa](https://avatars.discourse-cdn.com/v4/letter/n/85e7bf/32.png) [@nerpa](https://discourse.mc-stan.org/u/nerpa)\
**Post date:** [June 30, 2020, 12:30pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/2 "2020-06-30T12:30:19Z")

</div>

Update - I checked it on three different machines. Models weren’t changed. Different models crush in all three machines.

---

<div class="post-metadata">

**Author:** ![nerpa](https://avatars.discourse-cdn.com/v4/letter/n/85e7bf/32.png) [@nerpa](https://discourse.mc-stan.org/u/nerpa)\
**Post date:** [June 30, 2020, 1:50pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/3 "2020-06-30T13:50:34Z")

</div>

Update 2 - for models that do run, I get the following error after sampling:

```
/Users/venv/lib/python3.6/site-packages/pystan/diagnostics.py:213: RuntimeWarning: invalid value encountered in true_divide
  numer = ((np.diff(energies, axis=0)**2).sum(axis=0)) / chain_len
/Users/venv/lib/python3.6/site-packages/numpy/core/fromnumeric.py:3584: RuntimeWarning: Degrees of freedom <= 0 for slice
  **kwargs)
/Users/venv/lib/python3.6/site-packages/numpy/core/_methods.py:186: RuntimeWarning: invalid value encountered in true_divide
  arrmean, rcount, out=arrmean, casting='unsafe', subok=False)
/Users/venv/lib/python3.6/site-packages/numpy/core/_methods.py:207: RuntimeWarning: invalid value encountered in true_divide
  ret, rcount, out=ret, casting='unsafe', subok=False)
WARNING:pystan:Truncated summary with the 'fit. __repr__' method. For the full summary use 'print(fit)'

```

When I hit print(fit), I get  
`ValueError: Stan model anon_model_c827ea328eaaf47fe42cabc2262ba4a1 contains no samples.`

All model worked just fine before.

---

<div class="post-metadata">

**Author:** ![nerpa](https://avatars.discourse-cdn.com/v4/letter/n/85e7bf/32.png) [@nerpa](https://discourse.mc-stan.org/u/nerpa)\
**Post date:** [June 30, 2020, 2:59pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/4 "2020-06-30T14:59:05Z")

</div>

Update 3 (feeling really stupid) - so all models crush when I run then with 1 chain and small number of iterations (500). All goes back to normal when I increase both (4 chains and 1500 iterations). Have no idea why this is, but all works again.

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [June 30, 2020, 3:10pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/5 "2020-06-30T15:10:40Z")

</div>

> [@nerpa](#):
>
> Update 3 (feeling really stupid) - so all models crush when I run then with 1 chain and small number of iterations (500).

Don’t feel stupid, that’s definitely not supposed to crash. Can you show the exact code that crashes?

---

<div class="post-metadata">

**Author:** ![nerpa](https://avatars.discourse-cdn.com/v4/letter/n/85e7bf/32.png) [@nerpa](https://discourse.mc-stan.org/u/nerpa)\
**Post date:** [June 30, 2020, 3:18pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/6 "2020-06-30T15:18:48Z")

</div>

this is one of them (the one we discussed in a separate thread)

```stan
functions {
    real comp_error(real c, real Delta, real sigma){
    real out;
    out = 0.5 * (erfc((c-Delta)/(sqrt(2)*sigma)) + erfc((c+Delta)/(sqrt(2)*sigma)));
    return out;
    }
}

data {
    int<lower=1> N;                                             
    int<lower=1> P;                                             
    int<lower=1> T_max;                                        
    int<lower=0> Tr[N];                                        
    int<lower=0> Nb[N, T_max];
    int<lower=0> Tar[N, T_max];
    real<lower=0> Delta[N, T_max];   
    int<lower=-1, upper=1> choice_cd[N, T_max];             
    }

parameters {
    // Hyper(group)-parameters
    vector[P] mu_prior;
    vector<lower=0>[P] tau;

    // Subject-level raw parameters
    vector[N] c_pr;
    vector[N] sigma_pr;  
}

transformed parameters {
    vector<lower=0>[N] c;
    vector<lower=0>[N] sigma;

    c = exp(c_pr);
    sigma = exp(sigma_pr);
}

model {
    real f;
    real h;

    //priors
    mu_prior ~ normal(0,5); //weakly informative priors on the regression coefficients
    tau ~ cauchy(0,2.5); //weakly informative priors, see section 6.9 in STAN user guide
    c_pr ~ normal(mu_prior[1],tau[1]);
    sigma_pr ~ normal(mu_prior[2],tau[2]);

    for (n in 1:N) {
        f = comp_error(c[n], 0, sigma[n]);
        for (t in 1:Tr[n]) {
                                        
            if (choice_cd[n,t] == 1 && Delta[n,t] > 0) {
                h = comp_error(c[n], Delta[n,t], sigma[n]);
                target += log(1 - (pow((1-h), Tar[n,t]) * pow((1-f),(Nb[n,t]-Tar[n,t]))));                
            }
            else if (choice_cd[n,t] == 0 && Delta[n,t] > 0) {
                h = comp_error(c[n], Delta[n,t], sigma[n]);
                target += log(pow((1-h),Tar[n,t]) * pow((1-f),(Nb[n,t]-Tar[n,t])));
            }
            else if (choice_cd[n,t] == 1 && Delta[n,t] == 0) {
                target += log(1 - pow((1-f),Nb[n,t]));
            }
            else if (choice_cd[n,t] == 0 && Delta[n,t] == 0) {
                target += log(pow((1-f),Nb[n,t]));
            }        
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [June 30, 2020, 3:35pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/7 "2020-06-30T15:35:33Z")

</div>

Hey, @ahartikainen, PyStan devs might want to know that

```python
model.sampling(iter=500,warmup=500)

```

segfaults. That seems kind of bad.

@nerpa note that `iter` includes warmup. If you want 500 warmup and 500 post-warmup samples you need to call

```python
model.sampling(iter=1000,warmup=500,chains=1)

```

---

<div class="post-metadata">

**Author:** ![nerpa](https://avatars.discourse-cdn.com/v4/letter/n/85e7bf/32.png) [@nerpa](https://discourse.mc-stan.org/u/nerpa)\
**Post date:** [June 30, 2020, 3:39pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/8 "2020-06-30T15:39:19Z")

</div>

yeah! Learning it the hard way. I had  
`fit = stan.sampling(data=data, iter=500, chains=1, warmup=500, thin=5)`

Thanks again!

---

<div class="post-metadata">

**Author:** ![RJTK](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/rjtk/32/8360_2.png) [@RJTK](https://discourse.mc-stan.org/u/RJTK)\
**Post date:** [June 30, 2020, 3:48pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/9 "2020-06-30T15:48:18Z")

</div>

It doesn’t explain why it segfaults, but calling with `sampling(iter=500, warmup=500)` explains the zero division errors from Python – even if it didn’t crash there wouldn’t be any samples available.

---

<div class="post-metadata">

**Author:** ![ahartikainen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ahartikainen/32/321_2.png) [@ahartikainen](https://discourse.mc-stan.org/u/ahartikainen)\
**Post date:** [June 30, 2020, 4:05pm UTC](https://discourse.mc-stan.org/t/pystan-crushes-with-exit-code-139-interrupted-by-signal-11-sigsegv/16306/10 "2020-06-30T16:05:30Z")

</div>

Good to know. It did that some point with Windows.

I think we should add a check for that.

@ariddell I think this is already fixed in pystan3
