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

Catch SCIP errors / throw Python errors #610

Open
VonAlphaBisZulu opened this issue Sep 1, 2022 · 10 comments
Open

Catch SCIP errors / throw Python errors #610

VonAlphaBisZulu opened this issue Sep 1, 2022 · 10 comments

Comments

@VonAlphaBisZulu
Copy link

PySCIPOpt's error management should be improved. There are many situations in which very simple problems resolve in uncaught errors and crash the parent python program.

Here is one simple example: Create an empty model, solve it, call freeReoptSolve, solve again.

from pyscipopt import Model

m = Model()
print('first optimization')
m.optimize()
print('change state')
m.freeReoptSolve()
print('state changed, 2nd optimization')
m.optimize()
print('done')

This goes into a segmentation fault that ends the Python thread. This should rather throw an error in Python with some more explanation on how to avoid it.

Just to be clear: I do not need help with the particular problem mentioned above. I just suggest catching errors and forwarding them to the python error stream.

@VonAlphaBisZulu VonAlphaBisZulu changed the title Catch if SCIP in wrong state and throw Python error Catch SCIP errors / throw Python errors Sep 1, 2022
@VonAlphaBisZulu
Copy link
Author

Throwing the error in Python and showing the original error message would (1) help identify the problem (2) allow making use of Python debugging mode

@CGraczyk
Copy link
Collaborator

CGraczyk commented Sep 2, 2022

Hi, that does sound like a useful extension of the code! If you have a workaround for this issue or extended the code base on your side, please feel free to create a merge request and we can have a look to integrate this into the master.

Thanks for letting us know.

@VonAlphaBisZulu
Copy link
Author

VonAlphaBisZulu commented Sep 2, 2022

I wish I had, but unfortunately, I never dived deep enough into PySCIPOpt's code. Maybe someone can tag this issue as enhancement.

@Joao-Dionisio Joao-Dionisio moved this to Todo in PySCIPOpt Oct 9, 2023
@Joao-Dionisio Joao-Dionisio moved this from Todo to Seems Doable in PySCIPOpt Oct 10, 2023
@Joao-Dionisio Joao-Dionisio moved this from Seems Doable to Todo in PySCIPOpt Oct 10, 2023
@mmghannam mmghannam moved this from Todo to Backlog in PySCIPOpt May 3, 2024
@VonAlphaBisZulu
Copy link
Author

VonAlphaBisZulu commented Jul 20, 2024

I'd really like to use SCIP 9.1.0, but I cannot because of this non-critical error in scip that writes to the error stream which stalls the parent program. Is there anything I can do about this?

@Joao-Dionisio
Copy link
Collaborator

Hey @VonAlphaBisZulu, there's a big conference going on, so it's going to be difficult helping out, but I'll try to see if anyone can. Sorry for this taking so long, it's actually a pretty important issue.

@Joao-Dionisio
Copy link
Collaborator

Hey, @VonAlphaBisZulu. Just checking, these are two different issues, right?

I understand the annoyance of programs crashing without an error message, but I think we can only solve this on a case-by-case basis. Maybe someone better at Cython can chime in eventually, but I spoke with a bunch of people, and none found a way to do it generally. These types of things probably happen because a PySCIPOpt function is missing a stage check, or it's not checking that the input is correct, or something like this. These are mostly easy fixes, and until a better way is found, we'll be solving them as users report them.

As for the ELEAVE56 error, did you check Issue #691? The problem here was that the user was trying to do column generation but he forgot to add modifiable=True to the constraints.

@VonAlphaBisZulu
Copy link
Author

Thanks for the reply. I understand. It really seems like there is no easy fix to this. Perhaps it would be easier to resolve the issue in SCIP that I referenced before.

I checked issue #691 and modified my problem to have all constraints modifiable. It didn't fix it. The error refers to a constraint whose index higher than the number of constraints put into that problem. The issue might be that solving the MILP with SCIP introduces some cut-constraints that are not handled or passed on correctly to SoPlex. I think some cuts result in some variables being fixed to a certain integer value, and the constraint that does so is marked as "fixed". But then something, SCIP or SoPlex, tries to put them into the basis and fails because they are fixed. The error says, "this should never happen". This particular underlying problem should probably be addressed in SCIP.

@Joao-Dionisio
Copy link
Collaborator

Joao-Dionisio commented Nov 23, 2024

Hello, @VonAlphaBisZulu! I think the problem with your initial code is that you didn't enable reoptimization. This code

m = Model()
m.enableReoptimization()
print('first optimization')
m.optimize()
print('change state')
m.freeReoptSolve()
print('state changed, 2nd optimization')
m.optimize()
print('done')

works for me. Admittedly, this should be better documented, but you can look at test_reopt.py. Does this also work in your work?

@VonAlphaBisZulu
Copy link
Author

Hi Joao,

Yes, enabling reoptimization helps for this particular problem. The broader problem mentioned in the initial post is that errors (like ELEAVE56) were not caught properly. So they cannot be caught with "try-catch" in python, but they will stall or kill the parent Pyhton program instead. Admittedly, I haven't looked into this for a while and don't know if this has been resolved in the meantime.

@Joao-Dionisio
Copy link
Collaborator

Joao-Dionisio commented Nov 24, 2024

Okay, I'm just happy that the initial problem got fixed.

As for catching errors, I've started a conversation with the remaining team on whether there should be an option to pip install pyscipopt-debug, where pyscipopt-debug would link against a SCIP binary compiled in Debug mode. This would throw more errors on the C side, which hopefully PySCIPOpt could catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

4 participants