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

Windows fatal exception: access violation message while using HIGHS via math_opt #4226

Closed
vaidzelevich opened this issue May 9, 2024 · 3 comments
Assignees
Labels
Help Needed Modeling/Usage problem Lang: Python Python wrapper issue OS: Windows Windows OS
Milestone

Comments

@vaidzelevich
Copy link

What version of OR-Tools and what language are you using?
Version: v9.10
Language: Python 3.11.1

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

What operating system (Linux, Windows, ...) and version?
Windows

What did you do?
Run the following script

from typing import Sequence
from absl import app
from ortools.math_opt.python import mathopt


def main(argv: Sequence[str]) -> None:
    del argv  # Unused.

    model = mathopt.Model(name="my_model")
    x = model.add_binary_variable(name="x")
    y = model.add_variable(lb=0.0, ub=2.5, name="y")
    model.add_linear_constraint(x + y <= 1.5, name="c")
    objective_expression = 0
    objective_expression += 2 * x
    objective_expression += y
    model.maximize(objective_expression)
    
    result = mathopt.solve(model, mathopt.SolverType.HIGHS)

    if result.termination.reason not in (
        mathopt.TerminationReason.OPTIMAL,
        mathopt.TerminationReason.FEASIBLE,
    ):
        raise RuntimeError(f"model failed to solve: {result.termination}")

    print(f"Objective value: {result.objective_value()}")
    print(f"Value for variable x: {result.variable_values()[x]}")


if __name__ == "__main__":
    app.run(main)

What did you expect to see

Objective value: 2.5
Value for variable x: 1.0

What did you see instead?

The previous message and the following addition

Windows fatal exception: access violation

Thread 0x00001994 (most recent call first):
  <no Python frame>
Windows fatal exception: access violation

Anything else we should know about your project / environment
There is no the error message if I replace app.run(main) with main('').

@lperron
Copy link
Collaborator

lperron commented May 9, 2024

c:\Users\laure\Work\test>Scripts\python.exe test_mathopt.py
Objective value: 2.5
Value for variable x: 1.0

try cleaning your env, or create a blank venv

@vaidzelevich
Copy link
Author

Unfortunately, this didn't help. I also tried other versions of Python (Python 3.10.9 and Python 3.12.3) but the error message persisted.

@vaidzelevich
Copy link
Author

Now everything is working fine. Updating the build tool for Visual Studio seems to help.

Thanks again for such a wonderful library.

@lperron lperron closed this as completed May 10, 2024
@Mizux Mizux added this to the v9.10 milestone May 11, 2024
@Mizux Mizux self-assigned this May 11, 2024
@Mizux Mizux added Help Needed Modeling/Usage problem OS: Windows Windows OS Lang: Python Python wrapper issue labels May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Needed Modeling/Usage problem Lang: Python Python wrapper issue OS: Windows Windows OS
Projects
None yet
Development

No branches or pull requests

3 participants