Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor]: when should FIMS switch to TMBad? #210

Open
Andrea-Havron opened this issue Aug 2, 2022 · 10 comments
Open

[Refactor]: when should FIMS switch to TMBad? #210

Andrea-Havron opened this issue Aug 2, 2022 · 10 comments
Assignees
Labels
kind: refactor Restructure code to improve the implementation of FIMS P3 low priority task status: in progress Designing or coding is actively occurring theme: code cleanup
Milestone

Comments

@Andrea-Havron
Copy link

Andrea-Havron commented Aug 2, 2022

Refactor request

TMB's default AD library depends of CppAD but a new AD library, TMBad, is available for TMB version 1.8.0 and hgiher.

Currently, the FIMS Rcpp Interface sets up four instances of the model to interface with CppAD Types (defined here). This architecture does not work when using the TMBad library.

Should FIMS develop an interface that works with both libraries or deprecate the support for CppAD, requiring users install TMB 1.8.0 and higher?
TMBad is still considered experimental. What criteria should we use to determine TMBad is tested enough to use for FIMS?

Expected behavior

Currently when trying to run the ModularTMBExample with the DTMBAD_FRAMEWORK compile flag specified, the model compiles and runs, but parameter values are not being updated and the objective function is not minimized.

A new Rcpp interface needs to be specified when #ifdef TMBAD_FRAMEWORK. Optimization needs to be implemented in order to test the architecture is set up correctly for the new TMBad library to work.

@Andrea-Havron Andrea-Havron added the status: triage_needed This is not approved for this milestone, do not work on it yet label Aug 2, 2022
@msupernaw
Copy link
Contributor

msupernaw commented Aug 3, 2022

We should develop an interface that works with both libraries and eventually deprecate the former. After TMBad is out of experimental mode, we can use an R script to rewrite the Makevars files and expose the appropriate #define statements based on the installed version of TMB.
Something like this:

v<-compareVersion(toString(packageVersion("TMB")), "1.9.0")

if(v == 1){

 file.rename(from = "~/.R/Makevars", to = "~/.src/Makevars_old")
 file.remove("~/.src/Makevars")

 file.rename(from = "~/.R/Makevars.win", to = "~/.src/Makevars.win_old")
 file.remove("~/.src/Makevars")

 cat("CXX14FLAGS +=  -DTMB_AD_MODEL -mtune=native -march=native -Wno-ignored- 
 attributes -Wno-deprecated-declarations", file = "~/.src/Makevars")

 cat("CXX14FLAGS +=  -DTMB_AD_MODEL -mtune=native -march=native -Wno-ignored- 
 attributes -Wno-deprecated-declarations", file = "~/.src/Makevars.win")

}

@k-doering-NOAA
Copy link
Member

I agree with the philosophy of testing out TMBad and then once we are confident it is working well with FIMS, deprecating CPPad so we don't need to maintain CPPad code in the long term. I think the deprecation process can be very quick given FIMS is still in the early stages of development and no one is depending on it yet for stock assessments (or other uses).

@ChristineStawitz-NOAA ChristineStawitz-NOAA added kind: feature New feature or request status: wishlist this will be moved to a later milestone and removed status: triage_needed This is not approved for this milestone, do not work on it yet labels Aug 9, 2022
@ChristineStawitz-NOAA ChristineStawitz-NOAA added this to the MQ milestone Aug 9, 2022
@ChristineStawitz-NOAA
Copy link
Contributor

Speedups come from TMBad - Kasper speeds up the AD computations with a list. Bias correction is faster due to some rank-reduced thing. It would make add_to_fims_tmb simpler because we would only need one template rather than four. At some point, Kasper will deprecate the CppAD and then we will need to switch, keeping reverse compatibility with CppAD would increase flexibility without much overhead but would increase maintenance costs.

@Andrea-Havron-NOAA Andrea-Havron-NOAA added the status: needs discussion Dialogue is needed before a decision can be made. label Jul 11, 2023
@Andrea-Havron-NOAA
Copy link
Collaborator

Related to Issue #390 #241

@kellijohnson-NOAA
Copy link
Contributor

This issue is currently in the "Parking Lot" milestone but I would like to make a decision if we should switch to TMBad. Please, view this comment on GitHub and respond with a thumbs down if you do NOT want to move to TMBad. If there are any 👎 or 👀 reactions by EOD June 21, 2024, I will schedule some time, for those that want to attend, to discuss the decision.

@kellijohnson-NOAA kellijohnson-NOAA self-assigned this Jun 13, 2024
@kellijohnson-NOAA kellijohnson-NOAA removed the status: wishlist this will be moved to a later milestone label Jun 13, 2024
@Andrea-Havron-NOAA
Copy link
Collaborator

TMBad functinality would require:

  • Adding the three lines of code from tmb_core.hpp to FIMS def.hpp.
  • Each rcpp_object would need a new line specifying the TMBad type (e.g. here).
  • CreateTMBModel() in rcpp_interface updated to point to the single GetInstance from TMBad
  • clear_internal in rcpp_interface updated to clear TMBad pointers
  • Old Cppad specific code would need to be wrapped in #ifdef CPPAD_FRAMEWORK and new TMBad code wrapped in #ifdef TMBAD_FRAMEWORK
  • Makevars changed to include -DTMBAD_FRAMEWORK flag (e.g. here)

@msupernaw
Copy link
Contributor

👎, my vote is to wait until M2 is complete. I feel we should focus on the modeling components of FIMS. Switching would be trivial if there are no problems, but if there are issues discovered, it might hinder development if we devote time to a TMB problem.

@kellijohnson-NOAA kellijohnson-NOAA removed kind: feature New feature or request status: needs discussion Dialogue is needed before a decision can be made. labels Jun 27, 2024
@kellijohnson-NOAA kellijohnson-NOAA added status: wishlist this will be moved to a later milestone kind: refactor Restructure code to improve the implementation of FIMS theme: code cleanup and removed theme: NLL refactor Negative log likelihood labels Jun 27, 2024
@kellijohnson-NOAA
Copy link
Contributor

As discussed in NOAA-FIMS/seaside-chats#5, we will be switching to TMBad after M2 during the cleanup phase.

@msupernaw
Copy link
Contributor

msupernaw commented Jun 27, 2024 via email

@Andrea-Havron-NOAA
Copy link
Collaborator

@kellijohnson-NOAA, should we add this task to #662?

@kellijohnson-NOAA kellijohnson-NOAA added status: in progress Designing or coding is actively occurring and removed status: wishlist this will be moved to a later milestone labels Nov 8, 2024
@kellijohnson-NOAA kellijohnson-NOAA modified the milestones: Parking lot, 2 Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: refactor Restructure code to improve the implementation of FIMS P3 low priority task status: in progress Designing or coding is actively occurring theme: code cleanup
Projects
None yet
Development

No branches or pull requests

6 participants