Skip to content
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

abort trap in gurobi backend with non PSD matrix #27

Closed
tlambert03 opened this issue Apr 10, 2023 · 5 comments · Fixed by #28
Closed

abort trap in gurobi backend with non PSD matrix #27

tlambert03 opened this issue Apr 10, 2023 · 5 comments · Fixed by #28

Comments

@tlambert03
Copy link
Member

tlambert03 commented Apr 10, 2023

the following script results in a segfault crash in the gurobi backend:

libc++abi: terminating with uncaught exception of type std::runtime_error: Gurobi error in ./ilpy/impl/solvers/GurobiBackend.cpp:236: Q matrix is not positive semi-definite (PSD). Set NonConvex parameter to 2 to solve model.
[1]    56530 abort      python x.py

I have no doubt I've set something up that is impossible, non-convex, or something bad :) ... but it shouldn't segfault either way:

import ilpy

solver = ilpy.Solver(1, ilpy.VariableType.Continuous)

# -(x ** 2)
obj = ilpy.Objective()
obj.set_quadratic_coefficient(0, 0, -1)
solver.set_objective(obj)

# x >= 2
const2 = ilpy.Constraint()
const2.set_coefficient(0, 1)
const2.set_relation(ilpy.Relation.GreaterEqual)
const2.set_value(2)
solver.add_constraint(const2)

print(solver.solve())
@funkey
Copy link
Member

funkey commented Apr 10, 2023

That doesn't look like a segfault, I think this is just an unhandled exception of type std::runtime_error. We could catch this kind of exception and turn it into a proper python exception to fail more gracefully.

@funkey
Copy link
Member

funkey commented Apr 10, 2023

That part is quite interesting: Set NonConvex parameter to 2 to solve model.

Can it be gurobi allows non-PSD matrices now? If so, then we should just set this magic parameter to 2 ;)

@tlambert03
Copy link
Member Author

I agree, sorry, wrong term! I think I had seen a segfault when running a test that had included this ... but maybe I'm wrong there too 😂

anyway, do you think it's as simple as always setting it? Or do we have to set it conditionally?

@tlambert03
Copy link
Member Author

note to self, can avoid the crash by adding this to model.solve():

	GRBenv* modelenv = GRBgetenv(_model);
	GRB_CHECK(GRBsetintparam(modelenv, GRB_INT_PAR_NONCONVEX, 2));

(this requires a new header file, will PR when finished exploring)

@tlambert03 tlambert03 changed the title Segfault in gurobi backend with non PSD matrix abort trap in gurobi backend with non PSD matrix Apr 11, 2023
@tlambert03
Copy link
Member Author

037283e closes this issue by re-raising the exception in python...

adding support for GRB_INT_PAR_NONCONVEX can be discussed in #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 a pull request may close this issue.

2 participants