Skip to content

Commit d3f0bf5

Browse files
authored
Merge pull request Pyomo#3433 from jsiirola/neos-test-solvers
Verify we are testing all NEOS solvers
2 parents 44d9bc3 + eb888cb commit d3f0bf5

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

pyomo/neos/kestrel.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ def getJobAndPassword(self):
207207
password = m.groups()[0]
208208
return (jobNumber, password)
209209

210+
def getAvailableSolvers(self):
211+
"""Return a list of all NEOS solvers that this interface supports"""
212+
allKestrelSolvers = self.neos.listSolversInCategory("kestrel")
213+
_ampl = ':AMPL'
214+
return sorted(s[: -len(_ampl)] for s in allKestrelSolvers if s.endswith(_ampl))
215+
210216
def getSolverName(self):
211217
"""
212218
Read in the kestrel_options to pick out the solver name.
@@ -218,12 +224,7 @@ def getSolverName(self):
218224
219225
"""
220226
# Get a list of available kestrel solvers from NEOS
221-
allKestrelSolvers = self.neos.listSolversInCategory("kestrel")
222-
kestrelAmplSolvers = []
223-
for s in allKestrelSolvers:
224-
i = s.find(':AMPL')
225-
if i > 0:
226-
kestrelAmplSolvers.append(s[0:i])
227+
kestrelAmplSolvers = self.getAvailableSolvers()
227228
self.options = None
228229
# Read kestrel_options to get solver name
229230
if "kestrel_options" in os.environ:

pyomo/neos/tests/test_neos.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ def test_connection_failed(self):
9898
finally:
9999
pyomo.neos.kestrel.NEOS.host = orig_host
100100

101+
def test_check_all_ampl_solvers(self):
102+
kestrel = kestrelAMPL()
103+
solvers = kestrel.getAvailableSolvers()
104+
for solver in solvers:
105+
name = solver.lower().replace('-', '')
106+
if not hasattr(RunAllNEOSSolvers, 'test_' + name):
107+
self.fail(f"RunAllNEOSSolvers missing test for '{solver}'")
108+
101109

102110
class RunAllNEOSSolvers(object):
103111
def test_bonmin(self):
@@ -165,10 +173,10 @@ def test_ooqp(self):
165173
else:
166174
self._run('ooqp')
167175

168-
# The simple tests aren't complementarity
169-
# problems
170-
# def test_path(self):
171-
# self._run('path')
176+
def test_path(self):
177+
# The simple tests aren't complementarity
178+
# problems
179+
self.skipTest("The simple NEOS test is not a complementarity problem")
172180

173181
def test_snopt(self):
174182
self._run('snopt')

pyomo/opt/plugins/driver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def setup_test_parser(parser):
5050
def test_exec(options):
5151
import pyomo.solvers.tests.testcases
5252

53-
pyomo.solvers.tests.testcases.run_test_scenarios(options)
53+
pyomo.solvers.tests.testcases.run_scenarios(options)
5454

5555

5656
#

pyomo/solvers/tests/testcases.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def run_scenarios(options):
355355

356356
for key, test_case in generate_scenarios():
357357
model, solver, io = key
358-
if len(solvers) > 0 and not solver in solvers:
358+
if len(solvers) > 0 and solver not in solvers:
359359
continue
360360
if test_case.status == 'skip':
361361
continue
@@ -381,7 +381,7 @@ def run_scenarios(options):
381381
# Validate solution status
382382
try:
383383
model_class.post_solve_test_validation(None, results)
384-
except:
384+
except Exception:
385385
if test_case.status == 'expected failure':
386386
stat[key] = (True, "Expected failure")
387387
else:
@@ -431,7 +431,7 @@ def run_scenarios(options):
431431
total = Bunch(NumEPass=0, NumEFail=0, NumUPass=0, NumUFail=0)
432432
for key in stat:
433433
model, solver, io = key
434-
if not solver in summary:
434+
if solver not in summary:
435435
summary[solver] = Bunch(NumEPass=0, NumEFail=0, NumUPass=0, NumUFail=0)
436436
_pass, _str = stat[key]
437437
if _pass:

0 commit comments

Comments
 (0)