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

BOP solver unresponsive, disrespects time limit #1886

Open
snedeljkovic opened this issue Feb 18, 2020 · 6 comments
Open

BOP solver unresponsive, disrespects time limit #1886

snedeljkovic opened this issue Feb 18, 2020 · 6 comments
Assignees
Labels
Bug Lang: Python Python wrapper issue Solver: Linear Solver Related to all Linear Solver (GLOP, BOP, CBC etc...)
Milestone

Comments

@snedeljkovic
Copy link

What version of OR-tools and what language are you using?
Version: 7.5.7466
Language: Python

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
BOP

What operating system (Linux, Windows, ...) and version?
Ubuntu 18.04.3 LTS (Google Colab)

What did you do?
Steps to reproduce the behavior:
I set the time limit to 5 min.

What did you expect to see
I expected the solver to terminate after ~5 min, or respond to a cell interrupt command.

What did you see instead?
The solver doesn't terminate after the time limit, and is unresponsive to interrupt. I had to manually restart the kernel.

Anything else we should know about your project / environment
I ran it on Google Colab. Sometimes ~2x smaller instances exhibit the same behavior although I cannot reproduce it consistently. I attached the model that fails every time.
model_lp.zip

@Mizux Mizux added Bug Lang: Python Python wrapper issue Solver: Linear Solver Related to all Linear Solver (GLOP, BOP, CBC etc...) labels Feb 18, 2020
@Mizux
Copy link
Collaborator

Mizux commented Feb 18, 2020

AFAIK, since the solver is in C++ and we only swig wrap it in python, signal are not forwarded to the underlying libraries solver.

For timeout not respected need to find some information internally....

@snedeljkovic
Copy link
Author

Is this a confirmed bug (on your side), and if so will it be added to a milestone? Can I somehow further help you?

@snedeljkovic
Copy link
Author

@Mizux @lperron I built the master branch from source and the model still fails.

@jundl77
Copy link

jundl77 commented Dec 15, 2020

Is there any update on this? I have also noticed that ortools is not responding to signals, which is a problem especially if it is the SIGTERM signal

@lperron
Copy link
Collaborator

lperron commented Dec 15, 2020 via email

@jundl77
Copy link

jundl77 commented Dec 15, 2020

Thanks for your quick reply, but I found that not to be true. I have created a little example below that demonstrates this.

As soon as the code enters the "start solving" step, i.e. the search for solutions begins, the CP-SAT solver also no longer replies to SIGTERM. You can see this is if you run this in your terminal and press Ctrl+C once that "start solving" line has been printed.

Here is the code that reproduces this, it's just a very simple solver that solves the subset-sum problem:

from ortools.sat.python import cp_model
import random


class VarArraySolutionPrinter(cp_model.CpSolverSolutionCallback):
    """Print intermediate solutions."""

    def __init__(self, variables):
        cp_model.CpSolverSolutionCallback.__init__(self)
        self.__variables = variables
        self.__solution_count = 0

    def on_solution_callback(self):
        self.__solution_count += 1
        for v in self.__variables:
            print('%i' % (self.Value(v)), end=' ')
        print()

    def solution_count(self):
        return self.__solution_count


def SearchForAllSolutionsSampleSat(values, total_sum):
    """Showcases calling the solver to search for all solutions."""
    # Creates the model.
    model = cp_model.CpModel()

    num_values = len(values)
    subsets = [model.NewIntVar(0, num_values, f'{i}') for i in range(num_values)]
    subset_sum = model.NewIntVar(0, num_values, 'sum')

    # add constraints on each variable to ensure it is only used at most once
    [model.Add(subset <= 1) for subset in subsets]
    model.Add(subset_sum == cp_model.LinearExpr.Sum(subsets))
    model.Add(total_sum == cp_model.LinearExpr.ScalProd(subsets, values))

    # create a solver and solve.
    solver = cp_model.CpSolver()
    solution_printer = VarArraySolutionPrinter(subsets)
    print('start solving')
    status = solver.SearchForAllSolutions(model, solution_printer)

    print('Status = %s' % solver.StatusName(status))
    print('Number of solutions found: %i' % solution_printer.solution_count())

print('generate data')
s = [random.randint(1, 100) for _ in range(2000000)]

print('enter solver')
SearchForAllSolutionsSampleSat(s, 452343)

@Mizux Mizux added this to the v8.3 milestone Feb 12, 2021
@Mizux Mizux self-assigned this Feb 12, 2021
@Mizux Mizux modified the milestones: v9.0, v9.1 Mar 22, 2021
@Mizux Mizux modified the milestones: v9.1, v9.2 Aug 23, 2021
@Mizux Mizux modified the milestones: v9.2, v9.3 Oct 5, 2021
@Mizux Mizux modified the milestones: v9.3, v10.0 Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Lang: Python Python wrapper issue Solver: Linear Solver Related to all Linear Solver (GLOP, BOP, CBC etc...)
Projects
None yet
Development

No branches or pull requests

4 participants