Skip to content

Commit

Permalink
Change implementation: make private-esque attribute that user can alter
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmundt committed Mar 7, 2024
1 parent 9bbb887 commit 78431b7
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pyomo/contrib/appsi/solvers/ipopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import os
from pyomo.contrib.appsi.cmodel import cmodel_available
from pyomo.core.staleflag import StaleFlagManager
from pyomo.opt.base import subprocess_timeout


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -148,6 +147,7 @@ def __init__(self, only_child_vars=False):
self._primal_sol = ComponentMap()
self._reduced_costs = ComponentMap()
self._last_results_object: Optional[Results] = None
self._version_timeout = 2

def available(self):
if self.config.executable.path() is None:
Expand All @@ -159,7 +159,7 @@ def available(self):
def version(self):
results = subprocess.run(
[str(self.config.executable), '--version'],
timeout=subprocess_timeout,
timeout=self._version_timeout,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
Expand Down
4 changes: 2 additions & 2 deletions pyomo/contrib/solver/ipopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from pyomo.core.expr.numvalue import value
from pyomo.core.base.suffix import Suffix
from pyomo.common.collections import ComponentMap
from pyomo.opt.base import subprocess_timeout

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -207,6 +206,7 @@ def __init__(self, **kwds):
self._writer = NLWriter()
self._available_cache = None
self._version_cache = None
self._version_timeout = 2

def available(self, config=None):
if config is None:
Expand All @@ -229,7 +229,7 @@ def version(self, config=None):
else:
results = subprocess.run(
[str(pth), '--version'],
timeout=subprocess_timeout,
timeout=self._version_timeout,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
Expand Down
2 changes: 0 additions & 2 deletions pyomo/opt/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@
from pyomo.opt.base.results import ReaderFactory, AbstractResultsReader
from pyomo.opt.base.problem import AbstractProblemWriter, BranchDirection, WriterFactory
from pyomo.opt.base.formats import ProblemFormat, ResultsFormat, guess_format

subprocess_timeout = 2
1 change: 1 addition & 0 deletions pyomo/opt/solver/shellcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, **kwargs):
# a solver plugin may not report execution time.
self._last_solve_time = None
self._define_signal_handlers = None
self._version_timeout = 2

if executable is not None:
self.set_executable(name=executable, validate=validate)
Expand Down
4 changes: 2 additions & 2 deletions pyomo/solvers/plugins/solvers/CONOPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyomo.common.collections import Bunch
from pyomo.common.tempfiles import TempfileManager

from pyomo.opt.base import ProblemFormat, ResultsFormat, subprocess_timeout
from pyomo.opt.base import ProblemFormat, ResultsFormat
from pyomo.opt.base.solvers import _extract_version, SolverFactory
from pyomo.opt.results import SolverStatus
from pyomo.opt.solver import SystemCallSolver
Expand Down Expand Up @@ -79,7 +79,7 @@ def _get_version(self):
return _extract_version('')
results = subprocess.run(
[solver_exec],
timeout=subprocess_timeout,
timeout=self._version_timeout,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
Expand Down
10 changes: 2 additions & 8 deletions pyomo/solvers/plugins/solvers/CPLEX.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@
from pyomo.common.tempfiles import TempfileManager

from pyomo.common.collections import ComponentMap, Bunch
from pyomo.opt.base import (
ProblemFormat,
ResultsFormat,
OptSolver,
BranchDirection,
subprocess_timeout,
)
from pyomo.opt.base import ProblemFormat, ResultsFormat, OptSolver, BranchDirection
from pyomo.opt.base.solvers import _extract_version, SolverFactory
from pyomo.opt.results import (
SolverResults,
Expand Down Expand Up @@ -410,7 +404,7 @@ def _get_version(self):
return _extract_version('')
results = subprocess.run(
[solver_exec, '-c', 'quit'],
timeout=subprocess_timeout,
timeout=self._version_timeout,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
Expand Down
4 changes: 2 additions & 2 deletions pyomo/solvers/plugins/solvers/GLPK.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from pyomo.common import Executable
from pyomo.common.collections import Bunch
from pyomo.common.errors import ApplicationError
from pyomo.opt import (
SolverFactory,
OptSolver,
Expand All @@ -29,7 +30,6 @@
SolutionStatus,
ProblemSense,
)
from pyomo.opt.base import subprocess_timeout
from pyomo.opt.base.solvers import _extract_version
from pyomo.opt.solver import SystemCallSolver
from pyomo.solvers.mockmip import MockMIP
Expand Down Expand Up @@ -138,7 +138,7 @@ def _get_version(self, executable=None):
[executable, "--version"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=subprocess_timeout,
timeout=self._version_timeout,
universal_newlines=True,
)
return _extract_version(result.stdout)
Expand Down
4 changes: 2 additions & 2 deletions pyomo/solvers/plugins/solvers/IPOPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyomo.common.collections import Bunch
from pyomo.common.tempfiles import TempfileManager

from pyomo.opt.base import ProblemFormat, ResultsFormat, subprocess_timeout
from pyomo.opt.base import ProblemFormat, ResultsFormat
from pyomo.opt.base.solvers import _extract_version, SolverFactory
from pyomo.opt.results import SolverStatus, SolverResults, TerminationCondition
from pyomo.opt.solver import SystemCallSolver
Expand Down Expand Up @@ -79,7 +79,7 @@ def _get_version(self):
return _extract_version('')
results = subprocess.run(
[solver_exec, "-v"],
timeout=subprocess_timeout,
timeout=self._version_timeout,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
Expand Down
4 changes: 2 additions & 2 deletions pyomo/solvers/plugins/solvers/SCIPAMPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pyomo.common.collections import Bunch
from pyomo.common.tempfiles import TempfileManager

from pyomo.opt.base import ProblemFormat, ResultsFormat, subprocess_timeout
from pyomo.opt.base import ProblemFormat, ResultsFormat
from pyomo.opt.base.solvers import _extract_version, SolverFactory
from pyomo.opt.results import (
SolverStatus,
Expand Down Expand Up @@ -103,7 +103,7 @@ def _get_version(self, solver_exec=None):
return _extract_version('')
results = subprocess.run(
[solver_exec, "--version"],
timeout=subprocess_timeout,
timeout=self._version_timeout,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
Expand Down

0 comments on commit 78431b7

Please sign in to comment.