google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11.32k stars 2.14k forks source link

Python: CP-SAT tutorial example crashes on Windows with 9.10.4067 #4227

Closed dnpetrov closed 6 months ago

dnpetrov commented 6 months ago

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

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

What operating system (Linux, Windows, ...) and version? Windows 10 Pro, 10.0.19045 build 19045

What did you do? Run tutorial example https://developers.google.com/optimization/cp/cp_example

What did you expect to see

What did you see instead? Process finished with exit code -1073741819 (0xC0000005)

Make sure you include information that can help us debug (full error message, model Proto).

Anything else we should know about your project / environment 9.9.3963: works as expected, prints a list of solutions

lperron commented 6 months ago

most likely duplicate of:

nhuet commented 6 months ago

4225 has been closed as solved. But the issue remains. The tutorial example is still crashing on windows with 9.10 + python3.11. Perhaps an error of compilation in python wheel on pypi ?

nhuet commented 6 months ago

With both python 3.11 and 3.12 + ortools 9.10.4067 + Windows 11 Pro, i got

Segmentation fault

(And the computation succeeds with ortools 9.9.3963)

More precisely, the python versions i tried: python 3.11.0 and 3.12.2

lperron commented 6 months ago

Make sure to:

Update visual studio Create a blank venv Pip install ortools Run the samples. It works for me.

Le ven. 10 mai 2024, 16:56, nhuet @.***> a écrit :

With both python 3.11 and 3.12 + ortools 9.10.4067 + Windows 11 Pro, i got

Segmentation fault

(And the computation succeeds with ortools 9.9.3963)

— Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/4227#issuecomment-2104757755, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUPL3K5OYWLVNYVEM3WLSDZBTN25AVCNFSM6AAAAABHQOQM3WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBUG42TONZVGU . You are receiving this because you commented.Message ID: @.***>

nhuet commented 6 months ago

I do not have visual studio. We need to install visual studio to make ortools work ? I never needed it for previous versions yet. As i am using the wheel from PyPi, i was rather expecting that no c++ library was needed to make it work ?

lperron commented 6 months ago

You always need the visual studio redistributable libraries

Le ven. 10 mai 2024, 18:00, nhuet @.***> a écrit :

I do not have visual studio. We need to install visual studio to make ortools work ? I never needed it for previous versions yet.

— Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/4227#issuecomment-2104854221, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUPL3KEWKWOXMLN4DXH3ULZBTVJ7AVCNFSM6AAAAABHQOQM3WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBUHA2TIMRSGE . You are receiving this because you commented.Message ID: @.***>

nhuet commented 6 months ago

You always need the visual studio redistributable libraries

As I said, the previous release of ortools worked fine for me without installing anything. But indeed i think i have the redistributable libraries preinstalled. I tried to update them using the link https://aka.ms/vs/17/release/vc_redist.x64.exe found on https://learn.microsoft.com/fr-fr/cpp/windows/latest-supported-vc-redist?view=msvc-170, but it changed nothing for me.

My "ultimate" goal is to make ortools 9.10 work for me on github runners "windows-latest" because i have unit tests using ortools in my ci-cd workflow. If you know the command to update their redistributable libraries on it, i would greatly appreciate it.

lperron commented 6 months ago

it works fine: https://github.com/google/or-tools/actions/runs/8998718133

Oops: it does not test the right thing.

lperron commented 6 months ago

Note this was solved on S.O.L: https://stackoverflow.com/questions/78489444/google-ortools-sat-cpsolver-solve-causes-accessviolationexception/78489630#78489630

jeremydover commented 6 months ago

I experienced this error on upgrading to ortools version 9.10, and upgrading the Virtual Studio C++ redistributable at the link above (https://aka.ms/vs/17/release/vc_redist.x64.exe) fixed the problem for me.

lperron commented 6 months ago

Most likely this is fixed.

RobinParmentier commented 5 months ago

Hey, I was having the same problem. Windows 11, python 3.12, ortools 9.10.4067. For my future use I'll just use ortools 9.9 since that seems to work fine. While I was trying to find a solution I also noticed a similar issue with another python example from the documentation:

from ortools.init.python import init
from ortools.linear_solver import pywraplp

def main():
    print("Google OR-Tools version:", init.OrToolsVersion.version_string())

    # Create the linear solver with the GLOP backend.
    solver = pywraplp.Solver.CreateSolver("GLOP")
    if not solver:
        print("Could not create solver GLOP")
        return

    # Create the variables x and y.
    x_var = solver.NumVar(0, 1, "x")
    y_var = solver.NumVar(0, 2, "y")

    print("Number of variables =", solver.NumVariables())

    infinity = solver.infinity()
    # Create a linear constraint, x + y <= 2.
    constraint = solver.Constraint(-infinity, 2, "ct")
    constraint.SetCoefficient(x_var, 1)
    constraint.SetCoefficient(y_var, 1)

    print("Number of constraints =", solver.NumConstraints())

    # Create the objective function, 3 * x + y.
    objective = solver.Objective()
    objective.SetCoefficient(x_var, 3)
    objective.SetCoefficient(y_var, 1)
    objective.SetMaximization()

    print(f"Solving with {solver.SolverVersion()}")
    result_status = solver.Solve()

    print(f"Status: {result_status}")
    if result_status != pywraplp.Solver.OPTIMAL:
        print("The problem does not have an optimal solution!")
        if result_status == pywraplp.Solver.FEASIBLE:
            print("A potentially suboptimal solution was found")
        else:
            print("The solver could not solve the problem.")
            return

    print("Solution:")
    print("Objective value =", objective.Value())
    print("x =", x_var.solution_value())
    print("y =", y_var.solution_value())

    print("Advanced usage:")
    print(f"Problem solved in {solver.wall_time():d} milliseconds")
    print(f"Problem solved in {solver.iterations():d} iterations")

if __name__ == "__main__":
    init.CppBridge.init_logging("basic-example.py")
    cpp_flags = init.CppFlags()
    cpp_flags.stderrthreshold = True
    cpp_flags.log_prefix = False
    init.CppBridge.set_flags(cpp_flags)
    main()

In this example the line
init.CppBridge.init_logging("basic-example.py") never finishes and the program crashes silently. The code works fine for ortools 9.9 with no other changes so it seems to me both these problems are related.

I did try to fix the problem with visual studio installer but this did not work for me. What exactly are the requirements of visual studio for ortools?

lperron commented 5 months ago

Can you update the visual studio redistributable libraries. Many users reported success doing so. Laurent Perron | Operations Research | @.*** | (33) 1 42 68 53 00

Le mer. 12 juin 2024 à 10:23, RobinParmentier @.***> a écrit :

Hey, I was having the same problem. Windows 11, python 3.12, ortools 9.10.4067. For my future use I'll just use ortools 9.9 since that seems to work fine. While I was trying to find a solution I also noticed a similar issue with another python example from the documentation:

from ortools.init.python import init from ortools.linear_solver import pywraplp

def main(): print("Google OR-Tools version:", init.OrToolsVersion.version_string())

# Create the linear solver with the GLOP backend.
solver = pywraplp.Solver.CreateSolver("GLOP")
if not solver:
    print("Could not create solver GLOP")
    return

# Create the variables x and y.
x_var = solver.NumVar(0, 1, "x")
y_var = solver.NumVar(0, 2, "y")

print("Number of variables =", solver.NumVariables())

infinity = solver.infinity()
# Create a linear constraint, x + y <= 2.
constraint = solver.Constraint(-infinity, 2, "ct")
constraint.SetCoefficient(x_var, 1)
constraint.SetCoefficient(y_var, 1)

print("Number of constraints =", solver.NumConstraints())

# Create the objective function, 3 * x + y.
objective = solver.Objective()
objective.SetCoefficient(x_var, 3)
objective.SetCoefficient(y_var, 1)
objective.SetMaximization()

print(f"Solving with {solver.SolverVersion()}")
result_status = solver.Solve()

print(f"Status: {result_status}")
if result_status != pywraplp.Solver.OPTIMAL:
    print("The problem does not have an optimal solution!")
    if result_status == pywraplp.Solver.FEASIBLE:
        print("A potentially suboptimal solution was found")
    else:
        print("The solver could not solve the problem.")
        return

print("Solution:")
print("Objective value =", objective.Value())
print("x =", x_var.solution_value())
print("y =", y_var.solution_value())

print("Advanced usage:")
print(f"Problem solved in {solver.wall_time():d} milliseconds")
print(f"Problem solved in {solver.iterations():d} iterations")

if name == "main": init.CppBridge.init_logging("basic-example.py") cpp_flags = init.CppFlags() cpp_flags.stderrthreshold = True cpp_flags.log_prefix = False init.CppBridge.set_flags(cpp_flags) main()

In this example the line init.CppBridge.init_logging("basic-example.py") never finishes and the program crashes silently. The code works fine for ortools 9.9 with no other changes so it seems to me both these problems are related.

I did try to fix the problem with visual studio installer but this did not work for me. What exactly are the requirements of visual studio for ortools?

— Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/4227#issuecomment-2163555562, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUPL3J3GIN5BIZWNPAOAV3ZHB7XPAVCNFSM6AAAAABHQOQM3WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRTGU2TKNJWGI . You are receiving this because you were assigned.Message ID: <google/or-tools/issues/4227/2163555562 @.***>

RobinParmentier commented 5 months ago

I tried using the link that was posted here earlier (https://aka.ms/vs/17/release/vc_redist.x64.exe) but this didn't work for me.

walelo9787 commented 5 months ago

Same for me, the solver crashes even though I have the latest vcredist: Microsoft Visual C++ 2015-2022 Redistributable (x64) - 14.40.33810. Env: OS: win 11 Entreprise Code: jdk21

nhuet commented 5 months ago

FYI, I still did not succeed in making it work (and actually stopped trying, simply freezing for now ortools version). And github windows runner have recently upgraded their Microsoft Visual C++ 2015-2022 Redistributable and the example still crashes on it with ortools 9.10.