Cmdstan 2.24.1 is released

We are very happy to announce that the next release of Cmdstan (2.24.1) is now available on Github.

You can find it here: https://github.com/stan-dev/cmdstan/releases/tag/v2.24.1

There were ~150 pull requests merged for this release, code was contributed by 17 developers:

@Adam_Haber , @andrjohns, @bbbales2, @Bob_Carpenter, @charlesm93, Christopher22 , @simon, HaoZeke, @IvanYashchuk , @mitzimorris , @nhuurre, @peterwicksstringfield, @rybern, @serban-nicusor, @SteveBronder, @tadej and @rok_cesnovar.

Also huge thanks to everyone that contributed with code reviews!

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 now have an online Cmdstan guide available at https://mc-stan.org/docs/2_24/cmdstan-guide/

With cmdstanpy you can update to the new release using:

import cmdstanpy
cmdstanpy.install_cmdstan()

With cmdstanr you can update to the new release using:

library(cmdstanr)
install_cmdstan(release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.24.1/cmdstan-2.24.1.tar.gz")

New features

This release comes with a lot of new features and bugfixes. The detailed release notes for Cmdstan and all the submodules can be found here. If you have any questions or cannot find the documentation, do not hesitate to ask. Below are some of the highlights.

A new ODE interface

The new ODE interface is intended to make it easier to specify the ODE RHS by avoiding packing and unpacking schemes required with the old interface. It is important to switch to the new interfaces because the old interfaces are significantly slower than they were previously (we have seen up to 30%)

The new functions are:

vector[] ode_bdf(F f, vector y0, real t0, real[] times, ...)
vector[] ode_adams(F f, vector y0, real t0, real[] times, ...)
vector[] ode_rk45(F f, vector y0, real t0, real[] times, ...)
vector[] ode_bdf_tol(F f, vector y0, real t0, real[] times, real rel_tol, real abs_tol, int max_num_steps, ...)
vector[] ode_adams_tol(F f, vector y0, real t0, real[] times, real rel_tol, real abs_tol, int max_num_steps, ...)
vector[] ode_rk45_tol(F f, vector y0, real t0, real[] times, real rel_tol, real abs_tol, int max_num_steps, ...)

Where ... can be argument(s) of any type.

For examples converting ODEs written with the old interface to the new interface, look at the case study Upgrading to the new ODE interface.

For detailed information, check out the Ordinary Differential Equation (ODE) Solvers section in the Function Reference or the Ordinary Differential Equations section in the User’s Guide.

Functions for Hidden Markov Models with a discrete latent variable

New signatures:

matrix hmm_hidden_state_prob(matrix, matrix, vector)
int[] hmm_latent_rng(matrix, matrix, vector)
real hmm_marginal(matrix, matrix, vector)

For detailed information, check out the Hidden Markov Models section in the Function Reference.

Elementwise pow operator and matrix power function

The .^ operator now supports elementwise pow. The following examples are now all supported:

vector .^ vector
row_vector .^ row_vector
matrix .^ matrix
int .^ matrix
matrix .^ int
matrix .^ real
vector .^ real
vector[] .^ vector[]
int .^ matrix[]
row_vector[] .^ real
row_vector .^ real
...

A new matrix matrix_power is also available with the signature:

matrix matrix_power(matrix, int)

For detailed information, check out the Matrix Power section in the Functions Reference.

Newton solver

The Newton solver is available via

vector algebra_solver_newton((vector, vector, data real[], data int[]) => vector,
                               vector, vector, real[], int[])
vector algebra_solver_newton((vector, vector, data real[], data int[]) => vector,
                               vector, vector, real[], int[], real, real,
                               real)

For detailed information, check out the Algebraic Equation Solver section in the Functions Reference.

Support for the multinomial logit distribution

Supported signatures:

real multinomial_logit_log(int[], vector)
real multinomial_logit_lpmf(int[], vector)
int[] multinomial_logit_rng(vector, int)

For detailed information, check out the Multivariate Discrete Distributions section in the Functions Reference.

Reverse function

Supported signatures:

T reverse(T)

T is vector, row_vector or an array of any type

For detailed information, check out the Reverse Functions section in the Functions Reference.

Integer division operator

A new integer division operator was added: %/% . Dividing integer numbers with the / operator will warn.

Pedantic mode

You can now run a pedantic check on your model that warns you about potential issues in your Stan program.

You can enable it in Cmdstan by adding a --warn-pedantic flag to STANCFLAGS.

You can enable it in cmdstanr with the stanc_options argument:

model = cmdstan_model("test.stan", stanc_options = list("warn-pedantic" = TRUE))

For detailed information, check out the Pedantic mode section in the Reference Manual.

Non-scalar values in lower, upper, offset and multiplier

Non-scalar values are now allowed in lower, upper, offset and multiplier transforms if the value has the same type and size as the declared variable.

Example:

real L[K];
real U[K];
vector<lower = L, upper = U>[K] alpha;

Faster compile times and easier handling of threading

If you are using the g++ C++ compiler, the Stan models should now compile ~50% faster. If you are using the clang C++ compiler, the models should compile ~20% faster than with Cmdstan 2.23.

On Linux and macOS this speedup is available out of the box. On Windows, if you are using the toolchain available with RTools 4.0, you have to add

PRECOMPILED_HEADERS=true

to the make/local file. This speedup is unfortunately not available with RTools 3.5 on Windows.

A new and improved stansummary

  • added option of returning custom quantiles
  • separate summaries for sampler and model params
  • a lot of minor improvements for stability and maintainability
12 Likes

Minor thing: In the HMM doc page, clicking 26.1 Stan functions does not lead to the HMM stan functions, but instead to https://mc-stan.org/docs/2_24/functions-reference/bernoulli-distribution.html#stan-functions

1 Like

Thanks!

Would you mind opening an issue in https://github.com/stan-dev/docs so this does not get forgotten?

It seems that moving to the next page (clicking the right arrow) brings us to the right page, but the menu does not.

2 Likes

docs should work now - thanks for checking and reporting!

3 Likes

Thank you all for all your hard work!

2 Likes

FYI, cmdstanr has not picked up the latest release:

> install_cmdstan()
* Latest CmdStan release is v2.24.0
1 Like

Thanks.

Github is still picking up 2.24.0 as “Latest release” https://github.com/stan-dev/cmdstan/releases

@serban-nicusor can we do anything about that?

For now, I fixed the instruction in the top post to :

install_cmdstan(release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.24.1/cmdstan-2.24.1.tar.gz")
3 Likes

Hey @rok_cesnovar github should have taken the latest release based on the timestamp. To fix this I need to re-create the release if that’s alright.

Fine by me. There is probably no other way so lets go with that.

Is there a way to use the exact same tag (maybe delete the existing one)? If the URL https://github.com/stan-dev/cmdstan/releases/tag/v2.24.1 could point to this newly created release that would be great. That way we don’t need to fix the URLs in the blog post.

1 Like

@rok_cesnovar v2.24.1 shows up as latest , nothing else changed so everything should be fine now.

4 Likes

Thanks Nic for the very quick response. Enjoy the rest of the weekend!

1 Like

request for clarification from a semanticist:
were these features were introduced in 2.24.0? and the 2.24.1 release is making good on the promise of the 2.24 feature set, having resolved a few kinks present in 2.24.0?

Indeed. 2.24.1 was a hotfix release fixing some code generation bugs that fell through. If it had new features, it would have to be 2.25.0

I installed cmdstanr and downloaded lastest stan version, v2.24.0 (28 July 2020). Then, I tested the examples from lastest case study. Everything is working!

1 Like

when did you do this? according to previous messages, latest release should be 2.24.1.

FWIW, I just ran cmdstanpy.install_cmdstan() and it did indeed install 2.24.1.

You’re right! I did this yesterday. I have stan 2.24.1. I’m sure 2.24.1 .tar was here, but I don’t why it doesn’t appear anymore.

the above link is to the Stan module - the latest CmdStan release is here: https://github.com/stan-dev/cmdstan/releases

the CmdStan release tarball includes a tagged version of the Stanc3 binaries, and the latest released version of the Stan and math modules. since the fixes here were all on the Stanc3 transpiler, the versions of the Stan and math lib modules are still at 2.24.0. hope this makes sense.

1 Like