You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reported downstream as nlmixr2/nlmixr2#408 ("Error building model - food effect not running?").
Summary
.rxEventSensCExpr() (R/eventSens.R) only collects THETA[n]/ETA[n] tokens from the first element of its (vectorized) expr argument. Any index that appears solely in a later element is never rewritten to the codegen local _THETA_n_/_ETA_n_, so raw symengine array syntax leaks into the generated C and the model fails to compile:
error: 'ETA' undeclared (first use in this function)
error: 'THETA' undeclared (first use in this function)
This is a real codegen bug — it reproduces on Linux with a perfectly good toolchain. The reporter in #408 was sent down an Rtools rabbit hole because of the diagnostic wording (filed separately).
expr is a character vector — one entry per event-sensitivity assignment line — but [[1]] keeps only the matches from element 1. gsub() then substitutes those tokens across all elements, so whatever happens to appear first is translated and the rest silently survive as ETA[n]/THETA[n].
Minimal demonstration against the installed function:
Needs a model where a dosing event modifier (dur(), f(), ...) depends on two or more distinct etas, so that .rxEventSensCLines() emits more than one assignment line for the same buffer:
same expression used only in the ODE / cp (no event modifier)
OK
single-eta dur() / f() / lag()
OK
So it requires at least two distinct etas contributing separate lines to the same event-sensitivity buffer. The some etas defaulted to non-mu referenced warning that accompanies these models is a red herring — mu-referencing both branches on simple lines yields byte-identical C and fails the same way.
Workaround (for reference)
Restructuring so every emitted line contains all the indices avoids it, e.g. folding the branches inside a single exp():
A test asserting that generated event-sensitivity C contains no bare ETA[/THETA[ would cover this directly, plus a unit test on .rxEventSensCExpr() with a length-2 input.
Reported downstream as nlmixr2/nlmixr2#408 ("Error building model - food effect not running?").
Summary
.rxEventSensCExpr()(R/eventSens.R) only collectsTHETA[n]/ETA[n]tokens from the first element of its (vectorized)exprargument. Any index that appears solely in a later element is never rewritten to the codegen local_THETA_n_/_ETA_n_, so raw symengine array syntax leaks into the generated C and the model fails to compile:This is a real codegen bug — it reproduces on Linux with a perfectly good toolchain. The reporter in #408 was sent down an Rtools rabbit hole because of the diagnostic wording (filed separately).
Root cause
R/eventSens.R:806:expris a character vector — one entry per event-sensitivity assignment line — but[[1]]keeps only the matches from element 1.gsub()then substitutes those tokens across all elements, so whatever happens to appear first is translated and the rest silently survive asETA[n]/THETA[n].Minimal demonstration against the installed function:
Resulting generated C (from
rxode2::rxLastCompile()$c):Suggested fix
Collect tokens across every element:
Verified this produces the correct output for the vector above:
Reproducible example
Needs a model where a dosing event modifier (
dur(),f(), ...) depends on two or more distinct etas, so that.rxEventSensCLines()emits more than one assignment line for the same buffer:Scope
Narrowed by variant testing:
dur()f()cp(no event modifier)dur()/f()/lag()So it requires at least two distinct etas contributing separate lines to the same event-sensitivity buffer. The
some etas defaulted to non-mu referencedwarning that accompanies these models is a red herring — mu-referencing both branches on simple lines yields byte-identical C and fails the same way.Workaround (for reference)
Restructuring so every emitted line contains all the indices avoids it, e.g. folding the branches inside a single
exp():This is algebraically identical when the indicators are mutually exclusive, and it compiles and fits.
Environment
Regression test suggestion
A test asserting that generated event-sensitivity C contains no bare
ETA[/THETA[would cover this directly, plus a unit test on.rxEventSensCExpr()with a length-2 input.