Open PavelBal opened 7 months ago
createSimulationBatch <- function(simulation, parametersOrPaths = NULL, moleculesOrPaths = NULL,
stateVariableParametersOrPaths = NULL) {
validateIsOfType(simulation, "Simulation")
validateIsOfType(parametersOrPaths, c("Parameter", "character"), nullAllowed = TRUE)
validateIsOfType(stateVariableParametersOrPaths, c("Parameter", "character"), nullAllowed = TRUE)
validateIsOfType(moleculesOrPaths, c("Molecule", "character"), nullAllowed = TRUE)
if ((length(parametersOrPaths) + length(moleculesOrPaths) + length(stateVariableParametersOrPaths)) == 0) {
stop(messages$errorSimulationBatchNothingToVary)
}
variableParameters <- c(parametersOrPaths)
if (isOfType(variableParameters, "Parameter")) {
variableParameters <- unlist(lapply(variableParameters, function(x) x$path), use.names = FALSE)
}
variableMolecules <- c(moleculesOrPaths)
if (isOfType(variableMolecules, "Quantity")) {
variableMolecules <- unlist(lapply(variableMolecules, function(x) x$path), use.names = FALSE)
}
# Add state variable parameters to the molecules list as internally such parameters
# are treated as molecules
if (isOfType(stateVariableParametersOrPaths, "Parameter")) {
variableMolecules <- c(variableMolecules, unlist(lapply(stateVariableParametersOrPaths, function(x) x$path), use.names = FALSE))
} else {
variableMolecules <- c(variableMolecules, stateVariableParametersOrPaths)
}
Documentation:
#' @param stateVariableParametersOrPaths Parameter instances (element or vector)
#' typically retrieved using `getAllParametersMatching` or parameter path (element or vector of strings)
#' of parameters that are defined by an ODE that will be varied in the simulation. (optional)
I realized this is not that straightforward. SimulationBatch$addRunValues() supports adding values for parameters and initial values of molecules, and RHS params should be in the molecules list. If we want to extend the createSimulationBatch function by the argument for state variable parameters, addRunValues should support this too, but this is implemented in .NET. IMO too much overhead for now.
I wonder if we need this extension or rather it should be handled internally.
E.g. the createSimulationBatch
function could check for every parameter (path) if the corresponding parameter has an RHS or not. If yes: insert parameter path into variableMolecules
and not into variableParameters
.
Then no interface modification is required and no changes in the OSPSuite.Core
https://github.com/Open-Systems-Pharmacology/OSPSuite-R/blob/03e8f5aed10f1a783b0fdc1621d03f6e6c416248/R/utilities-simulation.R#L338-L366
Doable... Then we would have to track the idx of parameters that are ODE based to add the initial values of those parameters to the molecules IC list... Sounds error-prone.
Add a new argument
stateVariableParams
to the function, socreateSimulationBatch(simulation, parametersOrPaths = NULL, stateVariableParamsOrPaths = NULL, moleculesOrPaths = NULL)
.