Running unit tests for stan_math: how to avoid recompilation

I’m looking at extending gaussian_dlm_obs to allow time-varying system matrices. I ran the stan_math unit tests initially using runTests.py. This takes very long, with most of the time spent compiling the tests. Then, after making some changes to gaussian_dlm_obs_lpdf.hpp, I ran runTests.py again. I was expecting that only a few things would be recompiled, those directly affected by the change to the header file, but instead it seems to be recompiling everything. Is this the expected behavior? Is there any way to get make-like behavior where only the things that need to be recompiled get recompiled?

For some definition of expected. Many of the tests first #include <stan/math.hpp>, which in turn includes almost every file under rev or prim, and so make thinks everything needs to be recompiled. It is this way because the order of the included headers matters in Stan Math and just putting #include <stan/math.hpp> on the top line was considered “easier” for developers to get things to compile correctly, even though it then becomes impractical for developers to run all the unit tests on their own machine.

For something like gaussian_dlm_obs_lpdf.hpp, which isn’t used by anything else, I would just call

./runTests.py test/unit/math/prim/mat/prob/gaussian_dlm_obs_log_test.cpp

and once that is working, push the branch so that all the tests get run on a server.

3 Likes

Yes, this is the current expected behavior. In order to ease the burden on developers, we’ve gone with a simpler include in the unit tests. As @bgoodri outlined, this pulls in almost all of the headers in one go, so there’s no way for make (through an invocation of the C++ compiler) to know that only a small portion of the tests have changed.

At some point, we can change how the tests are linked to make this convenient for running again. (It used to be that way a few versions ago.)

+1. That’s the fast way to get things unit tested these days.

Yes. To expand on what @bgoodri and @syclik said, we’re moving to including the top level stan/math.hpp in our tests rather than little bits and pieces because we were continually getting bit by things working with only a few includes, but not working with the whole library due to things like ambiguity.

1 Like