Release of CmdStan 2.27.0

We are very happy to announce that the 2.27.0 release of CmdStan is now available on Github! As usual, the release of CmdStan 2.27.0 is accompanied with the new releases of Stan Math, core Stan and Stanc3.

The release of Stan 2.27 is also accompanied by the release of pystan 3.1!

This new release brings new ODE solvers, new array and definition/declaration syntax, new functions, performance and usability improvements and as always, bug fixes.

Install instructions are provided at the end of the post.

Contributors

We would like to thank everyone that contributed to this release with their bug reports, feature or bug fix discussions, code or code reviews!

In total, we had code and docs contributions from 23 developers and users in this release cycle. Listing their Github usernames in alphabetical order:

adamhaber, andrjohns, bbbales2, chenel, dirmeier, gregorp90, hsbadr, hyunjimoon, jeffreypullin, jsocolar, mandel, martinmodrak, mitzimorris, mortonjt, nhuurre, rok-cesnovar, rybern, seantalts, serban-nicusor-toptal, SteveBronder, t4c1, wds15, yizhang-yiz.

We would also like to welcome the newest Stan developer that accepted the invitation to formally join our Stan development team: Hamada S. Badr (hsbadr).

Hamada has recently been helping us by adding support for newest versions of the TBB library and maintaining a development version of rstan that supports the latest Stan. We are excited to see what comes next.

Sponsors and donators

We would like to express a big THANK YOU to all of our sponsors and donators that have been supporting us during this last release cycle and in years past.

You can support Stan via NumFocus or the Github sponsorship program.

Release highlights

Adjoint ODE

We added a new adjoint ODE solver from CVODES. The adjoint ODE method has favorable performance scaling for large ODE problems with many more parameters than ODE states. As the adjoint ODE approach is numerically more involved, we are exposing the feature for more advanced users such that most tuning parameters of the solver are being exposed. We intend to provide a simplified adjoint ODE solver interface once the community has collected more experience with the solver. For more details see Stan’s User Guide section on the Adjoint ODE solver and the function reference.

Cash–Karp method for solving ODE

We also added another new solver that solves the ODE system using the Cash-Karp algorithm, a 4th/5th order explicit Runge-Kutta method. The Cash-Karp algorithm should improve numerical integration of ODEs with semi-stiffness and/or rapid oscillations. See the ODE solver functions reference for details.

New array syntax

We silently added support for a new array syntax in the previous release. With this release this new syntax is becoming more prominent and will be used in error messages, documentation and example models. Prevously an array was defined with the array dimensions following the variable identifier:

real a[5];
matrix[3,3] b[5];
vector[3] c[5];

The new syntax uses the array keyword, similar to matrices and vectors. The following are equivalent arrays declared with the new syntax:

array[5] real a;
array[5] matrix[3,3] b;
array[5] vector[3] c;

The old syntax will be supported for the forseable future but we strongly encourage getting used to the new syntax.

New functions and signatures

We added a new function to compute the quantiles in the transformed data or generated quanties. The following signatures are supported:

quantile(data vector, data real) => real
quantile(data row_vector, data real) => real
quantile(data array[] real, data real) => real
quantile(data vector, data array[] real) => array[] real
quantile(data row_vector, data array[] real) => array[] real
quantile(data array[] real, data array[] real) => array[] real

See the function reference for more.

In addition we have extended the fma() function which now supports more vectorized signatures:

fma(real, real, vector) => vector
fma(real, vector, real) => vector
fma(real, vector, vector) => vector
fma(vector, real, real) => vector
fma(vector, real, vector) => vector
fma(vector, vector, real) => vector
fma(vector, vector, vector) => vector

and for row_vector and matrix arguments instead of vector.

Multiple definitions in one declaration statements

We have added support to allow declaring and defining more than one variable with the same declaration statement, given that they have the same type.
So the following will now be valid in Stan 2.27+:

data {
  real x, y, z;
  array[5] int i, j;
}
transformed data {
  real a = 5, b = 6;
  real c = 5, d, e = 7;
}

Performance optimizations

The following functions should have improved performance:

  • diag_pre_multiply
  • diag_post_multiply
  • multi_normal_cholesky (when covariance is data)
  • csr_matrix_times_vector (for cases when the matrix is data and the vector is a parameter)

We also improved handling data and transformed data by avoiding an unnecessary copy when using reverse mode.

Improved range checks

We have improved the range checks when accesing elements of a vector/row_vector/matrix or array.
These will now return a more informative error in case of a users bug with indexing like setting an index out of a vector’s range.

These checks can in some cases add a noticeable performance regression of around 10%. Users can use the STAN_NO_RANGE_CHECKS make flag to avoid the range checks in favor of maximum performance.

We advise only turning the checks off once you are sure in the correctness of indexing in your model. See the CmdStan guide for more details.

Miscellaneous improvements

  • More robust detection of improper posteriors.
  • Standalone generated quantities will also run on warmup draws if supplied.
  • The fixed_param method is run automatically if the model has no parameters.
  • The _cdf functions now also use the vertical bar (|) form, matching the lcdf/lcdf/lpdf/lpmf functions.
  • Fixed an issue with a memory leak with the OpenCL backend.
  • The Stan-to-C++ compiler can now output lists of data, parameter and GQ variables in JSON form.
  • Avoiding copying data/transformed data in the stack allocator when doing reverse mode.

Updated downstream dependencies

The TBB library has been upgraded to the 2020.3 version and the Sundials library has been updated to 5.7.0.

How to install the new release?

Download the tar.gz file from the CmdStan release page, extract it and use it the way you use any Cmdstan release. We also have an online Cmdstan guide available for new users.

If you are using cmdstanpy install the new release using

import cmdstanpy
cmdstanpy.install_cmdstan()

With CmdStanR you can install the new release using

library(cmdstanr)
install_cmdstan(cores = 4)

The next release is planned for end of September.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s