Skip to content

Tune solver tolerances and barrier ordering#273

Merged
ParticularlyPythonicBS merged 2 commits intoTemoaProject:unstablefrom
SutubraResearch:pr/solver-tuning
Mar 20, 2026
Merged

Tune solver tolerances and barrier ordering#273
ParticularlyPythonicBS merged 2 commits intoTemoaProject:unstablefrom
SutubraResearch:pr/solver-tuning

Conversation

@SutubraResearch
Copy link
Collaborator

@SutubraResearch SutubraResearch commented Mar 11, 2026

Summary

Two solver configuration changes that improve performance on large-scale models:

  • Solver tolerances: Relax barrier convergence tolerance from 1e-5 to 1e-3 and feasibility tolerance from 1e-6 to 1e-4 for both Gurobi and CPLEX. These values are standard for large-scale energy system models and match the tolerances used in mip-dev and PyPSA. Tighter tolerances cause unnecessary barrier iterations without meaningful solution improvement.
  • BarOrder auto: Change Gurobi BarOrder from 0 (AMD) to -1 (automatic). Automatic ordering selects the best fill-reducing strategy per problem structure, yielding 2-4x speedup on national-scale barrier solves (268s vs 1029s on a 26-region test case).

Files changed

File Change
temoa/_internal/run_actions.py Tolerance values + BarOrder setting

Test plan

  • All 190 tests pass
  • No functional change to model results (solver parameters only)
  • Verified on 26-region national model: 2-4x barrier speedup from BarOrder alone

Summary by CodeRabbit

  • Chores
    • Updated solver configuration settings for CPLEX and Gurobi optimization engines. Adjusted numerical tolerance and convergence parameters to refine how solvers handle precision and stability during computations. Implemented a new solver ordering configuration for Gurobi supporting automatic ordering functionality in optimization processes.

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

Walkthrough

Adjusted numerical tolerance parameters for CPLEX and Gurobi solvers in the solve_instance function. Relaxed convergence and feasibility tolerances from stricter values to 1.0e-3 and 1.0e-4 respectively. Added auto-ordering configuration for Gurobi's barrier method.

Changes

Cohort / File(s) Summary
Solver Configuration Tuning
temoa/_internal/run_actions.py
Modified CPLEX and Gurobi tolerance parameters in solve_instance, relaxing barrier convergence and feasibility tolerances from 1.0e-5/1.0e-6 to 1.0e-3/1.0e-4. Added Gurobi BarOrder=-1 for automatic ordering. Updated comments to reference mip-dev / PyPSA alignment.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

enhancement, Maintenance

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: tuning solver tolerances and adjusting barrier ordering parameters.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Tip

CodeRabbit can use your project's `ruff` configuration to improve the quality of Python code reviews.

Add a Ruff configuration file to your project to customize how CodeRabbit runs ruff.

Relax barrier convergence tolerance from 1e-5 to 1e-3 and
feasibility tolerance from 1e-6 to 1e-4 for both Gurobi and
CPLEX. These values align with mip-dev defaults and are
standard for large-scale energy system models where tighter
tolerances cause unnecessary barrier iterations without
meaningful solution improvement.
Change BarOrder from 0 (AMD) to -1 (automatic) for barrier
solves. Automatic ordering selects the best fill-reducing
strategy per problem structure, yielding 2-4x speedup on
national-scale energy system models (268s vs 1029s on a
26-region test case). AMD ordering is suboptimal for the
sparse constraint structure typical of Temoa models.
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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8051a0c8-5a6b-4baa-85e0-f497ee259910

📥 Commits

Reviewing files that changed from the base of the PR and between 514a7fe and 7f7c1d0.

📒 Files selected for processing (1)
  • temoa/_internal/run_actions.py

Comment on lines 208 to +214
elif solver_name == 'cplex':
# Note: these parameter values are taken to be the same as those in PyPSA
# Note: these parameter values match mip-dev / PyPSA
# (see: https://pypsa-eur.readthedocs.io/en/latest/configuration.html)
optimizer.options['lpmethod'] = 4 # barrier
optimizer.options['solutiontype'] = 2 # non basic solution, ie no crossover
optimizer.options['barrier convergetol'] = 1.0e-5
optimizer.options['feasopt tolerance'] = 1.0e-6
optimizer.options['barrier convergetol'] = 1.0e-3
optimizer.options['feasopt tolerance'] = 1.0e-4
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

What are the default solver tolerances for CPLEX barrier in PyPSA-EUR?

💡 Result:

The default solver tolerances for CPLEX barrier in PyPSA-EUR are configured as follows in the project's documentation (e.g., can-pypsa-eur configuration examples): - barrier_convergetol: 1.e-5 - feasopt_tolerance: 1.e-6 These are specified under the cplex-default solver options for the barrier algorithm (lpmethod: 4). PyPSA-EUR inherits solver configurations from PyPSA, where tolerances can also be customized via options, but the project defaults match CPLEX's barrier convergence tolerance (BarConVTol) and feasibility tolerance (FeasOptTol) as shown. No stricter or different defaults were found in the main PyPSA-EUR config.default.yaml references; users override via config.yaml if needed. CPLEX default without specification is typically 1e-6 for complementarity tolerance, but PyPSA-EUR sets 1e-5 for convergence.

Citations:


Code comment claim contradicted: tolerances are 100x looser than PyPSA-EUR defaults.

The comment states these parameter values "match mip-dev / PyPSA," but PyPSA-EUR documentation specifies:

  • barrier_convergetol: 1e-5 (not 1e-3)
  • feasopt_tolerance: 1e-6 (not 1e-4)

The code sets tolerances 100x looser than the referenced standard without justification. This compounds the existing tolerance mismatch with tests (which use 1e-5 to 1e-6 precision), making solutions fragile to solver version updates or edge cases. Correct the code comment or provide rationale for the significant tolerance relaxation. If looser tolerances are intentional, update test assertions accordingly to prevent spurious failures as solvers evolve.

@ParticularlyPythonicBS ParticularlyPythonicBS merged commit 6284a38 into TemoaProject:unstable Mar 20, 2026
12 checks passed
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.

2 participants