FelicienLL / mapbayr

Easy Maximum A Posteriori Bayesian Estimation of PK parameters in R.
21 stars 2 forks source link

shared object not loaded #130

Closed FelicienLL closed 2 years ago

FelicienLL commented 2 years ago

Test if mrgsolve shared object is loaded, and return an explicit error message if not. Currently, if the SO is missing, the optimizer is just crashing.

kylebaron commented 2 years ago

mrgsolve should try to load the shared object if it isn't loaded when you go to simulate. You can check for the shared object here (I think you are already pulling this list)

as.list(mod)$sodll

So maybe something like this

x <- as.list(mod)
stopifnot(file.exists(x$sodll))

and optionally

loadso(mod)

But this step should happen under the hood if the so isn't loaded.

FelicienLL commented 2 years ago

Yes, thanks, this is what I was thinking about. It happened in these situations when we do not pay much attention on how models and R objects were named... mrgsolve returns a good error message, but inside optim() it does not show up apparently... loadso() does not help though.

library(mrgsolve)
#> 
#> Attachement du package : 'mrgsolve'
#> L'objet suivant est masqué depuis 'package:stats':
#> 
#>     filter
cod <-"$PARAM CL = 1" 
mod    <- mcode("mod", cod)
#> Building mod ...
#> done.
modbis <- mcode("mod", cod)
#> Building mod ...
#> (waiting) ...
#> done.

mrgsim(mod)
#> Error : [loadso] the model dll file doesn't exist
#> Error in pointers(x): 
#> There was a problem accessing the model shared object.
#>   Either the model object was corrupted or the model was 
#>   not properly compiled and/or loaded. If the model is 
#>   not loaded, use `loadso(mod)` to do so. This is usually 
#>   required for parallel simulation on a worker node that
#>   was not forked (e.g. when using future::multisession).
#>   Also check mrgsolve:::funset(mod) for more information.
loadso(mod)
#> Error: [loadso] the model dll file doesn't exist
kylebaron commented 2 years ago

Oh ... ok; then maybe you could just do try(loadso(mod)) and check that.