Skip to content

Commit

Permalink
Broken cmt ordering in solve
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Sep 10, 2024
1 parent 6105d95 commit 0d79ce4
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions tests/testthat/test-cmt-order.R
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,128 @@ rxTest({
expect_equal(tmp$stateExtra, "cp")
})

test_that("compartment ordering does not affect c-code generation #785",
{

f1 <- function() {
ini({
TVCL <- c(0, 0.0308628127403366)
TVV1 <- c(0, 0.132584062223269)
TVQ <- c(0, 0.0107718034646091)
TVV2 <- c(0, 0.0613517707801907)
TVR0 <- c(0, 3.94111989610973)
TVKON <- c(0, 1.31095109796496)
TVKOFF <- c(0, 0.0758072298659602)
TVKDEG <- c(0, 1.07290072658165)
TVKINT <- c(0, 3.49422759360926)
ADD.ERR.PK <- c(0, 0.446231462752061)
ETA.CL ~ 0.0499998244205031
})
model({
CL <- TVCL * exp(ETA.CL)
V1 <- TVV1
Q <- TVQ
V2 <- TVV2
R0 <- TVR0
KON <- TVKON
KOFF <- TVKOFF
KDEG <- TVKDEG
KINT <- TVKINT
KEL <- CL/V1
K12 <- Q/V1
K21 <- Q/V2
KD <- KOFF/KON
KSYN <- R0 * KDEG
A3(0) <- R0
KEL <- 0
d/dt(A1) = -(K12 + KEL) * A1 + K21 * A2 - KON * A1 *
A3 + KOFF * A4 * V1
d/dt(A2) = K12 * A1 - K21 * A2
d/dt(A3) = KSYN - KDEG * A3 - KON * (A1/V1) * A3 + KOFF *
A4
d/dt(A4) = KON * (A1/V1) * A3 - (KINT + KOFF) * A4
CFREE = A1/V1
CTOT = CFREE + A4
CP = log(CTOT)
CP ~ add(ADD.ERR.PK)
SPEC.OUT <- SPEC
DGRP.OUT <- DGRP
BW.OUT <- BW
})
}

f1 <- f1 %>% zeroRe("omega")

library(rxode2)

f2 <- function() {
ini({
TVCL <- c(0, 0.0308628127403366)
TVV1 <- c(0, 0.132584062223269)
TVQ <- c(0, 0.0107718034646091)
TVV2 <- c(0, 0.0613517707801907)
TVR0 <- c(0, 3.94111989610973)
TVKON <- c(0, 1.31095109796496)
TVKOFF <- c(0, 0.0758072298659602)
TVKDEG <- c(0, 1.07290072658165)
TVKINT <- c(0, 3.49422759360926)
ADD.ERR.PK <- c(0, 0.446231462752061)
ETA.CL ~ 0.0499998244205031
})
model({
cmt(A1)
cmt(A2)
cmt(A3)
cmt(A4)
CL <- TVCL * exp(ETA.CL)
V1 <- TVV1
Q <- TVQ
V2 <- TVV2
R0 <- TVR0
KON <- TVKON
KOFF <- TVKOFF
KDEG <- TVKDEG
KINT <- TVKINT
KEL <- CL/V1
K12 <- Q/V1
K21 <- Q/V2
KD <- KOFF/KON
KSYN <- R0 * KDEG
A3(0) <- R0
KEL <- 0
d/dt(A1) = -(K12 + KEL) * A1 + K21 * A2 - KON * A1 *
A3 + KOFF * A4 * V1
d/dt(A2) = K12 * A1 - K21 * A2
d/dt(A3) = KSYN - KDEG * A3 - KON * (A1/V1) * A3 + KOFF *
A4
d/dt(A4) = KON * (A1/V1) * A3 - (KINT + KOFF) * A4
CFREE = A1/V1
CTOT = CFREE + A4
CP = log(CTOT)
CP ~ add(ADD.ERR.PK)
SPEC.OUT <- SPEC
DGRP.OUT <- DGRP
BW.OUT <- BW
})
}

f2 <- f2 %>% zeroRe("omega")

ev <- eventTable()
mybw <- 70
mymw <- 150000
mydgrp <- 50
ev$add.dosing(dose=mydgrp*mybw*1000000/mymw ,nbr.doses= 13, dosing.interval= 7)
ev$add.sampling(seq(0,13*7,length.out=7))

ev2 <- ev %>% as.data.frame() %>%
dplyr::mutate(BW=mybw, DGRP=mydgrp, SPEC=4)

s2 <- rxSolve(f2, ev2, returnType="data.frame")

s1 <- rxSolve(f1, ev2, returnType="data.frame")

expect_equal(s1, s2)
})

})

0 comments on commit 0d79ce4

Please sign in to comment.