bit weird behavior with RTMB?

252 views
Skip to first unread message

William Stockhausen - NOAA Federal

unread,
Mar 2, 2024, 2:51:09 PM3/2/24
to TMB Users
I'm new to RTMB, so a problem I've experienced is probably just from naivete, not from an issue with RTMB. I've coded up an objective function in R that calls a couple of other functions (might or might not  be relevant). The source for all the functions involved is in a separate file from the script I run to MakeADFun of the objective function. If I source the file with the objective function code and MakeADFun it, everything works fine. However, if I source the code, run the objective function code as an R function (i.e., without having MakeADFun'd it first), and then MakeADFun it, I get the error "Error in advector(e1) : Invalid argument to 'advector' (lost class attribute?)". If I then remove the sourced functions, source the code again, and just run MakeADFun I get no error message and everything seems fine.

So my question is: Is this expected behavior? I.e., don't run your objective function as an R function before MakeADFun'ing it? Hopefully the answer is simply "yes, you dummy, you must have missed it in the help files". 

Cheers!

William T. Stockhausen

Research Fishery Biologist, Alaska Fisheries Science Center

NOAA Fisheries | U.S. Department of Commerce

Office: (206) 526-4241

www.fisheries.noaa.gov


Kasper Kristensen

unread,
Mar 4, 2024, 3:46:20 AM3/4/24
to TMB Users
Sounds to me like a bug. Would it be possible to boil down the example and post a github issue?

FWIW, there are some unfortunate side effects of R's 'byte compiler' (enabled by default in R) which might explain the weird behavior. Could you try running the example with byte compiler disabled:

compiler::enableJIT(0)

William Stockhausen - NOAA Federal

unread,
Mar 4, 2024, 6:42:22 PM3/4/24
to Kasper Kristensen, TMB Users
Thanks Kasper!

As you suggested, using the "compiler::enableJIT(0)" does eliminate the issue!

Attached are files that will generate the error if "compiler::enableJIT(0)" is commented out. Just put all files in the same folder, make that the working directory, and run_code.R. 

William T. Stockhausen

Research Fishery Biologist, Alaska Fisheries Science Center

NOAA Fisheries | U.S. Department of Commerce

Office: (206) 526-4241

www.fisheries.noaa.gov



--
To post to this group, send email to us...@tmb-project.org. Before posting, please check the wiki and issuetracker at https://github.com/kaskr/adcomp/. Please try to create a simple repeatable example to go with your question (e.g issues 154, 134, 51). Use the issuetracker to report bugs.
---
You received this message because you are subscribed to the Google Groups "TMB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tmb-users/5d98477f-4c1d-473f-bf00-03b6dfd7fb65n%40googlegroups.com.
ex1a.dat
rtmb_objfun.R
run_code.R
Reply all
Reply to author
Forward
0 new messages