traitecoevo / mortality_bci

Tropical tree mortality model using Barro Colorado Island as a case study
Other
7 stars 3 forks source link

Capture and / or hide stan messages #18

Closed dfalster closed 9 years ago

dfalster commented 9 years ago

When calling stan there is a lot of noise, first from the compiler then "Informational Messages" from stan (issues with sampling, we expect some in early stage but if these persist can suggest poor model). Can we capture these somehow?

@richfitz ideas?

Example output

...
file14982c92aca6.cpp:41:23: warning: unused parameter 'pstream__' [-Wunused-parameter]
        std::ostream* pstream__ = 0)
                      ^
file14982c92aca6.cpp:171:40: warning: unused parameter 'pstream__' [-Wunused-parameter]
                         std::ostream* pstream__) const {
                                       ^
file14982c92aca6.cpp:311:32: warning: unused parameter 'pstream__' [-Wunused-parameter]
                 std::ostream* pstream__ = 0) const {
                               ^
file14982c92aca6.cpp:610:27: warning: unused parameter 'base_rng__' [-Wunused-parameter]
    void write_array(RNG& base_rng__,
                          ^
file14982c92aca6.cpp:616:36: warning: unused parameter 'pstream__' [-Wunused-parameter]
                     std::ostream* pstream__ = 0) const {
                                   ^
file14982c92aca6.cpp:822:25: warning: unused parameter 'base_rng__' [-Wunused-parameter]
    void write_csv(RNG& base_rng__,
                        ^
file14982c92aca6.cpp:826:34: warning: unused parameter 'pstream__' [-Wunused-parameter]
                   std::ostream* pstream__ = 0) const {
                                 ^
In file included from file14982c92aca6.cpp:1133:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/stan_fit.hpp:39:
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/io/rlist_ref_var_context_factory.hpp:16:58: warning: unused parameter 'source' [-Wunused-parameter]
      rlist_ref_var_context operator()(const std::string source) {
                                                         ^
In file included from file14982c92aca6.cpp:1133:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/stan_fit.hpp:41:
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/stan_args.hpp:493:5: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
    const inline sampling_metric_t get_ctrl_sampling_metric() const {
    ^~~~~~
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/stan_args.hpp:496:5: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
    const inline sampling_algo_t get_ctrl_sampling_algorithm() const {
    ^~~~~~
In file included from file14982c92aca6.cpp:1133:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/stan_fit.hpp:57:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/rstan_recorder.hpp:6:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/common/recorder/filtered_values.hpp:4:
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/common/recorder/values.hpp:38:57: warning: unused parameter 'x' [-Wunused-parameter]
        void operator()(const std::vector<std::string>& x) { }
                                                        ^
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/common/recorder/values.hpp:51:43: warning: unused parameter 'x' [-Wunused-parameter]
        void operator()(const std::string x) { }
                                          ^
In file included from file14982c92aca6.cpp:1133:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/rstaninc.hpp:3:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/stan_fit.hpp:57:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include/rstan/rstan_recorder.hpp:7:
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/common/recorder/sum_values.hpp:72:9: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
        const size_t called() const {
        ^~~~~~
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/common/recorder/sum_values.hpp:76:9: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
        const size_t recorded() const {
        ^~~~~~
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/common/recorder/sum_values.hpp:27:57: warning: unused parameter 'x' [-Wunused-parameter]
        void operator()(const std::vector<std::string>& x) { 
                                                        ^
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/common/recorder/sum_values.hpp:53:43: warning: unused parameter 'x' [-Wunused-parameter]
        void operator()(const std::string x) { }
                                          ^
In file included from file14982c92aca6.cpp:8:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:17:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
    static void set_zero_all_adjoints() {
                ^
In file included from file14982c92aca6.cpp:8:
In file included from /Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:21:
/Users/dfalster/Dropbox/Library/R/Versions/3.1/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
      size_t product(std::vector<size_t> dims) {
             ^
127 warnings generated.

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Invalid value of p: validate transformed params(N4stan5agrad3varE): p[k0__] is nan:0, but must be greater than or equal to 0
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Invalid value of p: validate transformed params(N4stan5agrad3varE): p[k0__] is nan:0, but must be greater than or equal to 0
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
richfitz commented 9 years ago

First, check the stan docs as this is nontrivial; there may be some controlling options.

The compiler bits are hard because they're done by the system() calls. I don't know a good way of intercepting these unless you have access to the actual call.

capture.output captures output from cat

suppressMessages suppresses output from message, but you can reimplement to capture them.

See testthat:::evaluate_promise for the most complete capturing code I've seen.