canmod / macpan2

Rebuilding https://github.com/mac-theobio/McMasterPandemic/
https://canmod.github.io/macpan2/
GNU General Public License v3.0
2 stars 0 forks source link

warnings from the engine -- new feature #189

Open stevencarlislewalker opened 6 months ago

stevencarlislewalker commented 6 months ago

A discussion at a macpan tech meeting about when to round variables that should be integers (e.g. state variables in some models with process error) led to the idea that we should have a warning system for the engine. The standard Rf_warning mechanism is annoying in TMB because it will get called at each of the (5?) steps of the MakeADFun machinery and for each time step. Here is a design that addresses this issue and makes it straightforward to provide information about what time-step and expression was involved in the warning.

  1. Define an enum of distinct warning messages.
  2. When a warning is triggered it pushes back one int into each of the following vectors:
    • warn_msg_int : value of the enum for the triggered warning
    • warn_row : parse table row
    • warn_time : time step
  3. These vectors are placed in the report.
  4. On the r-side we can interpret every element of these vectors:
    • warn_msg_int -> character vector of warning messages
    • warn_row -> vector of expressions as characters (e.g. "x ~ round(0.5)")
    • warn_time -> unaltered vector of time-steps
  5. Summarise this 'warning table' so that the time column is a string representing time-step ranges (e.g. "1, 5-10"), which would keep the table from being too long in models with many time-steps.
  6. When this interpreted and summarised warning table has more than zero rows, throw a warning that prints the table.
bbolker commented 6 months ago

This seems like a good idea. It's too bad that we're working within C++ instead of R here; in R we could more easily write functions that modify their environments to warn only once in a session (as discussed by you in a recent lab meeting I think?)

I'm trying to think of alternative ways to achieve this goal without writing our own warning system ...

stevencarlislewalker commented 6 months ago

This is a great point. Can we get any inspiration from glmmTMB here?