PopED + babelmixr2 for windows#79
Conversation
|
In general it saves the |
|
Had to add |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #79 +/- ##
==========================================
- Coverage 44.52% 44.49% -0.04%
==========================================
Files 120 120
Lines 8810 8817 +7
==========================================
Hits 3923 3923
- Misses 4887 4894 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
As |
|
The error in oldrel-1 is unrelated to this pull request. |
|
Thanks Andy! |
There was a problem hiding this comment.
Why do we need to add
start_parallel_env <- new.env(parent=emptyenv())
start_parallel_env$babelmixr2 <- NULL
outside of the function?
There was a problem hiding this comment.
This is so it can be assigned in a global like environment.
The actual function is
parallel::clusterCall(cl, babelmixr2::.popedCluster, start_parallel_env$babelmixr2)|
Hi Matt, Thanks for all your work on this. I am wondering if there is any way to achieve the same result without having to add the following code snippet in, essentially, every PopED function?
Could you supply a minimal working example that I could test a bit with? My thought is that it should be a bit more efficient to just pass Andy |
|
parallel::clusterCall(cl, babelmixr2::.popedCluster, start_parallel_env$babelmixr2)
I originally tried this, but it dropped the |
|
I simply used your examples and modified it. You could try the warfarin one: |
start_parallel() now auto-detects poped.db$babelmixr2 from parent.frame(), the same mechanism already used for clusterExport(). This removes the per-function boilerplate and module-level global state.
|
I uppdated start_parallel() so that it now auto-detects poped.db$babelmixr2 from parent.frame(), the same mechanism already used for clusterExport(). This removes the per-function boilerplate and module-level global state. I think this solution should work. Can you test it? |
|
Reading the code, it is a bit fragile; it assumes you are using the name |
|
Hi Matt, I have tried to update the fix to make it more robust. I had a hard time installing babelmixr2 on my parallels version of windows, so I would be happy if you could test it. I notice that with that using babelmixr2 instead of the original example causes a slowdown of many orders of magnitude. Not quite sure why. |
|
Just tested, it still doens't work: library(babelmixr2)
library(PopED)
##-- Model: One comp first order absorption
## -- Analytic solution for both mutiple and single dosing
f <- function() {
ini({
tV <- 72.8
tKa <- 0.25
tCl <- 3.75
tF <- fix(0.9)
eta.v ~ 0.09
eta.ka ~ 0.09
eta.cl ~0.25^2
prop.sd <- fix(sqrt(0.04))
add.sd <- fix(sqrt(5e-6))
})
model({
V<-tV*exp(eta.v)
KA<-tKa*exp(eta.ka)
CL<-tCl*exp(eta.cl)
Favail <- tF
N <- floor(time/TAU)+1
y <- (DOSE*Favail/V)*(KA/(KA - CL/V)) *
(exp(-CL/V * (time - (N - 1) * TAU)) *
(1 - exp(-N * CL/V * TAU))/(1 - exp(-CL/V * TAU)) -
exp(-KA * (time - (N - 1) * TAU)) * (1 - exp(-N * KA * TAU))/(1 - exp(-KA * TAU)))
y ~ prop(prop.sd) + add(add.sd)
})
}
e <- et(list(c(0, 1, 10),
c(0, 2, 10),
c(0, 8, 10),
c(240, 240, 248),
c(240, 245, 248))) %>%
as.data.frame()
babel.db <- nlmixr2(f, e, "poped",
popedControl(groupsize=20,
bUseGrouped_xt=TRUE,
a=list(c(DOSE=20,TAU=24),
c(DOSE=40, TAU=24)),
maxa=c(DOSE=200,TAU=24),
mina=c(DOSE=0,TAU=24)))
## create plot of model without variability
plot_model_prediction(babel.db, model_num_points = 300)
## create plot of model with variability
plot_model_prediction(babel.db, IPRED=T, DV=T, separate.groups=T, model_num_points = 300)
## evaluate initial design
## From original
## $rse
## V KA CL d_V d_KA d_CL
## 8.215338 10.090955 4.400304 39.833230 60.089601 27.391518
evaluate_design(babel.db)
## original: > shrinkage(poped.db)
## # A tibble: 9 × 5
## d_V d_KA d_CL type group
## <dbl> <dbl> <dbl> <chr> <chr>
## 1 0.364 0.578 0.184 shrink_var all_groups
## 2 0.364 0.579 0.184 shrink_var grp_1
## 3 0.363 0.577 0.183 shrink_var grp_2
## 4 0.202 0.350 0.0965 shrink_sd all_groups
## 5 0.202 0.351 0.0967 shrink_sd grp_1
## 6 0.202 0.350 0.0963 shrink_sd grp_2
## 7 0.181 0.228 0.107 se all_groups
## 8 0.181 0.228 0.107 se grp_1
## 9 0.181 0.228 0.107 se grp_2
shrinkage(babel.db)
# Optimization of sample times
# Note: The parallel option does not work well with Windows machines at this moment.
# Please set parallel = FALSE if you are working on a Windows machine
output <- poped_optim(babel.db, opt_xt =TRUE, parallel=TRUE)
# Evaluate optimization results
summary(output)
## From original
# V KA CL d_V d_KA d_CL
# 6.281944 7.726279 4.295908 32.416232 49.062880 26.363021
get_rse(output$FIM,output$poped.db)
plot_model_prediction(output$poped.db)
# Optimization of sample times and doses
# Note: The parallel option does not work well with Windows machines at this moment.
# Please set parallel = FALSE if you are working on a Windows machine
output_2 <- poped_optim(output$poped.db, opt_xt =TRUE, opt_a = TRUE, parallel = TRUE)Gives |
|
Sigh …
OK, thanks. Back to the drawing board!
Andy
… On 8 May 2026, at 00:34, Matthew Fidler ***@***.***> wrote:
mattfidler
left a comment
(andrewhooker/PopED#79)
<#79 (comment)>
Just tested, it still doens't work:
library(babelmixr2)
library(PopED)
##-- Model: One comp first order absorption
## -- Analytic solution for both mutiple and single dosing
f <- function() {
ini({
tV <- 72.8
tKa <- 0.25
tCl <- 3.75
tF <- fix(0.9)
eta.v ~ 0.09
eta.ka ~ 0.09
eta.cl ~0.25^2
prop.sd <- fix(sqrt(0.04))
add.sd <- fix(sqrt(5e-6))
})
model({
V<-tV*exp(eta.v)
KA<-tKa*exp(eta.ka)
CL<-tCl*exp(eta.cl)
Favail <- tF
N <- floor(time/TAU)+1
y <- (DOSE*Favail/V)*(KA/(KA - CL/V)) *
(exp(-CL/V * (time - (N - 1) * TAU)) *
(1 - exp(-N * CL/V * TAU))/(1 - exp(-CL/V * TAU)) -
exp(-KA * (time - (N - 1) * TAU)) * (1 - exp(-N * KA * TAU))/(1 - exp(-KA * TAU)))
y ~ prop(prop.sd) + add(add.sd)
})
}
e <- et(list(c(0, 1, 10),
c(0, 2, 10),
c(0, 8, 10),
c(240, 240, 248),
c(240, 245, 248))) %>%
as.data.frame()
babel.db <- nlmixr2(f, e, "poped",
popedControl(groupsize=20,
bUseGrouped_xt=TRUE,
a=list(c(DOSE=20,TAU=24),
c(DOSE=40, TAU=24)),
maxa=c(DOSE=200,TAU=24),
mina=c(DOSE=0,TAU=24)))
## create plot of model without variability
plot_model_prediction(babel.db, model_num_points = 300)
## create plot of model with variability
plot_model_prediction(babel.db, IPRED=T, DV=T, separate.groups=T, model_num_points = 300)
## evaluate initial design
## From original
## $rse
## V KA CL d_V d_KA d_CL
## 8.215338 10.090955 4.400304 39.833230 60.089601 27.391518
evaluate_design(babel.db)
## original: > shrinkage(poped.db)
## # A tibble: 9 × 5
## d_V d_KA d_CL type group
## <dbl> <dbl> <dbl> <chr> <chr>
## 1 0.364 0.578 0.184 shrink_var all_groups
## 2 0.364 0.579 0.184 shrink_var grp_1
## 3 0.363 0.577 0.183 shrink_var grp_2
## 4 0.202 0.350 0.0965 shrink_sd all_groups
## 5 0.202 0.351 0.0967 shrink_sd grp_1
## 6 0.202 0.350 0.0963 shrink_sd grp_2
## 7 0.181 0.228 0.107 se all_groups
## 8 0.181 0.228 0.107 se grp_1
## 9 0.181 0.228 0.107 se grp_2
shrinkage(babel.db)
# Optimization of sample times
# Note: The parallel option does not work well with Windows machines at this moment.
# Please set parallel = FALSE if you are working on a Windows machine
output <- poped_optim(babel.db, opt_xt =TRUE, parallel=TRUE)
# Evaluate optimization results
summary(output)
## From original
# V KA CL d_V d_KA d_CL
# 6.281944 7.726279 4.295908 32.416232 49.062880 26.363021
get_rse(output$FIM,output$poped.db)
plot_model_prediction(output$poped.db)
# Optimization of sample times and doses
# Note: The parallel option does not work well with Windows machines at this moment.
# Please set parallel = FALSE if you are working on a Windows machine
output_2 <- poped_optim(output$poped.db, opt_xt =TRUE, opt_a = TRUE, parallel = TRUE)
Gives
************* Iteration 1 for all optimization methods***********************
*******************************************
Running Adaptive Random Search Optimization
*******************************************
Error in `start_parallel()`:
! object 'babelmixr2_model' not found
Hide Traceback
Fix
Explain
▆
1. └─PopED::poped_optim(babel.db, opt_xt = TRUE, parallel = TRUE)
2. ├─base::do.call(poped_optim_3, c(new.arg.list, dot_vals))
3. └─PopED (local) `<fn>`(...)
4. ├─base::do.call(...)
5. └─PopED (local) `<fn>`(...)
6. └─PopED::start_parallel(...)
—
Reply to this email directly, view it on GitHub <#79 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABJOMZAOT3WPOU2JFLHGU3T4ZUFQHAVCNFSM6AAAAACL7PWWVKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DIMBRGY2TSNJXG4>.
You are receiving this because you were mentioned.
|
|
The original pull works 😄 |

Hi @andrewhooker
This allows windows based
PopEDmodels from babelmixr2 to be run in parallel without modifying any user code. This mean the same user code works on windows and linux/mac