Development (original) (raw)

Guidelines

Developers without write access to the adcomp repository can contribute with code or documentation by forking the project and sending a pull request once the code has been changed.

git checkout master  
git pull official master  
git checkout master  
git pull official master  

And delete you local branch
git branch -d local_branch
Remember to delete it on github:
git push origin --delete local_branch

For developers with write access to the adcomp repository:

Conventions

Code formatting

Automated code formatting is recommended for new files

Distributing code

Probably the easiest way to distribute TMB code is to use R's package functionality. You can get a test package working following these steps (with mypkg replaced by the name of your package):

TMB uses some features that are against the CRAN polices (e.g. calling abort() to step into the debugger). In order to pass CRAN checks a few workarounds may be required:

#define TMB_LIB_INIT R_init_mypkg  
#include <TMB.hpp>  

In addition this enables 'C-callables' tmb_forward and tmb_reverse required by tmbstan.

Other notes:

Locating regressions and bugs

Suppose you update TMB and suddenly your model runs slow or has other issues. To find the commit that caused the problem, we can apply 'git bisect'.

  1. Clone a fresh adcomp folder and cd adcomp.
  2. Copy a selfcontained test example e.g. 'mymodel.R' and 'mymodel.cpp' to this folder.
  3. Make R-script 'bisect.R' containing:

Re-install TMB and re-compile model:

system("make install")
library(TMB)
system("rm -f *.o *.so")
compile("mymodel.cpp")

Run model under restricted permissions

status <- system("ulimit -t 20; R --vanilla < mymodel.R")
if(status != 0) stop("Fail")
Here 'ulimit -t 20' interrupts the model run if it takes more than 20 sec. Alternatively 'ulimit -v 100000' would trigger interruption if the model uses more than 100Mb. 4. Make an executable shell script 'bisect.sh' containing:
#/bin/bash
R --vanilla < bisect.R 5. Verify that the script fails now and that it worked e.g. 40 commits ago:
git checkout master
./bisect.sh
git checkout HEAD40
./bisect.sh 6. Now we can start bisecting:
git checkout master
git bisect start
git bisect bad HEAD
git bisect good HEAD
40
git bisect run ./bisect.sh
The first bad commit will be displayed.