Exposing higher-order function

@seantalts: for the new Newton solver, should I expose it using the new compiler (and if so, where’s the place to learn how to do this?) I’d love not to edit 30 grammar files for this PR.

Yep, check out this YouTube video and associated PR:
https://youtu.be/mvLa1LIQvBA

This is great stuff!

At the risk of asking a question that’s been asked many times, what’s the timeline for having the new compiler in a released version of Stan? My hope is to have the Newton solver in the next Stan release.

There is a cmdstan PR open that will replace the existing compiler with stanc3. There is only one issue that needs to be resolved to get the green lights on tests. I think the plan is to get it in for 2.21.

1 Like

ok. So 2.21 is the January release. Fine by me.

No no, 2.21 is the 18th October release.

Even better!

Could someone give me permission to edit the stanc3 repo, specifically, create a new branch? Thx.

Other question: it looks like the unit tests for the parser still live inside the stan repo. This means I need to write the code edits and tests in two different repos. This strikes as a pretty poor development process. Not to mention I don’t expect the tests written in stan would pass the integration tests. Am I missing something here?

EDIT: all the relevant unit tests are in the repo, I didn’t look carefully enough.

You should have permission now.

I just added the stan-dev group maintainers to the stanc3 repo list of teams. I believe that was the intention given the team maintainters is tagged “People that can approve pull requests across the org”.

1 Like

Ok, working through the README on Stanc3.

I ran scripts/setup_dev_env.sh, and then eval $(opam config env). After doing this, dune becomes an option on terminal. Cool.

I run make, and get the following message:

menhir src/frontend/parsing_errors.ml
Read 455 sample input sentences and 455 error messages.

Couldn’t find the file. Run make again, this time no complain. Weird.

Now I run dune runtest test/integration/good/function-signatures/math/functions/integrate_1d.stan and get the following error message:

Error: Don't know about directory
test/integration/good/function-signatures/math/functions/integrate_1d.stan
specified on the command line!

The file definitely exists. Any idea what might be happening?

Disclaimer: I am by no means an expert on development in Ocaml or Stanc3.

This is fine, at least as far as i know.

Just run dune runtest test/integration/good/function-signatures/math/functions/.

You could add a command to run the test just for integrate_1d.stan but the tests for the entire folder run fast, so I would not bother with that.

1 Like

I think we want to move to a move granular permissions set; I’ve been doing that when I add folks. Like you basically don’t get added to the contributors list for a director or repo until you submit a “non-trivial” PR to it and it gets approved. I encourage everyone to use GitHub forks and pull requests from those in general, not just for your first PR because that lets you create branches willy-nilly without impacting others and is closer to how git was intended to be used.

This is right - dune by default just has test actions for directories unless you create custom aliases. It’s documentation is pretty comprehensive and here: https://dune.readthedocs.io/en/latest/ though it can be a bit hard to find the exact thing you’re looking for.

Finally getting back to this. Really amazed at how straightforward it is to add a higher-order function.

I exposed the prototype laplace_marginal_bernoulli(), ran the test, everything looks good. Now… how do I use the new compiler? When I download cmdStan dev branch, there is no sign of stanc3 in there. Not sure how to do this based on the stanc3 ReadMe.

1 Like

Hmm, I should add a section on this to the stanc3 or CmdStan README. If you set the STANC3 environment variable to the path to your stanc3 git repo, CmdStan will automatically recompile stanc3 and use that instead of the downloaded version. I keep most of my source in scm (for some reason) so for me,

cd ~/scm/cmdstan
STANC3=~/scm/stanc3 make examples/bernoulli/bernoulli
1 Like

I get the following error message

make: *** No rule to make target `examples/bernoulli/bernoulli'.  Stop.

Do I need to build stanc3 before being able to use it? I already ran the tests on that repo.

No. That’s a weird error - there should be a rule for Bernoulli in CmdStan with or without stanc3, haha. Do you have local changes to CmdStan?

Nope, just downloaded it from GitHub. I think need to run make build or make stan-update first.

Yup, that does the trick. Compiler works. Thank you for the swift response.

Another question: when exposing a higher-order function with optional arguments, how do I control where the msgs argument appears in the C++ translation (the std::ostream* msgs object)?

By default, it’s added as the last argument, though obviously for algebra_solver, integrate_ode_*, etc, it will be placed before the optional arguments. Are there files, other than Stan_math_signature.ml that control this? Similarly, if I have a higher-order rng function, how do I control where the rng argument appears? Ideally, I’d want the transpiler to produce

(..., rng, msgs, rel_tol, max_num_steps)