CmdStan & Stan 2.35 release candidate

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

This release cycle brings several improvements to the headline features of the last release - tuple types and the Pathfinder algorithm - new distributions, and other improvements.

You can find the release candidate for cmdstan here. 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 more efficient while maintaining a high level of reliability.

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

Below are some of the highlights of the new release.

Bail out with fatal_error()

There is a new statement type: fatal_error. This looks a lot like print or reject, but will immediately terminate the algorithm rather than being used to signal a divergence.

A new RNG used internally

Stan now uses the boost::mixmax pRNG for generating random numbers internally. The primary consequence of this for most users is that seeds from previous versions will not yield the same numerical results on this version.
As per usual, exact reproducibility requires a fixed version of Stan, but this change is larger than normal, hence it being noted here.

Improved CmdStan outputs

Several new output options are available for CmdStan to produce JSON files for easier processing.

  • The diagnostic_file argument for the Laplace approximation sampler will now give a JSON output which contains the Hessian of the mode
  • The laplace method now supports the calculate_lp argument, similar to Pathfinder in the previous release.
  • Pathfinder will no longer return more draws than requested in certain circumstances.

New distributions

This release saw the extension of the wiener_lpdf distribution to a version with 7 parameters by @Franzi. They have a write-up here. Existing signatures are unchanged.

Deprecations

The keyword jacobian is being reserved for use within the Stan language in a future version.

Bug fixes!

This release also contains a large number of bug fixes across all levels of the Stan ecosystem. Some details are available in the preliminary release notes

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

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

cmdstanpy.install_cmdstan(version='2.35.0-rc2')

With CmdStanR you can install the release candidate using

cmdstanr::install_cmdstan(version = "2.35.0-rc2", cores = 4)
9 Likes

Dear WardBrian,I installed a new version of cmdstanr, when running the bernoulli.stan file, I got such an error, I tried many times and couldn’t find the reason, if you have time can you help me take a look?Thank you.

set_cmdstan_path(path = NULL)
CmdStan path set to: C:/Users/admin/Documents/.cmdstan/cmdstan-2.35.0-rc2

Create a CmdStanModel object from a Stan program,

here using the example model that comes with CmdStan

file ← file.path(cmdstan_path(), “examples/bernoulli/bernoulli.stan”)
mod ← cmdstan_model(file)
Model executable is up to date!
mod$print()
data {
int<lower=0> N;
array[N] int<lower=0, upper=1> y;
}
parameters {
real<lower=0, upper=1> theta;
}
model {
theta ~ beta(1, 1); // uniform prior on interval 0,1
y ~ bernoulli(theta);
}

Data as a named list (like RStan)

stan_data ← list(N = 10,y = c(0,1,0,0,0,0,0,0,0,1))
stan_data
$N
[1] 10

$y
[1] 0 1 0 0 0 0 0 0 0 1

Run MCMC using the ‘sample’ method

fit_mcmc ← mod$sample(

  • data = stan_data,
  • seed = 123,
  • chains = 4,
  • parallel_chains = 4,
  • refresh=500
  • )
    Running MCMC with 4 parallel chains…

Chain 1 Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 1 Iteration: 500 / 2000 [ 25%] (Warmup)
Chain 1 Iteration: 1000 / 2000 [ 50%] (Warmup)
Chain 1 Iteration: 1001 / 2000 [ 50%] (Sampling)
Chain 1 Iteration: 1500 / 2000 [ 75%] (Sampling)
Chain 1 Iteration: 2000 / 2000 [100%] (Sampling)
Chain 2 Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 2 Iteration: 500 / 2000 [ 25%] (Warmup)
Chain 2 Iteration: 1000 / 2000 [ 50%] (Warmup)
Chain 2 Iteration: 1001 / 2000 [ 50%] (Sampling)
Chain 2 Iteration: 1500 / 2000 [ 75%] (Sampling)
Chain 2 Iteration: 2000 / 2000 [100%] (Sampling)
Chain 3 Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 3 Iteration: 500 / 2000 [ 25%] (Warmup)
Chain 3 Iteration: 1000 / 2000 [ 50%] (Warmup)
Chain 3 Iteration: 1001 / 2000 [ 50%] (Sampling)
Chain 3 Iteration: 1500 / 2000 [ 75%] (Sampling)
Chain 3 Iteration: 2000 / 2000 [100%] (Sampling)
Chain 4 Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 4 Iteration: 500 / 2000 [ 25%] (Warmup)
Chain 4 Iteration: 1000 / 2000 [ 50%] (Warmup)
Chain 4 Iteration: 1001 / 2000 [ 50%] (Sampling)
Chain 4 Iteration: 1500 / 2000 [ 75%] (Sampling)
Chain 4 Iteration: 2000 / 2000 [100%] (Sampling)
Chain 1 finished in 0.0 seconds.
Chain 2 finished in 0.0 seconds.
Chain 3 finished in 0.0 seconds.
Chain 4 finished in 0.0 seconds.

All 4 chains finished successfully.
Mean chain execution time: 0.0 seconds.
Total execution time: 0.4 seconds.

Error in !is.null(csv_contents$metadata$save_warmup) && csv_contents$metadata$save_warmup:
The ‘y’ type in ‘x && y’ is invalid.

1 Like

Do you get the same error with the Github cmdstanr:

# install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")

Here’s my code, I hope you can help me take a look, it’s all downloaded.Thank you.

library(remotes)
install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
cmdstanr::install_cmdstan(version = "2.35.0-rc2", cores = 4)
## Not run: 
library(cmdstanr)
library(posterior)
library(bayesplot)
color_scheme_set("brightblue")
# Set path to CmdStan
# (Note: if you installed CmdStan via install_cmdstan() with default settings
# then setting the path is unnecessary but the default below should still work.
# Otherwise use the `path` argument to specify the location of your
# CmdStan installation.)
set_cmdstan_path(path = NULL)

# Create a CmdStanModel object from a Stan program,
# here using the example model that comes with CmdStan
file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.stan")
mod <- cmdstan_model(file)
mod$print()

# Data as a named list (like RStan)
stan_data <- list(N = 10,y = c(0,1,0,0,0,0,0,0,0,1))
stan_data
# Run MCMC using the 'sample' method
fit_mcmc <- mod$sample(
  data = stan_data,
  seed = 123,
  chains = 4,
  parallel_chains = 4,
  refresh=500
)

EDIT by Aki: added code block quotes

I have the same error and made an issue 2.35RC failing · Issue #1273 · stan-dev/cmdstan · GitHub, before coming here. I tested with the latest github CmdStanR. The issues comes only with the models compiled with 2.35RC

Thank you very much for your reply, and I’ll learn the other versions of cmdstanr.

After the error, I tried to read the csv with rstan:

rescue.read <- rstan::read_stan_csv('/tmp/RtmpNsTI80/Poisson-202405140850-1-4a2d19.csv','/tmp/RtmpNsTI80/Poisson-202405140850-2-4a2d19.csv')

I received this error:

Error in !col_major : invalid argument type
In addition: Warning message:
In parse_stancsv_comments(comments) : NAs introduced by coercion

The issue is only with 2.35 (changes to default output), I’ll be working through the issues today and will put out a new CmdStanR release tomorrow

1 Like

Ok, thank you very much for your reply, looking forward to the new version. I also have a question for you, about the use of wiener_full_lpdf(). I’m getting the following error:

file ← file.path(“H:/wiener_full_lpdf.stan”)
mod<-cmdstan_model(file)
Compiling Stan program…
Semantic error in ‘C:/Users/admin/AppData/Local/Temp/RtmpkvZyy9/model-5a8c1aa722d.stan’, line 9, column 17 to column 101:


 7:          if (resp[i] == 1) {
 8:            // upper threshold
 9:            ans += wiener_full_lpdf(rt_slice[i+1-start] | a, v_m[cnd[i]], zr_m, t0_m, v_s,  zr_s, t0_s);
                      ^
10:          } else {
11:            // lower threshold (mirror drift and starting point!)

A returning function was expected but an undeclared identifier ‘wiener_full_lpdf’ was supplied.
mingw32-make: *** [make/program:64: C:\Users\admin\AppData\Local\Temp\RtmpkvZyy9\model-5a8c1aa722d.hpp] Error 1
An error occured during compilation! See the message above for more information.
If you have time, would you like to help me take a look, thank you again.

The function as it was added to the language is just called wiener_lpdf – the _full portion was removed because we can tell which one is desired based only on the number of arguments provided

Dear WardBrian,thank you for your reply. Does that mean that the wiener_lpdf_full() function cannot be applied in cmdstanr?

It should be available! If you replace wiener_full with just wiener and pass it the same arguments you were trying, it will call the newly extended version

Ok,thank you.I will learn relevant knowledge and try to run the code to achieve my goal.

A new release of cmdstanr with compatibility for 2.35 (and this RC) is now available: CmdStanR v0.8.0 Released

4 Likes

Cmdstan 2.35 works! But rstan::read_stan_csv in 2.35 is broken.
Will adjust my workflow.

The official release of 2.35 will be delayed while we investigate some edge cases in the new random number generator. I don’t expect it to take too long, but we may want to do another set of RCs before the release proper