-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add qp support for highs #3531
base: main
Are you sure you want to change the base?
add qp support for highs #3531
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@quantresearch1, thank you for the contribution! As written, this does not yet add QP support for Highs, though: By changing the quadratic
flag to True
in generate_standard_repn
, you move the nonlinear term in your objective from repn.nonlinear_expr
to repn.quadratic_vars
and repn.quadratic_coefs
(and hence bypass the error in line 622 of appsi/solvers/highs.py
) . To properly send quadratic expressions to Highs, you will need to parse this part of the StandardRepn
object and send the result to Highs.
(Your test appears to get lucky--it is actually sending a constant objective to Highs, but the variables happen to land on the values you are expecting. You can see this by adding an assertion that the results
object returned by opt.solve(m)
agrees with your expected objective value: self.assertEqual(results.best_feasible_objective, 2)
.)
@emma58 Thanks for the advice. Looking into the Highs C++ code, I did not find a quadratic equivalent to changeColCost so I think each coefficient update would have to be a call to passHessian which is not ideal in a persistent setting (assuming many updates). I will think about this a bit more and reraise if I can come up with a decent solution |
raise unittest.SkipTest | ||
|
||
|
||
class TestBugs(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrmundt I have copied the test cases that are passing from the legacy appsi_highs. I am not sure if you wanted to leave the test cases for a later stage, let me know if I should remove them (I do need the new qp test cases though)
|
||
self._solver_model.changeObjectiveSense(sense) | ||
self._solver_model.changeColsCost(n, indices, costs) | ||
self._mutable_objective = _MutableObjective( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea here is we collect all the mutable objective terms and update them once through _mutable_objective.update()
self.col_idx = col_idx | ||
|
||
|
||
class _MutableObjective: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emma58 I have tried to emulate the new gurobi_persistent and use a similar objective data structure. However, highs quadratic objective handling is too different so I could not make it fit as nicely as I would have hoped. To avoid always calling passHessian at each update I first check against the last set of coefficients, let me know if you think there's a better way
I need to look into the highs unit tests failure, they look genuine |
Fixes #3381 .
Summary/Motivation:
HiGHS can solve quadratic programming (QP) models, which contain an objective term x.T @ Q @ x where the Hessian matrix Q is positive semi-definite.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: