Open-Systems-Pharmacology / OSPSuite.ParameterIdentification

R package for parameter identification for OSPS models
http://www.open-systems-pharmacology.org/OSPSuite.ParameterIdentification/
GNU General Public License v2.0
3 stars 1 forks source link

Break if first iteration produces NaN for error #35

Open PavelBal opened 1 year ago

PavelBal commented 1 year ago

If the very first iteration produces a NaN, stop the PI. Otherwise, the PI can run forever.

PavelBal commented 8 months ago

Write a test to check if this is still the case.

rengelke commented 8 months ago
  1. Simulation level: .handleSimulationFailure and .createErrorCostStructure which should return infinite model costs if simulation returns NA in commit 07dd891f. Difficult to test without a reproducible example here.
  2. Objective function level: will return infinite model costs if results is NA (86191e45)
PavelBal commented 7 months ago

Here how to test:

test_that("First iteration produces NaN", {
  simulation <- loadSimulation(system.file("extdata", "Aciclovir.pkml", package = "ospsuite"))

  # Define optimization para,eter
  parameterPath <- c("Aciclovir|Lipophilicity")
  modelParam <- ospsuite::getParameter(path = parameterPath, container = simulation)
  piParameter <- PIParameters$new(parameters = modelParam)

  # Load data and create output mapping
  filePath <- testthat::test_path("../data/AciclovirLaskinData.xlsx")
  dataConfiguration <- createImporterConfigurationForFile(filePath = filePath)
  dataConfiguration$sheets <- "Laskin 1982.Group A"
  dataConfiguration$namingPattern <- "{Source}.{Sheet}"
  observedData <- loadDataSetsFromExcel(
    xlsFilePath = filePath,
    importerConfigurationOrPath = dataConfiguration
  )

  outputMapping <- PIOutputMapping$new(
    quantity = getQuantity("Organism|PeripheralVenousBlood|Aciclovir|Plasma (Peripheral Venous Blood)",
                           container = simulation
    )
  )
  outputMapping$addObservedDataSets(observedData$`AciclovirLaskinData.Laskin 1982.Group A`)

  # Set solver tolerance to a high value so the simulation will definitely fail
  simulation$solver$mxStep <- 1
  # Create PI Task
  piTask <- ParameterIdentification$new(
    simulations = simulation,
    parameters = piParameter,
    outputMappings = outputMapping
  )

  piTask$run()
})

Setting this:

simulation$solver$mxStep <- 1

ensures that simulation fails.

But it seems that the optimization stops already, so all good?