Runner: run_solver.py update with knitro#410
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
siddharth-krishna
left a comment
There was a problem hiding this comment.
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?
| case "gurobi": | ||
| return solver_model.Runtime | ||
| case "knitro": | ||
| return solver_model |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Why not return kc instead of reported_runtime in linopy here? That's what I think we do for highs and gurobi.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Oh, that's weird. Alternatively, you could try what I did for CBC and return a namedtuple:
https://github.com/PyPSA/linopy/blob/164a1e00587cb03fb235c51ecbe2495dfc8bce9a/linopy/solvers.py#L608-L610
The goal of this pull request is add support for the
knitrosolver in therun_solver.pyscript.The interface between
linopyand theknitroPython API is introduced in this pull request.Changes
run_solver.pyI have added a
knitrospecification for the following functions:def get_solverdef def is_mip_problemdef get_reported_runtimedef get_duality_gapTest
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