Exposing quadratic optimizer


I’m trying to expose a higher-order function (the quadratic optimizer with linear constraints, see https://github.com/stan-dev/stan/issues/2556). I followed closely what was done for algebra_solver and then ran an already existing unit test, using:

./runTests.py src/test/unit/lang/parser/matrix_functions_test.cpp

The goal was to see if the code would compile. It doesn’t. The error message is in the attached file was return. error_message.txt (103.5 KB)

Ok. Both errors point to the same line of code, which I wrote: term_grammar_def.hpp:287:9: As far as I can tell, this line is fine and the error lies somewhere else. I’m not quiet sure where and how to look. After going through the files I made a few corrections, but none that fixed the above error. Note there is a total of 21 edited files.

Does anyone more familiar with the language parser have an idea about what may be causing the error? Thank you!


Sorry I missed this, @charlesm93. If you haven’t sorted it out yet, could you push a branch and email me? I can check it out.


Hey Bob,
branch is pushed and linked in my original post. I haven’t worked it out yet. I might give it a stab on the airplane.


You linked the issue. The branch is feature/issue-2556-quadratic_optimizer.

I’d recommend simplifying things. Remove the semantic actions to make sure the FUSION declarations and grammar rule types are all correct. Then compile the function and make sure that works. Then try to tie it into the grammar. It’s painful, but it’s the only way we were ever able to debug these Boost Spirit Qi grammars (in @syclik’s words, you want to take “baby steps”).

So I checked out your branch and removed the quadratic optimizer semantic action declaration, definition, and call from the grammar and everything compiles other than generate_expression because the case isn’t defined for the quadratic optimzer. Fix that (with a stub), then start with a stub for the semantic action to get it to compile. Then start filling it in piece by piece.


Following Bob’s advice to break things down, I was able to fix a myriad of small errors which ultimately caused the bug. The changes were committed and the code now compiles.

It however seems I’m still missing a piece to expose the function. See the following unit test src/test/unit/lang/parser/quadratic_optimizer_test.cpp, according to which quadratic_optimizer is not a known function. Which file would the parser use to check if a higher-order function exists? Do I perhaps need to recompile certain files?

Tagging @mitzimorris.


checked out branch feature/issue-2556_etc
but looks like you haven’t added (or committed or pushed) file



@charlesm93 - there were a few remaining small errors -

  1. inconsistant name for semantic actions function validate_quadratic_optimizer_control_f

  2. test-model was missing arg #8

also tweaked the grammar rule so that it will backtrack if it hits functions named something like quadratic_optimizer_with_fries( etc.

committed and pushed my changes - hope this helps.


here is what I did to uncover these problems:

  1. started looking at the unit test - cross-referenced the line in the test-model file with the quadratic optimizer code and noticed that there was a missing argument.

  2. uncommented the grammar rule in src/stan/lang/grammars/term_grammar_def.hpp

at this point, the code wasn’t compiling. captured the c++ boost/spirit/qi compiler error novel to an output file. in the error novel, looked for the very first line of spew that referenced files in src/stan/lang/grammars which showed that there was a problem with the term grammar rule. careful cross-referencing of the semantic action and its corresponding declarations and definitions in the semantic_actions.hpp, semantic_actions_def.cpp files showed that the problem was with the function name.



added tests for all 11 or so ways that one could mess up on the arguments to the quadratic_optimizer function call.

@Bob_Carpenter are there other tests that should be done w/r/t adding this to the language?


Not that I’m aware of.


@mitzimorris I finally got a chance to check out your commits (have been a little mia this month). Thank you so much for resolving the issue.