Skip to content

Runner: run_solver.py update with knitro#410

Merged
finozzifa merged 17 commits intomainfrom
add_knitro_support
Feb 11, 2026
Merged

Runner: run_solver.py update with knitro#410
finozzifa merged 17 commits intomainfrom
add_knitro_support

Conversation

@finozzifa
Copy link
Copy Markdown
Member

@finozzifa finozzifa commented Feb 4, 2026

The goal of this pull request is add support for the knitro solver in the run_solver.py script.

The interface between linopy and the knitro Python API is introduced in this pull request.

Changes

run_solver.py

I have added a knitro specification for the following functions:

  • def get_solver
  • def def is_mip_problem
  • def get_reported_runtime
  • def get_duality_gap

Test

I tested the integration between knitro and linopy and the changes to run_solver.py on the benchmark pypsa-eur-elec-trex-3-12h.lp.

I get:
{"runtime": 4.476548100999992, "reported_runtime": 3.8160810470581055, "status": "ok", "condition": "optimal", "objective": 7398198432.386027, "duality_gap": null, "max_integrality_violation": null}

The value of the objective function is compatible to those found here

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
solver-benchmark Ready Ready Preview, Comment Feb 11, 2026 4:25pm

Request Review

@finozzifa finozzifa changed the title Add knitro support Runner: run_solver.py add knitro support Feb 4, 2026
@finozzifa finozzifa changed the title Runner: run_solver.py add knitro support Runner: run_solver.py update with knitro Feb 4, 2026
Copy link
Copy Markdown
Member

@siddharth-krishna siddharth-krishna left a comment

Choose a reason for hiding this comment

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

Thanks, Fabrizio. Could you please comment on how you've tested the changes in this PR? (e.g. which benchmarks, what outputs e.g. runtime did you verify)

What happens when we run knitro on MILPs? Does it error, or default to some poor implementation?

Comment thread runner/run_solver.py Outdated
case "gurobi":
return solver_model.Runtime
case "knitro":
return solver_model
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We want the return value to be float | None -- is there no way to get the reported runtime from Knitro? If so, I guess this should be None?

Copy link
Copy Markdown
Member Author

@finozzifa finozzifa Feb 4, 2026

Choose a reason for hiding this comment

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

hey @siddharth-krishna we are getting it. In this case solver_model is a float already. There was not another way I could find to get the runtime.

The solver runtime is available through the function knitro.KN_get_solve_time_real(kc) where kc is the knitro solver context object. kc is instantiated in linopy. Hence it was easier to get the solver runtime in linopy and share it as part of the linopy.Result object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not return kc instead of reported_runtime in linopy here? That's what I think we do for highs and gurobi.

Image

Copy link
Copy Markdown
Member Author

@finozzifa finozzifa Feb 6, 2026

Choose a reason for hiding this comment

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

Ja I tried that but for some reason the returned context was always a NoneType. This is why I resorted to compute the runtime in linopy and pass it to run_solver.py.

The knitro Python API is honestly a bit cranky but I can give it another try.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done! :)

@finozzifa finozzifa merged commit aae885b into main Feb 11, 2026
5 checks passed
@finozzifa finozzifa deleted the add_knitro_support branch February 11, 2026 16:28
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.

3 participants