Open-Systems-Pharmacology / OSPSuite.SimModel

Calculation engine for models built with PK-Sim® or MoBi®
Other
4 stars 3 forks source link

SensitivityAnalysis does not produce any results in certain cases #146

Closed PavelBal closed 2 years ago

PavelBal commented 2 years ago

I cannot share the project, so I will send you the simulation when you can start working on it.

1) Load simulation in MoBi 2) Start sensitivity analysis 3) Select "Bone - Volume" as parameter and run

image

Results are generated: image

4) Select "Stomach - Volume" as parameter and run - NO results available:

image

The reason is that SimulationBatch with variable Stomach|Volume parameter produces results for 0 individuals, example from R. I load the simulation, create simulation batch from it with Stomach|Volume as variable and run with the initial value:

simulation <- loadSimulation("XXX.pkml", loadFromCache = FALSE )
parameterPath <-"Organism|Stomach|Volume"

param <- getParameter(parameterPath, simulation)
initialValue <- param$value

simBatch <- createSimulationBatch(
  simulation = simulation,
  parametersOrPaths = parameterPath
)
simBatch$addRunValues(parameterValues = initialValue)

res <- runSimulationBatches(simBatch, silentMode = FALSE)

## Number of simlated individuals 0???
> res
[[1]]
[[1]]$`e137dd6c-bdf5-4b45-b14d-f244cdf0ed60`
SimulationResults: 
   Number of individuals: 0 

What does it actually mean that the number of individuals in the results is 0? I would expect a solver error or at least warning when the simulation cannot be simulated.

Running the simulation as is (i.e., with the same initial values) works:

> resFromSim <- runSimulation(simulation)
> resFromSim
SimulationResults: 
   Number of individuals: 1 
abdelr commented 2 years ago

I have investigated this a bit but will not be able to solve the issue. Instead, I write some comments for the next developer. Indeed, when running the simulation there are results. In contrast, when using the batch runner there is non since there is one internal error claiming "Initial value of Birds_RR|Organism|EndogenousIgG|Plasma|FcRn was not set". The interesting question here is why the difference between running with one, or the other implementation. I checked and both ways serializes the simulation the same way so basically, they both run exactly the same simulation. I wrote a test on the SimModel which loads this serialized simulation, finalize it and run it and it fails with the same error so when running the simulation there is some initialization of the parameters which is carried on and this has to be missing when running the batch but I did not get that far. I hope this could useful for the next developer.

Yuri05 commented 2 years ago

@abdelr Can you send me the simulation and your test? @PavelBal Same question to you for the original project.

PavelBal commented 2 years ago

As a separate issue - the error is now not propagated and the user does not see that the simulation failed.

Yuri05 commented 2 years ago

As a separate issue - the error is now not propagated and the user does not see that the simulation failed.

Let's open a separate issue then for that ;)

abdelr commented 2 years ago

I have pushed the test now into SimModel, branch 1665_SensitivityAnalysis. It will fail now since you would need the xml file. I could send it by mail but keep in mind it should not go public. With the xml file it will fail when running the simulation.

On Fri, Jul 22, 2022 at 12:12 PM Juri Solodenko @.***> wrote:

As a separate issue - the error is now not propagated and the user does not see that the simulation failed.

Let's open a separate issue then for that ;)

— Reply to this email directly, view it on GitHub https://github.com/Open-Systems-Pharmacology/OSPSuite.SimModel/issues/146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2HMS4PI5H7FCTMWLVJ5DTVVJX2JANCNFSM53375COQ . You are receiving this because you were mentioned.Message ID: @.*** com>

Yuri05 commented 2 years ago

yes, send me the xml please

Yuri05 commented 2 years ago

So apart from the modeling problem: it is indeed a bug in SimModel. Parsing of formulas containing e,g, "Inf" or "NaN" is wrong in some cases. In this particular case: having the formula A*(B/0)^(-C) without parameter variation, the formula was immediately evaluated as 0. With the variation of B: formula is transformed into const*(B*inf)^const first and then parsed, and here due to the bug "inf" was parsed as 0, so the formula is evaluated to infinity during the calculation. Can be easily reproduced (s. the example project NaN_Inf_NegInf.zip)

Just pushed a PR which fixes this.

PavelBal commented 2 years ago

Awesome, thank you! :)