# Pystan, changing maximum treedepth

**URL:** <https://discourse.mc-stan.org/t/pystan-changing-maximum-treedepth/22681>\
**Category:** Modeling\
**Created:** [May 25, 2021, 9:27am UTC](https://discourse.mc-stan.org/t/pystan-changing-maximum-treedepth/22681 "2021-05-25T09:27:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pystan\_Beginner](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@Pystan\_Beginner](https://discourse.mc-stan.org/u/Pystan_Beginner)\
**Post date:** [May 25, 2021, 9:27am UTC](https://discourse.mc-stan.org/t/pystan-changing-maximum-treedepth/22681/1 "2021-05-25T09:27:27Z")

</div>

For a current fit I need to adjust the maximum treedepth. I am using Pystan.  
In the forum I found:

```
fit = sm.sampling(..., control=dict(max_treedepth=15))

```

This however yields me just another error “{‘json’: {‘control’: [‘Unknown field.’]}}”.  
Thanks in advance.

---

<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:** [May 25, 2021, 3:09pm UTC](https://discourse.mc-stan.org/t/pystan-changing-maximum-treedepth/22681/2 "2021-05-25T15:09:35Z")

</div>

Hi,

PyStan 3 follows similar names as CmdStan.

[https://pystan.readthedocs.io/en/latest/reference.html#stan.model.Model.hmc\_nuts\_diag\_e\_adapt](https://pystan.readthedocs.io/en/latest/reference.html#stan.model.Model.hmc_nuts_diag_e_adapt)

> **[CmdStan](https://mc-stan.org/users/interfaces/cmdstan)**

> **[9 MCMC Sampling using Hamiltonian Monte Carlo | CmdStan User’s Guide](https://mc-stan.org/docs/2_26/cmdstan-guide/mcmc-config.html#integration-time)**
>
> CmdStan user’s guide.

Following should work.

```
posterior = stan.Model(data=data)
fit = posterior.sample(..., max_depth=11)

```

Read also upgrading guide in PyStan docs.

---

<div class="post-metadata">

**Author:** ![jfalcon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jfalcon/32/12184_2.png) [@jfalcon](https://discourse.mc-stan.org/u/jfalcon)\
**Post date:** [July 26, 2021, 6:42am UTC](https://discourse.mc-stan.org/t/pystan-changing-maximum-treedepth/22681/3 "2021-07-26T06:42:04Z")

</div>

Hi Ari,

Following on the same topic of using extra keywords in pystan 3.2

I’d like to get the output CSV file with samples, so that I can do some monitoring in realtime.

CmdStan specifies the use of " output file=XXX.csv". How can I specify this in pystan? I’ve tried different options without success.

Apologies if I’ve missed something obvious.

Thanks!  
Jesus

---

<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:** [July 26, 2021, 7:19am UTC](https://discourse.mc-stan.org/t/pystan-changing-maximum-treedepth/22681/4 "2021-07-26T07:19:41Z")

</div>

There is no output csv file.

To do realtime things, you need to somehow edit pystan codebase so you have access to samples when they come in from httpstan.

---

<div class="post-metadata">

**Author:** ![jfalcon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jfalcon/32/12184_2.png) [@jfalcon](https://discourse.mc-stan.org/u/jfalcon)\
**Post date:** [July 26, 2021, 7:32am UTC](https://discourse.mc-stan.org/t/pystan-changing-maximum-treedepth/22681/5 "2021-07-26T07:32:25Z")

</div>

Understood. Thanks for the prompt reply.

Cheers,  
Jesus
