Interface with C++ program


I’m trying to use Stan as a library in my C++ program for its HMC sampler functionality. I haven’t been able to find any C++ documentation, so my current approach is to reverse engineer the API by reading the unit tests and autogenerated code from stanc compiler.

Is there another approach or some doc resources I’ve missed? I thought this would be a common requirement from users, but have not found much discussion on the topic.

I specifically require a C++ interface and can’t use the OCaml compiler as an intermediary.

Appreciate any help.

In the stan-dev/stan repo you’ll find src/services where there are function calls set up to various versions of the HMC algorithm. They’re used in stan-dev/cmdstan so you can look there for what it takes to set up the parameters to call the services layer. The construction of the arguments is not all that intuitive (to me anyway) to use externally but overall not bad at all!

Edit: it has not bee a common requirement, many users just use an interface from R/Python and spend all their time writing models. I’d still like for Stan to have a friendlier layer for developing interfaces but I sadly don’t have the free dev time to commit to making that happen -_(:/)_-

1 Like

In addition to @sakrejda’s great answer, there are some unofficial resources which you might find useful, such as this good series of blog posts by @jtimonen from last year: