Skip to content

#1717 autoreducetolerance#2773

Open
benjaperez1983 wants to merge 5 commits intodevelopfrom
1717-allow-enabling-autoreducetolerances-in-ospsuiterdomainsimulationrunoptions-fix
Open

#1717 autoreducetolerance#2773
benjaperez1983 wants to merge 5 commits intodevelopfrom
1717-allow-enabling-autoreducetolerances-in-ospsuiterdomainsimulationrunoptions-fix

Conversation

@benjaperez1983
Copy link
Contributor

@benjaperez1983 benjaperez1983 commented Feb 23, 2026

Fixes #1717

Description

Allow auto reduce tolerance

Type of change

Please mark relevant options with an x in the brackets.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires documentation changes (link at least one user or developer documentation issue):
  • Algorithm update - updates algorithm documentation/questions/answers etc.
  • Other (please describe):

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Integration tests
  • Unit tests
  • Manual tests
  • No tests required

Reviewer checklist

Mark everything that needs to be checked before merging the PR.

  • Check if the code is well documented
  • Check if the behavior is what is expected
  • Check if the code is well tested
  • Check if the code is readable and well formatted
  • Additional checks (document below if any)
  • Check if documentation update issue(s) are created if the option This change requires a documentation update above is selected

Screenshots (if appropriate):

Questions (if appropriate):

Summary by CodeRabbit

  • New Features

    • Automatic tolerance reduction for failed simulations: a new run option enables the solver to automatically relax tolerances when a simulation fails (enabled by default), improving robustness and success rates.
  • Tests

    • Added tests ensuring the automatic tolerance reduction option is present by default and correctly propagates through simulation configuration.

@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9dfd425 and c670477.

📒 Files selected for processing (4)
  • src/OSPSuite.Core/Domain/SimulationRunOptions.cs
  • src/OSPSuite.R/Domain/SimulationBatch.cs
  • src/OSPSuite.R/Domain/SimulationRunOptions.cs
  • tests/OSPSuite.Core.Tests/Domain/SimulationRunOptionsSpecs.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/OSPSuite.R/Domain/SimulationBatch.cs

📝 Walkthrough

Walkthrough

Adds a new boolean AutoReduceTolerances option across the simulation stack (Core and R), propagating the setting from SimulationRunOptions through SimulationRunner/SimModelManager and SimModelBatch into the created Simulation; defaults are enabled.

Changes

Cohort / File(s) Summary
Core interface & implementation
src/OSPSuite.Core/Domain/Services/ISimModelBatch.cs, src/OSPSuite.Core/Domain/Services/SimModelBatch.cs
Adds bool AutoReduceTolerances { get; set; } to the ISimModelBatch contract and implements it in SimModelBatch; propagated into created Simulation (x.AutoReduceTolerances = AutoReduceTolerances).
Core run options & manager
src/OSPSuite.Core/Domain/SimulationRunOptions.cs, src/OSPSuite.Core/Domain/Services/SimModelManager.cs
Adds AutoReduceTolerances property to SimulationRunOptions (default true) and passes _simulationRunOptions.AutoReduceTolerances into simulation execution options in SimModelManager.
R integration
src/OSPSuite.R/Domain/SimulationRunOptions.cs, src/OSPSuite.R/Services/SimulationRunner.cs, src/OSPSuite.R/Domain/SimulationBatch.cs
Adds AutoReduceTolerances to R-side SimulationRunOptions (XML doc, default true); maps R option into Core options in SimulationRunner; initializes _simModelBatch.AutoReduceTolerances from provided options in SimulationBatch.Initialize.
Tests
tests/OSPSuite.Core.IntegrationTests/SimModelBatchSpecs.cs, tests/OSPSuite.Core.Tests/Domain/SimulationRunOptionsSpecs.cs
Adds integration tests verifying AutoReduceTolerances propagation to simulation options; adds unit tests asserting default values (CheckForNegativeValues = true, AutoReduceTolerances = true).

Sequence Diagram(s)

sequenceDiagram
    participant R as "R caller"
    participant Runner as "SimulationRunner / SimModelManager"
    participant Batch as "SimModelBatch"
    participant Simulation as "Simulation"

    R->>Runner: provide SimulationRunOptions (AutoReduceTolerances=true)
    Runner->>Batch: Create/Initialize batch (set AutoReduceTolerances)
    Batch->>Simulation: Create Simulation with Options (AutoReduceTolerances set)
    Simulation-->>Runner: Run result (uses AutoReduceTolerances when handling failures)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I tweak a flag, so tolerances may fall,
When runs stumble, I nudge — hopping on the call.
From R to Core, through batches I steer,
A tiny rabbit fix — to make failures clear. 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and uses non-descriptive terms like shorthand references without context, failing to clearly summarize the main change. Use a more descriptive title like 'Add AutoReduceTolerances property to SimModel batch and simulation run options' to clearly convey the main feature being added.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request successfully implements the AutoReduceTolerances feature across all necessary layers as required by issue #1717.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the AutoReduceTolerances feature with corresponding test coverage; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 1717-allow-enabling-autoreducetolerances-in-ospsuiterdomainsimulationrunoptions-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/OSPSuite.R/Services/SimulationRunner.cs (1)

85-108: ⚠️ Potential issue | 🟠 Major

The population runner does not propagate AutoReduceTolerances to individual simulations.

The population path (lines 96–101) passes the R-domain SimulationRunOptions to _populationRunner.RunPopulationAsync, which receives it as a RunOptions parameter. However, PopulationRunner only extracts NumberOfCoresToUse from the options and creates individual simulations via CreateSimulation(simulationExport) without passing any configuration action. This means AutoReduceTolerances is never applied to the SimModel options for population runs, unlike the individual simulation path (line 120) which explicitly sets it via SimModelManager.simulate().

To fix this, PopulationRunner.RunPopulationAsync needs to accept SimulationRunOptions instead of the base RunOptions type, and pass a configuration action to CreateSimulation that sets AutoReduceTolerances and CheckForNegativeValues on the simulation options (similar to how SimModelManager.simulate() does at lines 98–99).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/OSPSuite.R/Services/SimulationRunner.cs` around lines 85 - 108, The
population path currently calls _populationRunner.RunPopulationAsync with a
SimulationRunOptions but PopulationRunner only accepts RunOptions and doesn't
forward AutoReduceTolerances/CheckForNegativeValues to individual simulations;
change PopulationRunner.RunPopulationAsync to accept SimulationRunOptions (not
RunOptions) and update its internal CreateSimulation calls to pass a
configuration action that sets sim.Options.AutoReduceTolerances and
sim.Options.CheckForNegativeValues from the incoming SimulationRunOptions
(mirroring how SimModelManager.simulate applies these) so population-run
individual simulations receive the same tolerance/negative-value settings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/OSPSuite.R/Services/SimulationRunner.cs`:
- Around line 85-108: The population path currently calls
_populationRunner.RunPopulationAsync with a SimulationRunOptions but
PopulationRunner only accepts RunOptions and doesn't forward
AutoReduceTolerances/CheckForNegativeValues to individual simulations; change
PopulationRunner.RunPopulationAsync to accept SimulationRunOptions (not
RunOptions) and update its internal CreateSimulation calls to pass a
configuration action that sets sim.Options.AutoReduceTolerances and
sim.Options.CheckForNegativeValues from the incoming SimulationRunOptions
(mirroring how SimModelManager.simulate applies these) so population-run
individual simulations receive the same tolerance/negative-value settings.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db6ece2 and 9dfd425.

📒 Files selected for processing (9)
  • src/OSPSuite.Core/Domain/Services/ISimModelBatch.cs
  • src/OSPSuite.Core/Domain/Services/SimModelBatch.cs
  • src/OSPSuite.Core/Domain/Services/SimModelManager.cs
  • src/OSPSuite.Core/Domain/SimulationRunOptions.cs
  • src/OSPSuite.R/Domain/SimulationBatch.cs
  • src/OSPSuite.R/Domain/SimulationRunOptions.cs
  • src/OSPSuite.R/Services/SimulationRunner.cs
  • tests/OSPSuite.Core.IntegrationTests/SimModelBatchSpecs.cs
  • tests/OSPSuite.Core.Tests/Domain/SimulationRunOptionsSpecs.cs

public void Initialize(IModelCoreSimulation simulation, SimulationBatchOptions simulationBatchOptions, SimulationRunOptions simulationRunOptions)
{
_simModelBatch.CheckForNegativeValues = simulationRunOptions?.CheckForNegativeValues ?? true;
_simModelBatch.AutoReduceTolerances = simulationRunOptions?.AutoReduceTolerances ?? false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default setting in SimModel is AutoReduceTolerances = true
https://github.com/Open-Systems-Pharmacology/OSPSuite.SimModel/blob/8071fcbb06efe6075b215489c94b6a9228d29f4a/src/OSPSuite.SimModelNative/src/SimulationOptions.cpp#L14C3-L14C23

If the AutoReduceTolerances setting was not modified by OSPSuite.Core till now, then the default is changed to false here for the case simulationRunOptions=null.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not know about the default sorry, will change it right away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to say. Is this the right default?

/// <summary>
/// Specifies whether the solver should automatically reduce tolerances when a simulation run fails. Default is <c>false</c>
/// </summary>
public bool AutoReduceTolerances { get; set; } = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unify syntax please. Should be true by default in code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could, but as I can see the other values are set on the constructor instead, I was responsible for the last 2:

public SimulationRunOptions()
{
SimModelExportMode = SimModelExportMode.Full;
CheckForNegativeValues = true;
AutoReduceTolerances = true;
}

But the first has been there before, shallI I completely get rid of the constructor here then and set the 3 properties by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@msevestre msevestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be set to true and not to false as defau;t

@benjaperez1983
Copy link
Contributor Author

@msevestre can you please re-review?
Thanks!

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

Successfully merging this pull request may close these issues.

Allow enabling AutoReduceTolerances in SimModel

3 participants