Tune solver tolerances and barrier ordering#273
Tune solver tolerances and barrier ordering#273ParticularlyPythonicBS merged 2 commits intoTemoaProject:unstablefrom
Conversation
WalkthroughAdjusted numerical tolerance parameters for CPLEX and Gurobi solvers in the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment 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 |
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.
ffa76f1 to
7f7c1d0
Compare
| 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 |
There was a problem hiding this comment.
🧩 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:
- 1: https://can-pypsa-eur.readthedocs.io/en/latest/configuration.html
- 2: https://pypsa-eur.readthedocs.io/en/latest/configuration.html
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.
6284a38
into
TemoaProject:unstable
Summary
Two solver configuration changes that improve performance on large-scale models:
Files changed
temoa/_internal/run_actions.pyTest plan
Summary by CodeRabbit