Running single model integration test


#1

These are instructions from @syclik on how to test a single model (.stan file) for compilability with a main() within stan-dev/stan.


Let’s say you wanted to test this Stan file: src/test/test-models/good/map_rect.stan

If you type:

> make src/test/test-models/good/map_rect.hpp-test

then it’ll do a number of things (in this order):

  1. build test/test-models/stanc — it’s a stripped down version of the compiler

  2. generate the C++: it goes from map_rect.stan to map_rect.hpp

  3. the *-test target attempts to compile it by including it into a file with a main(). That file with the main() is generated like this:

test/test-model-main.cpp:
	@mkdir -p test
	@touch $@
	@echo "int main() {" >> $@
	@echo "  stan::io::var_context *data = NULL;" >> $@
	@echo "  stan_model model(*data);" >> $@
	@echo >> $@
	@echo "  std::vector<stan::math::var> params;" >> $@
	@echo "  std::vector<double> x_r;" >> $@
	@echo "  std::vector<int> x_i;" >> $@
	@echo >> $@
	@echo "  model.log_prob<false, false>(params, x_i);" >> $@
	@echo "  model.log_prob<false, true>(params, x_i);" >> $@
	@echo "  model.log_prob<true, false>(params, x_i);" >> $@
	@echo "  model.log_prob<true, true>(params, x_i);" >> $@
	@echo "  model.log_prob<false, false>(x_r, x_i);" >> $@
	@echo "  model.log_prob<false, true>(x_r, x_i);" >> $@
	@echo "  model.log_prob<true, false>(x_r, x_i);" >> $@
	@echo "  model.log_prob<true, true>(x_r, x_i);" >> $@
	@echo >> $@
	@echo "  return 0;" >> $@
	@echo "}" >> $@
	@echo >> $@

Thanks, @syclik.


#2

No prob. Sorry it was so hard to find out how to do that. I’m sure it was on the dev list years ago, but that’s not a reasonable request (asking devs to comb through discussions). Ideally, where should this doc live? Wiki? Or in the make help target?


#3

I looked in the make help target. Given that @seantalts is planning on replacing make with CMake, I didn’t want to suggest more issues having to do with make.


#4

Sounds like we should put it there, then.


#5

Another project I’m working on has been using a documentation folder within the github repo for developer documentation. If you use Markdown it’s pretty readable on the command line and great on github and it keeps code + doc in one place. I think it might work well for Stan too. I’m not sure why we struggle with wiki’s and discussions for this stuff.


#6

Can you point me to that project? I’ve been looking for good examples, but haven’t found any that stand out.


#7

Sorry, it’s a private repo :/