From fc4bf437bc6ba5919bebed55ef24f95a77a80aa2 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Tue, 2 Apr 2024 10:26:48 -0600 Subject: [PATCH 1/5] Skip test under CyIpopt 1.4.0 --- .../contrib/pynumero/examples/tests/test_cyipopt_examples.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py index 408a0197382..bcd3b5d8bf5 100644 --- a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py +++ b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py @@ -266,6 +266,11 @@ def test_cyipopt_functor(self): s = df['ca_bal'] self.assertAlmostEqual(s.iloc[6], 0, places=3) + @unittest.skipIf( + cyipopt_core.__version__ == "1.4.0", + "Terminating Ipopt through a user callback is broken in CyIpopt 1.4.0 " + "(see mechmotum/cyipopt#249", + ) def test_cyipopt_callback_halt(self): ex = import_file( os.path.join(example_dir, 'callback', 'cyipopt_callback_halt.py') From 38d49d43293c45f50ccfbc9fbe7e3d57ed638a03 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Tue, 2 Apr 2024 10:27:20 -0600 Subject: [PATCH 2/5] Fix bug in retrieving cyipopt version --- .../contrib/pynumero/algorithms/solvers/cyipopt_solver.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyomo/contrib/pynumero/algorithms/solvers/cyipopt_solver.py b/pyomo/contrib/pynumero/algorithms/solvers/cyipopt_solver.py index cdea542295b..53616298415 100644 --- a/pyomo/contrib/pynumero/algorithms/solvers/cyipopt_solver.py +++ b/pyomo/contrib/pynumero/algorithms/solvers/cyipopt_solver.py @@ -319,7 +319,13 @@ def license_is_valid(self): return True def version(self): - return tuple(int(_) for _ in cyipopt.__version__.split(".")) + def _int(x): + try: + return int(x) + except: + return x + + return tuple(_int(_) for _ in cyipopt_interface.cyipopt.__version__.split(".")) def solve(self, model, **kwds): config = self.config(kwds, preserve_implicit=True) From c74427aeee68050d21c7d80929f9a1d440253c26 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Tue, 2 Apr 2024 10:27:43 -0600 Subject: [PATCH 3/5] Fix import from a deprecated location --- .../contrib/pynumero/examples/tests/test_cyipopt_examples.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py index bcd3b5d8bf5..55dccd6a0ed 100644 --- a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py +++ b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py @@ -44,11 +44,13 @@ raise unittest.SkipTest("Pynumero needs the ASL extension to run CyIpopt tests") import pyomo.contrib.pynumero.algorithms.solvers.cyipopt_solver as cyipopt_solver +from pyomo.contrib.pynumero.interfaces.cyipopt_interface import cyipopt_available -if not cyipopt_solver.cyipopt_available: +if not cyipopt_available: raise unittest.SkipTest("PyNumero needs CyIpopt installed to run CyIpopt tests") import cyipopt as cyipopt_core + example_dir = os.path.join(this_file_dir(), '..') From 55c78059667d5412df28cab3dd0905e66aa197da Mon Sep 17 00:00:00 2001 From: John Siirola Date: Tue, 2 Apr 2024 10:35:02 -0600 Subject: [PATCH 4/5] NFC: fix a message typo --- pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py index 55dccd6a0ed..a0e17df918a 100644 --- a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py +++ b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py @@ -271,7 +271,7 @@ def test_cyipopt_functor(self): @unittest.skipIf( cyipopt_core.__version__ == "1.4.0", "Terminating Ipopt through a user callback is broken in CyIpopt 1.4.0 " - "(see mechmotum/cyipopt#249", + "(see mechmotum/cyipopt#249)", ) def test_cyipopt_callback_halt(self): ex = import_file( From 50e2316be4d928694efb53fb11ea94546ee24e9f Mon Sep 17 00:00:00 2001 From: John Siirola Date: Tue, 2 Apr 2024 10:38:37 -0600 Subject: [PATCH 5/5] Use our version() method to test cyipopt version --- pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py index a0e17df918a..2df43c1e797 100644 --- a/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py +++ b/pyomo/contrib/pynumero/examples/tests/test_cyipopt_examples.py @@ -269,7 +269,7 @@ def test_cyipopt_functor(self): self.assertAlmostEqual(s.iloc[6], 0, places=3) @unittest.skipIf( - cyipopt_core.__version__ == "1.4.0", + cyipopt_solver.PyomoCyIpoptSolver().version() == (1, 4, 0), "Terminating Ipopt through a user callback is broken in CyIpopt 1.4.0 " "(see mechmotum/cyipopt#249)", )