Skip to content
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 new argument stateVariableParamsOrPaths to the function createSimulationBatch #1400

Open
PavelBal opened this issue Apr 24, 2024 · 4 comments

Comments

@PavelBal
Copy link
Member

Add a new argument stateVariableParams to the function, so createSimulationBatch(simulation, parametersOrPaths = NULL, stateVariableParamsOrPaths = NULL, moleculesOrPaths = NULL).

@PavelBal
Copy link
Member Author

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)

@PavelBal
Copy link
Member Author

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.

@Yuri05
Copy link
Member

Yuri05 commented Apr 24, 2024

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

createSimulationBatch <- function(simulation, parametersOrPaths = NULL, moleculesOrPaths = NULL) {
validateIsOfType(simulation, "Simulation")
validateIsOfType(parametersOrPaths, c("Parameter", "character"), nullAllowed = TRUE)
validateIsOfType(moleculesOrPaths, c("Molecule", "character"), nullAllowed = TRUE)
if (length(parametersOrPaths) == 0 && length(moleculesOrPaths) == 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, "Molecule")) {
variableMolecules <- unlist(lapply(variableMolecules, function(x) x$path), use.names = FALSE)
}
simulationBatchOptions <- SimulationBatchOptions$new(
variableParameters = variableParameters,
variableMolecules = variableMolecules
)
net <- rClr::clrNew("OSPSuite.R.Domain.ConcurrentRunSimulationBatch", simulation$ref, simulationBatchOptions$ref)
SimulationBatch$new(net, simulation)
}

@PavelBal
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants