From 728873e3778bec9786fe1be4ceddca1052da6cff Mon Sep 17 00:00:00 2001 From: Florian Maurer Date: Wed, 20 Nov 2024 14:46:48 +0100 Subject: [PATCH 1/7] fix running pyomo test-solvers --- pyomo/opt/plugins/driver.py | 2 +- pyomo/solvers/tests/testcases.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyomo/opt/plugins/driver.py b/pyomo/opt/plugins/driver.py index c7c7103835c..beaf5268fe9 100644 --- a/pyomo/opt/plugins/driver.py +++ b/pyomo/opt/plugins/driver.py @@ -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) # diff --git a/pyomo/solvers/tests/testcases.py b/pyomo/solvers/tests/testcases.py index 6bef40818d9..f0ea27136b6 100644 --- a/pyomo/solvers/tests/testcases.py +++ b/pyomo/solvers/tests/testcases.py @@ -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 @@ -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: @@ -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: From d324c2a9df4babf19b4912e0e5dad386187e4bc5 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Thu, 21 Nov 2024 11:04:06 -0700 Subject: [PATCH 2/7] Move logic for getting list of NEOS solvers to public method --- pyomo/neos/kestrel.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyomo/neos/kestrel.py b/pyomo/neos/kestrel.py index 7c1518fe06f..fda862903ce 100644 --- a/pyomo/neos/kestrel.py +++ b/pyomo/neos/kestrel.py @@ -207,6 +207,12 @@ def getJobAndPassword(self): password = m.groups()[0] return (jobNumber, password) + def getAvailableSolvers(self): + """Return a list of all NNEOS 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. @@ -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: From 2915c0814b65c869c9d62281469fe2e7ad63271a Mon Sep 17 00:00:00 2001 From: John Siirola Date: Thu, 21 Nov 2024 11:04:23 -0700 Subject: [PATCH 3/7] Add test to check that we are testing ALL of the NEOS solvers --- pyomo/neos/tests/test_neos.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyomo/neos/tests/test_neos.py b/pyomo/neos/tests/test_neos.py index f14600fdb84..004ed15ff03 100644 --- a/pyomo/neos/tests/test_neos.py +++ b/pyomo/neos/tests/test_neos.py @@ -98,6 +98,13 @@ def test_connection_failed(self): finally: pyomo.neos.kestrel.NEOS.host = orig_host + def test_check_all_ampl_solvers(self): + kestrel = kestrelAMPL() + solvers = kestrelAMPL.getAvailableSolvers() + for solver in solvers: + if not hasattr(RunAllNEOSSolvers, 'test_' + solver.lower()): + self.fail("RunAllNEOSSolvers missing test for '{solver}'") + class RunAllNEOSSolvers(object): def test_bonmin(self): From 52ef915ce0e37db7e3d153fa57bf9df23508bfee Mon Sep 17 00:00:00 2001 From: John Siirola Date: Thu, 21 Nov 2024 11:14:52 -0700 Subject: [PATCH 4/7] Fix logic for identifying NEOS solvers --- pyomo/neos/kestrel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/neos/kestrel.py b/pyomo/neos/kestrel.py index fda862903ce..ced76c7d06a 100644 --- a/pyomo/neos/kestrel.py +++ b/pyomo/neos/kestrel.py @@ -211,7 +211,7 @@ def getAvailableSolvers(self): """Return a list of all NNEOS 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)) + return sorted(s[: -len(_ampl)] for s in allKestrelSolvers if s.endswith(_ampl)) def getSolverName(self): """ From 8e3032faacef0c4ad1d64f9888fa815841df3de6 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Thu, 21 Nov 2024 11:15:22 -0700 Subject: [PATCH 5/7] Update test for verifying we are testing all NEOS solvers --- pyomo/neos/tests/test_neos.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pyomo/neos/tests/test_neos.py b/pyomo/neos/tests/test_neos.py index 004ed15ff03..21b5b818138 100644 --- a/pyomo/neos/tests/test_neos.py +++ b/pyomo/neos/tests/test_neos.py @@ -100,10 +100,11 @@ def test_connection_failed(self): def test_check_all_ampl_solvers(self): kestrel = kestrelAMPL() - solvers = kestrelAMPL.getAvailableSolvers() + solvers = kestrel.getAvailableSolvers() for solver in solvers: - if not hasattr(RunAllNEOSSolvers, 'test_' + solver.lower()): - self.fail("RunAllNEOSSolvers missing test for '{solver}'") + name = solver.lower().replace('-', '') + if not hasattr(RunAllNEOSSolvers, 'test_' + name): + self.fail(f"RunAllNEOSSolvers missing test for '{solver}'") class RunAllNEOSSolvers(object): @@ -172,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.skip("The simple NEOS test is not a complementarity problem") def test_snopt(self): self._run('snopt') From 37c97c8404f044c766d6fd06fe9d58d63a8df674 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Thu, 21 Nov 2024 11:20:22 -0700 Subject: [PATCH 6/7] Fix typo in test driver --- pyomo/neos/tests/test_neos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/neos/tests/test_neos.py b/pyomo/neos/tests/test_neos.py index 21b5b818138..f55afb10439 100644 --- a/pyomo/neos/tests/test_neos.py +++ b/pyomo/neos/tests/test_neos.py @@ -176,7 +176,7 @@ def test_ooqp(self): def test_path(self): # The simple tests aren't complementarity # problems - self.skip("The simple NEOS test is not a complementarity problem") + self.skipTest("The simple NEOS test is not a complementarity problem") def test_snopt(self): self._run('snopt') From eb888cbe97fe050d8d093b49d67f46eb29069d7f Mon Sep 17 00:00:00 2001 From: John Siirola Date: Thu, 21 Nov 2024 14:36:19 -0700 Subject: [PATCH 7/7] NFC: fix typo Co-authored-by: Bethany Nicholson --- pyomo/neos/kestrel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/neos/kestrel.py b/pyomo/neos/kestrel.py index ced76c7d06a..c917a6fe7d1 100644 --- a/pyomo/neos/kestrel.py +++ b/pyomo/neos/kestrel.py @@ -208,7 +208,7 @@ def getJobAndPassword(self): return (jobNumber, password) def getAvailableSolvers(self): - """Return a list of all NNEOS solvers that this interface supports""" + """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))