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

Error: the complex F is not supported by babelmixr2 #115

Open
john-harrold opened this issue Aug 21, 2024 · 23 comments
Open

Error: the complex F is not supported by babelmixr2 #115

john-harrold opened this issue Aug 21, 2024 · 23 comments

Comments

@john-harrold
Copy link

I'm testing the models in the model library (nlmixr2lib) trying to convert them to different formats. I'm having trouble converting this one to monolix.

library(babelmixr2)
#> Loading required package: nlmixr2
#> Loading required package: nlmixr2data
library(rxode2)
#> rxode2 2.1.3.9000 using 5 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
rx_fun = 
function() {
    covariateData <- list(WT = "Body weight in kg")
    description <- "Dupilumab PK model (Kovalenko 2020)"
    reference <- "Kovalenko P, Davis JD, Li M, et al. Base and Covariate Population Pharmacokinetic Analyses of Dupilumab Using Phase 3 Data. Clinical Pharmacology in Drug Development. 2020;9(6):756-767. doi:10.1002/cpdd.780"
    units <- list(time = "day", dosing = "mg")
    ini({
        lvc <- 0.908258560176891
        label("central volume (L)")
        lke <- -2.92994453301599
        label("elimination rate (1/d)")
        lkcp <- -1.54646311327271
        label("central-to-peripheral rate (1/d)")
        Mpc <- 0.686
        label("ratio of kcp and kpc (kpc is peripheral to central rate with units of 1/d)")
        lka <- -1.36257783450257
        label("absorption rate (1/d)")
        lMTT <- -2.25379492882461
        label("mean transit time (d)")
        lVm <- 0.0676586484738149
        label("maximum target-mediated rate of elimination (mg/L/d)")
        Km <- fix(0.01)
        label("Michaelis-Menten constant (mg/L)")
        lfdepot <- -0.441610554744518
        label("Bioavailability (fraction)")
        e_wt_vc <- 0.711
        label("Exponent of weight on central volume (unitless)")
        CcpropSd <- c(0, 0.15)
        label("Proportional residual error (fraction)")
        CcaddSd <- fix(0, 0.03)
        label("Additive residual error (mg/L)")
        etalvc ~ 0.192
        etalke ~ 0.285
        etalka ~ 0.474
        etalvm ~ 0.236
        etamtt ~ 0.525
    })
    model({
        vc <- exp(lvc + etalvc) * (WT/75)^e_wt_vc
        ke <- exp(lke + etalke)
        kcp <- exp(lkcp)
        ka <- exp(lka + etalka)
        MTT <- exp(lMTT + etamtt)
        Vm <- exp(lVm + etalvm)
        kpc <- kcp/Mpc
        ktr <- (3 + 1)/MTT
        d/dt(depot) <- -ktr * depot
        d/dt(transit1) <- ktr * (depot - transit1)
        d/dt(transit2) <- ktr * (transit1 - transit2)
        d/dt(transit3) <- ktr * transit2 - ka * transit3
        d/dt(central) <- ka * transit3 - ke * central - kcp * 
            central + kpc * periph - central * (Vm/(Km + central/vc))
        d/dt(periph) <- kcp * central - kpc * periph
        f(depot) <- exp(lfdepot)
        Cc <- central/vc
        Cc ~ add(CcaddSd) + prop(CcpropSd)
    })
}

rx_obj = rxode2::rxode2(rx_fun)
export_name = "test"

library(tibble)
dataset = 
tribble(
~id,  ~low,  ~time,  ~high,  ~cmt,  ~amt,  ~rate,  ~ii,  ~addl,  ~evid,  ~ss,  ~dur,  ~WT,  ~dv,
  1,    NA,      0,     NA,  'Cc',    NA,     NA,   NA,     NA,      0,   NA,    NA,    1,    0,
  1,    NA,      1,     NA,  'Cc',    NA,     NA,   NA,     NA,      0,   NA,    NA,    1,    0,
  2,    NA,      0,     NA,  'Cc',    NA,     NA,   NA,     NA,      0,   NA,    NA,    1,    0,
  2,    NA,      1,     NA,  'Cc',    NA,     NA,   NA,     NA,      0,   NA,    NA,    1,    0)

res = nlmixr2::nlmixr2(rx_obj, dataset, "monolix", babelmixr2::monolixControl(modelName=export_name, runCommand=NA))
#> Error : the complex F is not supported by babelmixr2
#> Error: the complex F is not supported by babelmixr2

Created on 2024-08-20 with reprex v2.1.1

@mattfidler
Copy link
Member

That is because it isn't supported because f(depot) is an equation. More parsing could probably support this particular expression, though I am not likely to get to this soon.

@mattfidler
Copy link
Member

The error could be a bit more clear, I suppose.

@john-harrold
Copy link
Author

Is there a way I can detect it's presence in rx_obj above?

@mattfidler
Copy link
Member

mattfidler commented Aug 21, 2024

Nope.

@mattfidler
Copy link
Member

At least not as the nlmixr2/rxode2 interface is currently written.

@john-harrold
Copy link
Author

Can I add that to the props? I know this isn't the place to request it :)

@mattfidler
Copy link
Member

That is where it would likely go, though I believe I wouldn't support this directly since it is too much of a edge case for properties, rather I would support what properties (aka initial condition, f, rate, dur, alag) are present in the model and for what state).

Then you could use modelExtract() to parse this out yourself. I would say that if this changes, it wouldn't work so this idea is fragile. I think you should base it on if the model translates instead. But that is just my thoughts right now.

There are likely cases where a model won't import from nonmem or export to nonmem, and the same is true for monolix.

@john-harrold
Copy link
Author

I'm sorry, you would rather support f, but isn't this f?

@john-harrold
Copy link
Author

Oh I see. Can you add what properties are supported? I can easily use that.

@mattfidler
Copy link
Member

I will add what properties are defined by the model.

For example in this model you would have some way of figuring out that f(depot) is in the model.

@john-harrold
Copy link
Author

Awesome. Thank you.

@john-harrold
Copy link
Author

If I wanted to conditionally skip tests for Monolix conversion where f is causing failure would I look at the Property column from the props$cmtProp data frame for a value of f?

$cmtProp
  Compartment Property
1       depot        f

@john-harrold john-harrold reopened this Sep 28, 2024
@mattfidler
Copy link
Member

No value of f is in the data frame. You would have to query it from the UI.

You can probably get that information from modelExtract(). The data.frame simply states there is a property there (not the value of it).

See

https://nlmixr2.github.io/rxode2/articles/Modifying-Models.html#creating-more-complex-model-modification-functions

@mattfidler
Copy link
Member

mattfidler commented Sep 29, 2024

I do not plan to add this to the data.frame either since it is can be queried elsewhere...

@john-harrold
Copy link
Author

If I wanted to conditionally skip tests for Monolix conversion where f is causing failure would I look at the Property column from the props$cmtProp data frame for a value of f?

$cmtProp
  Compartment Property
1       depot        f

This is what is in the props$cmtProp field.

@mattfidler
Copy link
Member

mattfidler commented Sep 29, 2024

Yes but it doesn't have the value of f(depot), just that f(depot) is in the model in some form. If you want to get the value you would have to query it.

@mattfidler
Copy link
Member

mattfidler commented Sep 29, 2024

If you want to skip all monolix models with f, then yes this would work, though some monolix models with F work just fine.

@john-harrold
Copy link
Author

I just need a way to detect models that will fail during testing. Can you tell me what babelmixr2 is looking at to throw the error?

@mattfidler
Copy link
Member

It looks for a f that depends on derived variables as opposed to an f that depends on only initial estimates.

@mattfidler
Copy link
Member

As said by the bug report, this example is likely a bug.

@john-harrold
Copy link
Author

john-harrold commented Sep 30, 2024 via email

@mattfidler
Copy link
Member

It's not obvious. It's linked to this issue in babelmixr2 issues...

@mattfidler
Copy link
Member

#116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants