Cmdstan 2.24 release candidate now available

I am very happy to announce that a release candidate for the next release of Cmdstan is now available on Github.

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

There was a total of 147 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 myself.

Also huge thanks to everyone that contributed with code reviews to what will certainly be a great release.

We just need a bit of your help. Please try the release candidate out, play with new features or just compile and run your exisiting models. And let us know what you think. Your time and help is very much appreciated by everyone at the Stan development team.

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/

If you are using cmdstanpy, make sure you point to the folder where you extracted the tar.gz file with

set_cmdstan_path(os.path.join('path','to','cmdstan'))

With cmdstanr you can install the release candidate using

install_cmdstan(release_url = "https://github.com/stan-dev/cmdstan/releases/download/v2.24.0-rc1/cmdstan-2.24.0-rc1.tar.gz", cores = 4)

And then select the RC with

set_cmdstan_path(file.path(Sys.getenv("HOME"), ".cmdstanr", "cmdstan-2.24.0-rc1"))

New features

This release comes with a lot of new functions. Some of them already have online documentation which is linked below. Other will get documented in time for the release.
If you have any questions, do not hesitate to ask.

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. ODE function docs is available here, and ther user guide here.

There will also be a case study available shortly that will be linked here once its online.

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)

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)

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)

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)

Reverse function

Supported signatures:
T reverse(T) , where T is vector, row_vector or an array of any type

Lambert functions

Supported signatures:
T lambert_w0(T), for any T
T lambert_w1(T), for any T

Construction utility functions

matrix identity_matrix(int)
real[] linspaced_array(int, real, real); row_vector linspaced_row_vector(int, real, real); vector linspaced_vector(int, real, real)
int[] one_hot_int_array(int, int); real[] one_hot_array(int, int); row_vector one_hot_row_vector(int, int); vector one_hot_vector(int, int)
int[] ones_int_array(int); real[] ones_array(int); row_vector ones_row_vector(int); vector ones_vector(int)
vector uniform_simplex(int)
int[] zeros_int_array(int); real[] zeros_array(int); row_vector zeros_row_vector(int); vector zeros_vector(int)

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. For more details see here. A more readable form of documentation will be available at release time.
You can enable it by adding a --warn-pedantic flag to STANCFLAGS.

Experimental optimization mode

There is also an experimental mode that will try to optimize your Stan model if possible. This can be enabled by adding the --O flag to STANCFLAGS. A provisional documentation for the feature is currently available at
https://github.com/rybern/optimization-docs/blob/master/optimization-docs.md The --O flag currently runs all listed optimizations.

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

Given that there were 147 pull requests merged since the last release, I may have missed some of the new features. If you want to highlight any of them, feel free to post here.

13 Likes

Cool!

ODE function docs here, and user guide here for now

3 Likes

Great work!

I was looking for documentation on the hmm stuff but wasn’t able to find it in the 2.24 doc references. Are there any examples of usage?

1 Like

@charlesm93 would know more on the status of the docs and example models.

This is a huge release!

Just as an additional info for the new ODE interface thing… users really want to switch to use the new, because continuing to use the old integrate_ode* functions will severely slow down your model (we have seen up to 30%)… so enjoy right away the new variadic ODE interface and switch over.

(We need to highlight this slow-down a bit more in the final notes… or did I miss that?)

3 Likes

@spinkney Documentation is a work in progress. This process was slowed down a little bit by us working out how to classify the hmm functions. It looks like we’ll need to add a new section to the manual. Hopefully, documentation will be out this week.

3 Likes

Yes, that needs to be highlighted.

CmdStan release notes so far:

CmdStan 2.24.0

Features:

  • CmdStan User’s Guide now online - updated and revised
  • Utility command stansummary allows user-specified quantile reporting,
    improved output format, better command-line options handling
  • Many makefile improvements:
    • precompiled headers
    • detect compiler option dependencies
    • improved messaging

Bugfixes

  • Generated quantities for models with non-scalar parameters

comments and edits here: https://github.com/stan-dev/cmdstan/issues/911

My bad. I’ll add something to the Math notes.

@rok_cesnovar announcement text can be something like “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%)”

Updated top-level comment and the draft I have for the actual release. Thanks.

So much good stuff! Thanks to everyone who contributed! :)

2 Likes

Thanks everyone! For anyone who wants to try out the release candidate with CmdStanR you can install it easily using

rc_2_24 <- "https://github.com/stan-dev/cmdstan/releases/download/v2.24.0-rc1/cmdstan-2.24.0-rc1.tar.gz"
cmdstanr::install_cmdstan(release_url = rc_2_24, cores = 4)

You may need to manually set the path the next time you use CmdStanR using

# replace with your path
set_cmdstan_path("/Users/jgabry/.cmdstanr/cmdstan-2.24.0-rc1/")

because I think we have it default to the latest installed release (not release candidate).

4 Likes

I’m playing around with this in cmdstanr and I needed to add the -Wno-ignored-attributes flag or my Rstudio gets crazy slow and bogged down.

Can we make this flag default until that warning goes away? It’s an Eigen/compiler interaction right?

Something like:

model <- cmdstan_model("test.stan",
                       cpp_options = list(CPPFLAGS = "-Wno-ignored-attributes"))

Without this even something simple like:

parameters {
  real a;
}

model {
  a ~ normal(0, 1);
}

eats up my Rstudio session.

2 Likes

@bbbales2 have you tried this from the command line just using the CmdStan makefile?
I think the makefile is sometimes recompiling more things than it should, but I haven’t yet tried to systematically make this happen - https://github.com/stan-dev/cmdstan/issues/910

I ran across this just compiling a very few different models to get output to test stansummary with.

Very awesome! Should we also tweet this out via the @mcmc_stan account for more visiblity?

1 Like

Yes, we should tweet this… we need testing NOW.

Refreshed 200+ core HTCondor pool in need of some jobs for stress testing. Would happily contribute some resources to testing out compile and run times.

is your friend. Maybe just use the stat_comp_benchmark stuff.

Though… these models are really tested well already. The example model git would probably be better to go through for larger test coverage.

I see the 2.24-rc tag in the Cmdstan repository but not in stan-dev/stan.

Does this mean there’s no rc for stan or math, just Cmdstan?

Indeed, we saw no use-case of making a Stan RC. Same for Math. If you have a need for a Stan RC we could build it next time.