-
Notifications
You must be signed in to change notification settings - Fork 36
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
Fill out plugin for tools to implement events inside the model #1149
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
04340bb
first start on evtools expansion
kylebaron 892d8a2
working on evtools
kylebaron e002716
add push method; re-order argument order
kylebaron 761b26a
add api
kylebaron 76b4cb9
drop api functions; add retime method
kylebaron d7ed16a
remove retime method from object and provide in evtools namespace
kylebaron e12529c
adds now method
kylebaron 5ab4b5b
add push method to evtools
kylebaron 5207ad2
adding unit tests for evtools
kylebaron e949d3f
adds test for now method; switch to self.push()
kylebaron 21f0d53
pull code out of modelheader.h
kylebaron 90cf8be
remove space
kylebaron 3d3d18a
restore mrgsolve::evt::push
kylebaron 5dbdcfc
remove local edition call at end of file
kylebaron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
|
||
namespace mrgsolve { | ||
namespace evt { | ||
void push(databox& self, mrg::evdata ev) { | ||
self.mevector.push_back(ev); | ||
} | ||
namespace evt { | ||
|
||
typedef mrgsolve::evdata ev; | ||
|
||
mrgsolve::evdata bolus(const double amt, const int cmt) { | ||
mrgsolve::evdata ev(0, 1); | ||
ev.amt = amt; | ||
ev.cmt = cmt; | ||
ev.check_unique = false; | ||
ev.now = true; | ||
return ev; | ||
} | ||
|
||
void bolus(databox& self, const double amt, const int cmt) { | ||
mrgsolve::evdata ev = bolus(amt, cmt); | ||
self.mevector.push_back(ev); | ||
return; | ||
} | ||
|
||
mrgsolve::evdata infuse(const double amt, const int cmt, const double rate) { | ||
mrgsolve::evdata ev(0, 1); | ||
ev.amt = amt; | ||
ev.cmt = cmt; | ||
ev.rate = rate; | ||
ev.now = true; | ||
ev.check_unique = false; | ||
return ev; | ||
} | ||
|
||
void infuse(databox& self, const double amt, const int cmt, const double rate) { | ||
mrgsolve::evdata ev = infuse(amt, cmt, rate); | ||
self.mevector.push_back(ev); | ||
return; | ||
} | ||
|
||
void retime(mrgsolve::evdata& ev, const double time) { | ||
ev.time = time; | ||
ev.now = false; | ||
return; | ||
} | ||
|
||
void now(mrgsolve::evdata& ev) { | ||
ev.now = true; | ||
return; | ||
} | ||
|
||
void push(databox& self, mrgsolve::evdata ev) { | ||
self.push(ev); | ||
return; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
|
||
library(testthat) | ||
library(mrgsolve) | ||
library(dplyr) | ||
|
||
Sys.setenv(R_TESTS="") | ||
options("mrgsolve_mread_quiet"=TRUE) | ||
|
||
local_edition(3) | ||
|
||
code <- ' | ||
$SET end = 12, rtol = 1e-4, atol = 1e-4, delta = 0.25 | ||
$PLUGIN evtools | ||
$PARAM | ||
mode = 0, f1 = 1, dose = 100, irate = 50, newtime = 2 | ||
$CMT A B | ||
$PK | ||
F_A = f1; | ||
$DES | ||
dxdt_A = -1 * A; | ||
dxdt_B = 1 * A - 0.1 * B; | ||
$TABLE | ||
bool givedose = TIME==0; | ||
if(mode==1 && givedose) { | ||
evt::bolus(self, dose, 1); | ||
} | ||
if(mode==2 && givedose) { | ||
evt::infuse(self, dose, 1, irate); | ||
} | ||
if(mode==3 && givedose) { | ||
evt::ev ev = evt::bolus(dose, 1); | ||
evt::retime(ev, 2); | ||
evt::push(self, ev); | ||
} | ||
if(mode==4 && givedose) { | ||
evt::ev ev = evt::infuse(dose, 1, irate); | ||
evt::retime(ev, newtime); | ||
evt::push(self, ev); | ||
} | ||
if(mode==5 && givedose) { | ||
evt::bolus(self, dose, 1); | ||
evt::bolus(self, dose, 1); | ||
evt::bolus(self, dose, 1); | ||
} | ||
if(mode==6 && givedose) { | ||
evt::ev ev = evt::bolus(dose, 1); | ||
ev.time = 100; | ||
evt::now(ev); | ||
evt::push(self, ev); | ||
} | ||
' | ||
|
||
mod <- mcode("test-evtools-model-1", code) | ||
|
||
mrgsim(mod, param = list(mode = 1, f1 = 1)) | ||
|
||
test_that("evtools - bolus now", { | ||
|
||
out <- mrgsim(mod, param = list(mode = 1)) | ||
expect_equal(out$A[1], mod$dose) | ||
expect_equal(out$B[1], 0) | ||
|
||
out <- mrgsim(mod, param = list(mode = 1, f1 = 0.5)) | ||
expect_equal(out$A[1], mod$dose * param(out)$f1) | ||
expect_equal(out$B[1], 0) | ||
}) | ||
|
||
test_that("evtools - infusion now", { | ||
out <- mrgsim(mod, param = list(mode = 2)) | ||
tmax <- out$time[which.max(out$A)] | ||
expect_equal(tmax, mod$dose/mod$irate) | ||
expect_equal(out$B[1], 0) | ||
|
||
out <- mrgsim(mod, param = list(mode = 2, f1 = 0.5)) | ||
tmax <- out$time[which.max(out$A)] | ||
env <- as.list(param(out)) | ||
expect_equal(tmax, param(out)$f1 * mod$dose / mod$irate) | ||
}) | ||
|
||
test_that("evtools - bolus with retime", { | ||
out <- mrgsim(mod, param = list(mode = 3), recsort = 3) | ||
cmax <- filter_sims(out, time==2) | ||
expect_equal(nrow(cmax), 1L) | ||
expect_equal(cmax$A, mod$dose) | ||
}) | ||
|
||
test_that("evtools - infusion with retime", { | ||
out <- mrgsim(mod, param = list(mode = 4), recsort = 3) | ||
tmax <- out$time[which.max(out$A)] | ||
expect_equal(tmax, mod$newtime + mod$dose/mod$irate) | ||
expect_equal(out$B[1], 0) | ||
}) | ||
|
||
test_that("evtools - multiple bolus doses given now", { | ||
out <- mrgsim(mod, param = list(mode = 5)) | ||
expect_equal(out$A[1], 300) | ||
tmax <- out$time[which.max(out$A)] | ||
expect_equal(tmax, 0) | ||
}) | ||
|
||
test_that("evtools - give timed dose now", { | ||
a <- mrgsim(mod, param = list(mode = 6)) | ||
b <- mrgsim(mod, param = list(mode = 1)) | ||
expect_identical(as.data.frame(a), as.data.frame(b)) | ||
}) | ||
|
||
local_edition(2) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this
local_edition
call unnecessary? The file-level edition set by thelocal_edition
call on line 9 should be automatically reset.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok; I wasn't sure about the scope for the editions.