Skip to content

Fix MILP solver parameters: remove LP-tuned custom solver options - #357

Open
mokhtar-sidi wants to merge 1 commit into
TemoaProject:mainfrom
mokhtar-sidi:fix-milp-solver-parameters
Open

Fix MILP solver parameters: remove LP-tuned custom solver options#357
mokhtar-sidi wants to merge 1 commit into
TemoaProject:mainfrom
mokhtar-sidi:fix-milp-solver-parameters

Conversation

@mokhtar-sidi

@mokhtar-sidi mokhtar-sidi commented Jul 27, 2026

Copy link
Copy Markdown

Removed the custom solver options for CPLEX and Gurobi in temoa/_internal/run_actions.py. All solvers now run with their default settings.

The previous options were tuned for LPs and cause problems once the integer (MILP) extensions are activated: disabling crossover can crash MIP solves, and the loose barrier/feasibility tolerances are not appropriate for integer solves. Per the maintainers' recommendation, the safest fix is to drop these custom options and let each solver choose settings appropriate to the problem type (LP or MILP).

The previous LP-tuned values (matching mip-dev / PyPSA) are kept as an inline reference comment so advanced users can re-tune LP performance if needed, e.g. via the extensions' *_solver_options.toml files.

Summary by CodeRabbit

  • Refactor
    • Simplified solver configuration by removing automatic, solver-specific tuning options.
    • Preserved the existing solve workflow, validation, error handling, and optimal-result checks.
    • Solver behavior may now rely more on each solver’s default settings.

Removed the custom solver options for CPLEX and Gurobi in
temoa/_internal/run_actions.py. All solvers now run with their default
settings.

The previous options were tuned for LPs and cause problems once the
integer (MILP) extensions are activated: disabling crossover can crash
MIP solves, and the loose barrier/feasibility tolerances are not
appropriate for integer solves. Per the maintainers' recommendation,
the safest fix is to drop these custom options and let each solver
choose settings appropriate to the problem type (LP or MILP).

The previous LP-tuned values (matching mip-dev / PyPSA) are kept as an
inline reference comment so advanced users can re-tune LP performance if
needed, e.g. via the extensions' *_solver_options.toml files.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

solve_instance no longer assigns custom CPLEX or Gurobi options. Solver creation, validation, suffix handling, solving, error handling, and termination checks remain unchanged.

Changes

Solver configuration

Layer / File(s) Summary
Remove custom solver options
temoa/_internal/run_actions.py
Removes CPLEX and Gurobi barrier, crossover, and tolerance settings while retaining the existing solve flow.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

Suggested labels: Maintenance

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing LP-tuned custom options from MILP solver setup.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@temoa/_internal/run_actions.py`:
- Around line 223-230: Remove the no-op solver-name conditional in the action
execution flow, including the cbc, cplex, and gurobi branches and the adjacent
appsi_highs no-op branch. Delete the entire conditional scaffolding rather than
preserving solver-specific branches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: be20b822-873c-4ed5-8756-a54b30b786fe

📥 Commits

Reviewing files that changed from the base of the PR and between 4a8aa60 and 1508d35.

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

Comment on lines 223 to +230
if solver_name == 'cbc':
pass

elif solver_name == 'cplex':
# 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-3
optimizer.options['feasopt tolerance'] = 1.0e-4
pass

elif solver_name == 'gurobi':
# Note: these parameter values match mip-dev / PyPSA (see: https://pypsa-eur.readthedocs.io/en/latest/configuration.html)
optimizer.options['Method'] = 2 # barrier
optimizer.options['Crossover'] = 0 # non basic solution, ie no crossover
optimizer.options['BarConvTol'] = 1.0e-3
optimizer.options['FeasibilityTol'] = 1.0e-4
optimizer.options['BarOrder'] = -1 # auto ordering; 2-4x faster than AMD on large models
pass

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the now-dead solver configuration branches.

All branches are no-ops; remove this conditional (including the adjacent unchanged appsi_highs no-op branch) rather than retaining solver-name-specific scaffolding.

Proposed cleanup
-    if solver_name == 'cbc':
-        pass
-
-    elif solver_name == 'cplex':
-        pass
-
-    elif solver_name == 'gurobi':
-        pass
-
-    elif solver_name == 'appsi_highs':
-        pass
-
     # Suffix Handling
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if solver_name == 'cbc':
pass
elif solver_name == 'cplex':
# 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-3
optimizer.options['feasopt tolerance'] = 1.0e-4
pass
elif solver_name == 'gurobi':
# Note: these parameter values match mip-dev / PyPSA (see: https://pypsa-eur.readthedocs.io/en/latest/configuration.html)
optimizer.options['Method'] = 2 # barrier
optimizer.options['Crossover'] = 0 # non basic solution, ie no crossover
optimizer.options['BarConvTol'] = 1.0e-3
optimizer.options['FeasibilityTol'] = 1.0e-4
optimizer.options['BarOrder'] = -1 # auto ordering; 2-4x faster than AMD on large models
pass
🧰 Tools
🪛 Ruff (0.15.21)

[warning] 223-227: Combine if branches using logical or operator

Combine if branches

(SIM114)


[warning] 226-230: Combine if branches using logical or operator

Combine if branches

(SIM114)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@temoa/_internal/run_actions.py` around lines 223 - 230, Remove the no-op
solver-name conditional in the action execution flow, including the cbc, cplex,
and gurobi branches and the adjacent appsi_highs no-op branch. Delete the entire
conditional scaffolding rather than preserving solver-specific branches.

Source: Linters/SAST tools

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.

1 participant