-
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
Add $EVENT block #1230
Add $EVENT block #1230
Changes from 6 commits
30ed899
e6968f4
50eabb3
8e83538
ba67c9e
665def8
6ea4d71
ce6bc9c
017b67a
b8de0f2
7a29e1a
59935fb
f900793
aae568a
efbbf4e
e78c79c
da42b01
99160c9
78da749
e49ddd7
3614e1e
4dc7cad
9eeed73
9f4637d
5dc2327
1d02ff2
78341f5
3f41e40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,7 @@ param_re_find <- "\\bparam\\s+\\w+\\s*=" | |
# please-deprecate | ||
move_global <- function(x,env) { | ||
|
||
what <- intersect(c("PREAMBLE","MAIN", "ODE", "TABLE", "PRED"),names(x)) | ||
what <- intersect(c("PREAMBLE","MAIN", "ODE", "TABLE", "EVENT", "PRED"),names(x)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this, but it's not in use any more (see comment). I'd rather get rid of it at this point, but it may or may not be in scope of this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking a quick look at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. |
||
|
||
if(length(what)==0) return(x) | ||
|
||
|
@@ -495,12 +495,17 @@ move_global2 <- function(spec, env, build) { | |
if(!is.null(table$code)) { | ||
spec$TABLE <- table$code | ||
} | ||
event <- c_vars(spec[["EVENT"]], context = "event") | ||
if(!is.null(event$code)) { | ||
spec$EVENT <- event$code | ||
} | ||
to_ns <- bind_rows( | ||
pream$vars, | ||
pred$vars, | ||
main$vars, | ||
ode$vars, | ||
table$vars | ||
table$vars, | ||
event$vars | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this is happening in the new version ( |
||
vars <- bind_rows(glob$vars, to_ns) | ||
if(any(cap <- to_ns$type=="capture")) { | ||
|
@@ -536,7 +541,7 @@ move_global2 <- function(spec, env, build) { | |
} | ||
|
||
find_cpp_dot <- function(spec, env) { | ||
to_check <- c("PREAMBLE", "MAIN", "PRED", "ODE", "TABLE", "GLOBAL") | ||
to_check <- c("PREAMBLE", "MAIN", "PRED", "ODE", "EVENT", "TABLE", "GLOBAL") | ||
x <- spec[names(spec) %in% to_check] | ||
x <- unlist(x, use.names = FALSE) | ||
# Narrow the search first; 10x speed up when searching for `pattern` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,7 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
ode_func(x), | ||
main_func(x), | ||
table_func(x), | ||
event_func(x), | ||
config_func(x), | ||
model = model(x), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added argument names for safety ... was getting called by position before. |
||
omats = omat(x), | ||
|
@@ -461,6 +462,7 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
x@shlib[["nm_import"]] <- mread.env[["nm_import"]] | ||
x@shlib[["source"]] <- file.path(build[["soloc"]],build[["compfile"]]) | ||
x@shlib[["md5"]] <- build[["md5"]] | ||
x@shlib[["call_event"]] <- "EVENT" %in% names(spec) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will pass this into the C+ simulation code to tell if we are using |
||
|
||
# build---- | ||
# In soloc directory | ||
|
@@ -536,6 +538,10 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
dbs[["ode"]], | ||
spec[["ODE"]], | ||
"__END_ode__", | ||
"\n// MODELED EVENTS:", | ||
"__BEGIN_event__", | ||
spec[["EVENT"]], | ||
"__END_event__", | ||
"\n// TABLE CODE BLOCK:", | ||
"__BEGIN_table__", | ||
dbs[["cmt"]], | ||
|
@@ -595,6 +601,8 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
|
||
x <- compiled(x,TRUE) | ||
|
||
x <- setpointers(x) | ||
|
||
return(x) | ||
} | ||
|
||
|
@@ -636,7 +644,7 @@ mread_cache <- function(model = NULL, | |
|
||
if(all(t0,t1,t2,t3,t4,te)) { | ||
if(!quiet) message("Loading model from cache.") | ||
loadso(x) | ||
x <- loadso(x) | ||
return(update(x,...,strict=FALSE)) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,4 +140,8 @@ typedef std::vector<double> dvec; | |
#define MRGSOLVE_CONFIG_SIGNATURE databox& self, const dvec& _THETA_, const double neq, const double npar | ||
#define MRGSOLVE_CONFIG_SIGNATURE_N 4 | ||
|
||
//! signature for <code>$EVENT</code> | ||
#define MRGSOLVE_EVENT_SIGNATURE const dvec& _A_, const dvec& _A_0_, dvec& _THETA_, const dvec& _F_, const dvec& _R_, databox& self, const dvec& _pred_, dvec& _capture_, mrgsolve::resim& simeps | ||
#define MRGSOLVE_EVENT_SIGNATURE_N 9 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is important; I'm having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could re-use that signature macro to emphasize this (e.g. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I like the idea of sharing for this reason, and I think the confusion could be made less likely by the combination of 1) putting in a code comment and 2) moving the macros next to each other. Another idea: what about renaming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I moved the macros next to each other and noted they are the same. I ended up copying the TABLE macro into the EVENT macro. So they will have different names in the code, but guaranteed to be in sync. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to send this off to winbuilder just to make sure the macros are behaving as I think they will on gcc. If that comes back ok, will merge. |
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ Rcpp::List DEVTRAN(const Rcpp::List parin, | |
const bool tad = Rcpp::as<bool> (parin["tad"]); | ||
const bool nocb = Rcpp::as<bool> (parin["nocb"]); | ||
bool obsaug = Rcpp::as<bool> (parin["obsaug"] ); | ||
bool call_event = Rcpp::as<bool> (parin["call_event"]); | ||
obsaug = obsaug & (data.nrow() > 0); | ||
|
||
// Grab items from the model object -------------------- | ||
|
@@ -615,8 +616,12 @@ Rcpp::List DEVTRAN(const Rcpp::List parin, | |
} | ||
} | ||
|
||
if(!this_rec->is_lagged()) { | ||
prob.table_call(); | ||
if(call_event) { | ||
prob.event_call(); | ||
} else { | ||
if(!this_rec->is_lagged()) { | ||
prob.table_call(); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the first work around to maintain event code in |
||
|
||
if(prob.any_mtime()) { | ||
|
@@ -716,7 +721,11 @@ Rcpp::List DEVTRAN(const Rcpp::List parin, | |
used_mtimehx = mtimehx.size() > 0; | ||
prob.clear_mtime(); | ||
} // Close handling of modeled events | ||
|
||
|
||
if(call_event && !this_rec->is_lagged()) { | ||
prob.table_call(); | ||
} | ||
|
||
if(this_rec->output()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second bit of "workaround" code to maintain event creation in both |
||
ans(crow,0) = id; | ||
ans(crow,1) = tto; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ dxdt_CENT = KAi*GUT - (CLi/VCi)*CENT; | |
dxdt_RESP = KIN*(1-INH) - KOUTi*RESP; | ||
__END_ode__ | ||
|
||
// MODELED EVENTS: | ||
__BEGIN_event__ | ||
__END_event__ | ||
|
||
// TABLE CODE BLOCK: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was programmatically generaged; every model will have this in the source going fowward. |
||
__BEGIN_table__ | ||
DV = CP*exp(EXPO); | ||
|
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.
We've saved a logical value indicating of
$EVENT
is in the model; if so, tell whether or not to call.