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

keyboard interrupt #67

Open
hadipourh opened this issue Nov 10, 2022 · 1 comment
Open

keyboard interrupt #67

hadipourh opened this issue Nov 10, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@hadipourh
Copy link

hadipourh commented Nov 10, 2022

Hello all,

I would just like to report that we can not get the intermediate solution after a keyboard interruption.
However, this feature is available when we use Minizinc through the terminal to solve an optimization problem.
The current Python interface outputs the intermediate solution when the time limit reaches. So, is it possible to add this feature for the keyboard interruptions as well?

@Dekker1
Copy link
Member

Dekker1 commented Nov 10, 2022

This is slightly tricky. The simple workaround to do this is to actually capture the intermediate solutions, and keep (only) the incumbent. You can then trap the keyboard interrupt in your Python script, and then outputting the captured incumbent before exiting.

The problem is that this pays the overhead of output/parsing for all the intermediate solutions. Depending on the amount of solutions (read: if there are thousands), this might be a large overhead to pay (especially in Python).

Instead, we would have to use MiniZinc behaviour, and, when the solutions() function is interrupted, output the last solution that is given when the terminate() method is completed on the process. This was part of the initial design of the solutions() function, but I found that Python would throw an error if you yielded values after the async generator was already cancelled. This means we would have to provide our own terminate method for the solution() generator. This is not impossible, but might be a lot of work.

I'm not sure if it's worth it . Especially since it should be noted that MiniZinc Python is currently set to always output and parse intermediate solutions since there are still various solvers that cannot be trusted to output their final solutions when reaching the time limit or when interrupted.

Hopefully the workaround works for you. Otherwise, maybe we can investigate what is possible.

@Dekker1 Dekker1 added the enhancement New feature or request label Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants