# I cannot run simple examples in pystan

**URL:** <https://discourse.mc-stan.org/t/i-cannot-run-simple-examples-in-pystan/32777>\
**Category:** PyStan\
**Tags:** pystan\
**Created:** [September 15, 2023, 9:31am UTC](https://discourse.mc-stan.org/t/i-cannot-run-simple-examples-in-pystan/32777 "2023-09-15T09:31:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fponce](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/fponce/32/17503_2.png) [@fponce](https://discourse.mc-stan.org/u/fponce)\
**Post date:** [September 15, 2023, 9:31am UTC](https://discourse.mc-stan.org/t/i-cannot-run-simple-examples-in-pystan/32777/1 "2023-09-15T09:31:15Z")

</div>

I am following this [tutorial](https://bob-carpenter.github.io/stan-getting-started/stan-getting-started.html), but the examples do not run.

I have compiled successfully models with pystan recently, but these examples without model or data block seem problematic.

The first example is:

```plaintext
data {
  int<lower=0> N;
  real<lower=0, upper=1> theta;
}
generated quantities {
  int<lower=0, upper=N> y = binomial_rng(N, theta);
}

```

The python code is:

```plaintext
import stan

N = 100
θ = 0.3

with open('model.stan', 'r') as f:
    model = f.read()

data = {'N': N, 'theta': θ}

posterior = stan.build(model, data, random_seed=123)
res = posterior.sample(num_chains=1, num_samples=10, num_warmup=0)
df = res.to_frame()

print(df.head())

```

The program stops at the line `res = posterior.sample`, and I get an AssertionError. Stan warns me that _Posterior is improper. Please check your model._

Similarly, if I try the stan code:

```plaintext
generated quantities {
  real<lower=-1, upper=1> x = uniform_rng(-1, 1);
  real<lower=-1, upper=1> y = uniform_rng(-1, 1);
  int<lower=0, upper=1> inside = x^2 + y^2 < 1;
  real<lower=0, upper=4> pi = 4 * inside;
}

```

I have the same problems.

- Ubuntu 20.04
- Python 3.9
- PyStan 3.7

---

<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:** [September 15, 2023, 10:40am UTC](https://discourse.mc-stan.org/t/i-cannot-run-simple-examples-in-pystan/32777/2 "2023-09-15T10:40:00Z")

</div>

> [@fponce](#):
>
> `res = posterior.sample(num_chains=1, num_samples=10, num_warmup=0)`

Can you try fixed\_param

`res = posterior.fixed_param(num_chains=1, num_samples=10)`

---

<div class="post-metadata">

**Author:** ![fponce](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/fponce/32/17503_2.png) [@fponce](https://discourse.mc-stan.org/u/fponce)\
**Post date:** [September 15, 2023, 12:42pm UTC](https://discourse.mc-stan.org/t/i-cannot-run-simple-examples-in-pystan/32777/3 "2023-09-15T12:42:09Z")

</div>

> [@ahartikainen](#):
>
> fixed\_param

Thank you, it runs! But is the method ‘fixed\_param’ mentioned in the documentation?

---

<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:** [September 18, 2023, 11:49am UTC](https://discourse.mc-stan.org/t/i-cannot-run-simple-examples-in-pystan/32777/4 "2023-09-18T11:49:15Z")

</div>

Not sure, We should have API somewhere, but need to check is this the case
