Skip to content

Commit

Permalink
Merge pull request Pyomo#3433 from jsiirola/neos-test-solvers
Browse files Browse the repository at this point in the history
Verify we are testing all NEOS solvers
  • Loading branch information
mrmundt authored Nov 26, 2024
2 parents 44d9bc3 + eb888cb commit d3f0bf5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
13 changes: 7 additions & 6 deletions pyomo/neos/kestrel.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def getJobAndPassword(self):
password = m.groups()[0]
return (jobNumber, password)

def getAvailableSolvers(self):
"""Return a list of all NEOS solvers that this interface supports"""
allKestrelSolvers = self.neos.listSolversInCategory("kestrel")
_ampl = ':AMPL'
return sorted(s[: -len(_ampl)] for s in allKestrelSolvers if s.endswith(_ampl))

def getSolverName(self):
"""
Read in the kestrel_options to pick out the solver name.
Expand All @@ -218,12 +224,7 @@ def getSolverName(self):
"""
# Get a list of available kestrel solvers from NEOS
allKestrelSolvers = self.neos.listSolversInCategory("kestrel")
kestrelAmplSolvers = []
for s in allKestrelSolvers:
i = s.find(':AMPL')
if i > 0:
kestrelAmplSolvers.append(s[0:i])
kestrelAmplSolvers = self.getAvailableSolvers()
self.options = None
# Read kestrel_options to get solver name
if "kestrel_options" in os.environ:
Expand Down
16 changes: 12 additions & 4 deletions pyomo/neos/tests/test_neos.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def test_connection_failed(self):
finally:
pyomo.neos.kestrel.NEOS.host = orig_host

def test_check_all_ampl_solvers(self):
kestrel = kestrelAMPL()
solvers = kestrel.getAvailableSolvers()
for solver in solvers:
name = solver.lower().replace('-', '')
if not hasattr(RunAllNEOSSolvers, 'test_' + name):
self.fail(f"RunAllNEOSSolvers missing test for '{solver}'")


class RunAllNEOSSolvers(object):
def test_bonmin(self):
Expand Down Expand Up @@ -165,10 +173,10 @@ def test_ooqp(self):
else:
self._run('ooqp')

# The simple tests aren't complementarity
# problems
# def test_path(self):
# self._run('path')
def test_path(self):
# The simple tests aren't complementarity
# problems
self.skipTest("The simple NEOS test is not a complementarity problem")

def test_snopt(self):
self._run('snopt')
Expand Down
2 changes: 1 addition & 1 deletion pyomo/opt/plugins/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setup_test_parser(parser):
def test_exec(options):
import pyomo.solvers.tests.testcases

pyomo.solvers.tests.testcases.run_test_scenarios(options)
pyomo.solvers.tests.testcases.run_scenarios(options)


#
Expand Down
6 changes: 3 additions & 3 deletions pyomo/solvers/tests/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def run_scenarios(options):

for key, test_case in generate_scenarios():
model, solver, io = key
if len(solvers) > 0 and not solver in solvers:
if len(solvers) > 0 and solver not in solvers:
continue
if test_case.status == 'skip':
continue
Expand All @@ -381,7 +381,7 @@ def run_scenarios(options):
# Validate solution status
try:
model_class.post_solve_test_validation(None, results)
except:
except Exception:
if test_case.status == 'expected failure':
stat[key] = (True, "Expected failure")
else:
Expand Down Expand Up @@ -431,7 +431,7 @@ def run_scenarios(options):
total = Bunch(NumEPass=0, NumEFail=0, NumUPass=0, NumUFail=0)
for key in stat:
model, solver, io = key
if not solver in summary:
if solver not in summary:
summary[solver] = Bunch(NumEPass=0, NumEFail=0, NumUPass=0, NumUFail=0)
_pass, _str = stat[key]
if _pass:
Expand Down

0 comments on commit d3f0bf5

Please sign in to comment.