# CmdStan & Stan 2.40 Release Candidates

**URL:** <https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585>\
**Category:** General\
**Created:** [September 9, 2026, 3:22pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585 "2026-09-09T15:22:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [September 9, 2026, 3:22pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/1 "2026-09-09T15:22:51Z")

</div>

I am happy to announce that the latest release candidates of CmdStan and Stan are now available on Github!

You can find the release candidate for CmdStan [here](https://github.com/stan-dev/cmdstan/releases/tag/v2.40.0-rc1). Instructions for installing are given at the bottom of this post.

Please test the release candidate with your models and report if you experience any problems. We also kindly invite you to test the new features and provide feedback. If you feel some of the new features could be improved or should be changed before the release, please do not hesitate to comment.

The Stan development team appreciates your time and help in making Stan better.

If everything goes according to plan, the 2.40 version will be released next week.

Below are some of the highlights of the new release.

# New options for 1d integration

Several new integration functions have been added:

- `integrate_1d_double_exponential`, a variadic version of the existing 1-d integrator
- `integrate_1d_gauss_kronrod`, a variadic function with a different quadrature rule

Preliminary documentation can be found [here](https://github.com/stan-dev/docs/pull/955).

# Matrix reshaping functions

New functions `to_vector_array(matrix) -> array[] vector` `to_row_vector_array(matrix) -> array[] row_vector`, as well as new overloads for `to_matrix` for arrays of (row-)vectors.

# New `poisson_binomial` distribution

A new discrete PMF, CDF, CCDF, and RNG functions available.

Preliminary documentation is available [here](https://github.com/stan-dev/docs/pull/974)

# Other changes

There have been various other bug fixes and usability improvements this release, thank you to everyone who reported a bug in the last few months!

The same `.stanfunctions` can be `#include`d multiple times without leading to errors about duplicated function definitions.

Updated the Math library to use Eigen 5.0.1

The vectorized RNGs were updated to fix a crash when given size-0 inputs.

The compiler has fewer dependencies, with a smaller binary size and improved speeds.

More details on all of the above and more are available in the [preliminary release notes](https://gist.github.com/WardBrian/39ccf3c1a6ab60d98aa549babc98d29a)

## How to install?

Download the tar.gz file from the link above, extract it and use it the way you use any Cmdstan release. We also have an online Cmdstan guide available at [CmdStan User’s Guide](https://mc-stan.org/docs/cmdstan-guide/).

If you are using cmdstanpy you can install the release candidate using

```no-highlight

cmdstanpy.install_cmdstan(version='2.40.0-rc1')

```

With CmdStanR you can install the release candidate using

```no-highlight

cmdstanr::install_cmdstan(version = "2.40.0-rc1", cores = 4)

```

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [September 11, 2026, 8:36pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/2 "2026-09-11T20:36:57Z")

</div>

1. I tested compiling a bunch of Stan files which use the new integrate and laplace functions, and all did compile.

2. `--Oexperimental` fails with empty loops, e.g.

```stan
parameters { real y; }
model {
  real x = 0;
  for (i in 1:0) x += 1;
  y ~ std_normal();
}

```

1. `--Oexperimental` fails with posteriordb model `state_wide_presidential_votes-hierarchical_gp.stan`. stanc accepts it, then g++ rejects the generated code:

```no-highlight
stan::model::assign(lcm_sym82__, multiply(multiply(17, prop_var), tot_var),
                    "assigning variable lcm_sym82__");
→ candidate expects 4 arguments, 3 provided

```

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [September 11, 2026, 9:58pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/3 "2026-09-11T21:58:51Z")

</div>

Thanks Aki!

#2 has an easy fix and I’ve put up a PR. #3 actually looks like an older issue, since I can recreate it on 2.39. Could be [Issue · GitHub](https://github.com/stan-dev/stanc3/issues/1463)

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [September 12, 2026, 6:55am UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/4 "2026-09-12T06:55:27Z")

</div>

Not sure in which repo this should be fixed (cmdstanr or cmdstan), so I didn’t create an issue yet (and yesterday it was just too late that I didn’t have time to create issues, and also why I didn’t check the older version for #3).

- stanc takes one optimization level and the last flag wins. For example, `--Oexperimental --O1` is byte-identical to O1 output. `cmdstanr` composes `<include-paths> <your stanc_options> <make/local STANCFLAGS>`, and if `make/local` has `STANCFLAGS=--O1`, then `stanc_options = list("Oexperimental")` is silently downgraded

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [September 12, 2026, 12:19pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/5 "2026-09-12T12:19:16Z")

</div>

I think a lot of flags have this last-wins behavior, but it’s rather complicated how Make will compose variables from different sources, so putting anything in make/local you hope to override later is probably just a hazard

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [September 12, 2026, 12:49pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/6 "2026-09-12T12:49:28Z")

</div>

I made an `cmdstanr` issue to switch order of `make/local` and `stanc_options`, so that `stanc_options` can be used to overrule `make/local` defaults

> <https://github.com/stan-dev/cmdstanr/issues/1268>
>
> \`cmdstanr\` composes \<include-paths\> \<your stanc\_options\> \<make/local STANCFLAGS\>…, which means the explicit \`stanc\_options\` can be overruled by \`make/local\`. I propose we change the order to \<make/local STANCFLAGS\> \<your stanc\_options\>, so that \`make/local\` provides the defaults which the user can override with explicit \`stanc\_options\` argument. For example, if \`make/local\` has \`--O1\` and the user wants to test \`--Oexperimental\` they could the latter with \`stanc\_options\` without need to edit \`make/local\`.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [September 12, 2026, 5:05pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/7 "2026-09-12T17:05:42Z")

</div>

This interacts with some of the changes on the v1.0 branch that I’ve been working on. I’ll check the issue to see if it adds anything beyond what’s already in the 1.0 plan. I agree that options explicitly specified via `stanc_options` should take precedence.

> [@WardBrian](#):
>
> putting anything in make/local you hope to override later is probably just a hazard

I do also agree with this in general.

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [September 12, 2026, 6:21pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/8 "2026-09-12T18:21:26Z")

</div>

> [@WardBrian](#):
>
> so putting anything in make/local you hope to override later is probably just a hazard

I’d like to have `-O1` as the default, and I have assumed `make/local` would be the right place. But then rarely I want to run experiments with `-O0` or `-Oexperimental`, so what would be your recommendation for setting up defaults and being able to override them for specific cases?

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [September 12, 2026, 7:29pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/9 "2026-09-12T19:29:20Z")

</div>

My make/local has a few blocks in it, with most of them commented out at any time. When I want to run some experiments, I uncomment the relevant ones and comment the others.

If you ever use cmdstanr to manage the make local file I imagine this wouldn’t work, so I’m not sure how to advise… just know that we inherit some often unintuitive behavior from make when it comes to specifying the same variable multiple times

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [September 12, 2026, 9:53pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/10 "2026-09-12T21:53:56Z")

</div>

> [@WardBrian](#):
>
> If you ever use cmdstanr to manage the make local file I imagine this wouldn’t work,

Can you say more about why you think this wouldn’t work with cmdstanr? You can’t tell cmdstanr to comment out lines for you (at least not currently), is that what you mean? Or am I overlooking something else?

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [September 12, 2026, 9:55pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/11 "2026-09-12T21:55:05Z")

</div>

I assumed that the write\_make\_local function removed what was there previously, does it not? Either way would require some manual intervention

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [September 12, 2026, 10:21pm UTC](https://discourse.mc-stan.org/t/cmdstan-stan-2-40-release-candidates/41585/12 "2026-09-12T22:21:32Z")

</div>

There’s an argument that toggles whether we overwrite or append to the end of the file. But yeah to comment and uncomment sections would require manual intervention.
