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

Solving an infeasible problem using HiGHS raises RuntimeError #2920

Closed
victorgarcia98 opened this issue Jul 23, 2023 · 2 comments
Closed

Solving an infeasible problem using HiGHS raises RuntimeError #2920

victorgarcia98 opened this issue Jul 23, 2023 · 2 comments
Labels

Comments

@victorgarcia98
Copy link

Summary

I run HiGHS in an infeasible problem but the solve step raises the RuntimeError exception, instead of returning a results object with the termination status being infeasible. Tried using both using the solver class Highs and the SolverFactory("appsi_highs"), but both produce the same behavior. Moreover, I followed the indication opt.config.load_solution=False, but the exception still raised.

Steps to reproduce the issue

$ python highs_error.py
WARNING: Loading a SolverResults object with a warning status into
model.name="unknown";
    - termination condition: infeasible
    - message from solver: <undefined>
Termination Condition:  infeasible
Running HiGHS 1.5.3 [date: 2023-05-16, git hash: 594fa5a9d-dirty]
Copyright (c) 2023 HiGHS under MIT licence terms
RuntimeError
Running HiGHS 1.5.3 [date: 2023-05-16, git hash: 594fa5a9d-dirty]
Copyright (c) 2023 HiGHS under MIT licence terms
RuntimeError
Running HiGHS 1.5.3 [date: 2023-05-16, git hash: 594fa5a9d-dirty]
Copyright (c) 2023 HiGHS under MIT licence terms
RuntimeError
## highs_error.py
import pyomo.environ as pyo
from pyomo.opt import SolverFactory
from pyomo.contrib.appsi.solvers.highs import Highs

######################
# Infeasible Problem #
######################

model = pyo.ConcreteModel()
model.x = pyo.Var(domain=pyo.NonNegativeReals)

model.infeasible_constraint = pyo.Constraint(expr = model.x <= -1)
model.objective = pyo.Objective(expr = model.x)

####################
# Solving with CBC #
####################

opt_cbc = SolverFactory("cbc")
results = opt_cbc.solve(
    model
)

print("Termination Condition: ", results.solver.termination_condition) # -> Termination Condition:  infeasible


######################
# Solving with HiGhs #
######################

opt_highs = Highs()
try:
    results = opt_highs.solve(model) # -> RuntimeError
except RuntimeError:
    print("RuntimeError")

opt_highs_factory = SolverFactory("appsi_highs")
try:
    results = opt_highs_factory.solve(model) # -> RuntimeError
except RuntimeError:
    print("RuntimeError")

opt_highs_factory = SolverFactory("appsi_highs")
opt_highs_factory.config.load_solution=False
try:
    results = opt_highs_factory.solve(model) # -> RuntimeError
except RuntimeError:
    print("RuntimeError")

Error Message

Running HiGHS 1.5.3 [date: 2023-05-16, git hash: 594fa5a9d-dirty]
Copyright (c) 2023 HiGHS under MIT licence terms
Traceback (most recent call last):
  File "/home/victor/Work/Seita/flexmeasures/pyomo_mve.py", line 23, in <module>
    results = opt.solve(
  File "/home/victor/Work/Seita/flexmeasures/venv/lib/python3.10/site-packages/pyomo/contrib/appsi/solvers/highs.py", line 250, in solve
    res = self._solve(timer)
  File "/home/victor/Work/Seita/flexmeasures/venv/lib/python3.10/site-packages/pyomo/contrib/appsi/solvers/highs.py", line 234, in _solve
    return self._postsolve(timer)
  File "/home/victor/Work/Seita/flexmeasures/venv/lib/python3.10/site-packages/pyomo/contrib/appsi/solvers/highs.py", line 657, in _postsolve
    raise RuntimeError(
RuntimeError: A feasible solution was not found, so no solution can be loaded.Please set opt.config.load_solution=False and check results.termination_condition and results.best_feasible_objective before loading a solution.

Information on your system

Pyomo version: Pyomo 6.6.1 (CPython 3.10.6 on Linux 6.2.6-76060206-generic)
Python version: Python 3.10.6
Operating system: Pop Os
How Pyomo was installed (PyPI, conda, source): pip
Solver: HiGHs (v.1.5.3), installed through the pip package highspy (v.1.5.3).

@michaelbynum
Copy link
Contributor

opt.config.load_solution = False only works with opt_highs = Highs(). If you use the solver factory, you have to use results = opt_highs_factory.solve(model, load_solutions=False).

@victorgarcia98
Copy link
Author

Thanks @michaelbynum! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants