From 23a8f86fabbba30bfc5651fa34213378fa18564b Mon Sep 17 00:00:00 2001 From: Neil Wu Date: Tue, 15 Aug 2023 16:11:09 -0700 Subject: [PATCH 1/5] update docs for NSGA2 --- doc/install.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/install.rst b/doc/install.rst index 0cb472ff..4b1ea597 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -35,12 +35,7 @@ pyOptSparse has the following dependencies: Please make sure these are installed and available for use. In order to use NSGA2, SWIG (v1.3+) is also required, which can be installed via the package manager. -If those optimizers are not needed, then you do not need to install SWIG. -Simply comment out the corresponding lines in ``pyoptsparse/pyoptsparse/meson.build`` so that they are not compiled. -The corresponding lines in ``pyoptsparse/pyoptsparse/__init__.py`` must be commented out as well. - Python dependencies are automatically handled by ``pip``, so they do not need to be installed separately. -The only exception is ``numpy``, which is required as part of the build process and therefore must be present before installing. .. note:: * In Linux, the python header files (``python-dev``) are also required. From c94ac05841b9bee6828e347bbc2a1fa61168c745 Mon Sep 17 00:00:00 2001 From: Neil Wu Date: Tue, 15 Aug 2023 16:11:57 -0700 Subject: [PATCH 2/5] make nsga2 tests optional --- tests/test_nsga2_multi_objective.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_nsga2_multi_objective.py b/tests/test_nsga2_multi_objective.py index 0fe7f57a..e4f716f9 100644 --- a/tests/test_nsga2_multi_objective.py +++ b/tests/test_nsga2_multi_objective.py @@ -20,6 +20,13 @@ class TestNSGA2(OptTest): name = "quadratic" optName = "NSGA2" + def setUp(self): + try: + # First party modules + from pyoptsparse.pyNSGA2 import nsga2 # noqa: F401 + except ImportError: + raise unittest.SkipTest("Optimizer not available: NSGA2") + def objfunc(self, xdict): x = xdict["x"] y = xdict["y"] @@ -43,6 +50,9 @@ def setup_optProb(self, n_obj): if n_obj == 2: self.optProb.addObj("obj2") + @unittest.skipIf( + sys.platform == "win32", "test_nsga2_multi_objective.py fails on windows with two objectives! Skipping for now." + ) @parameterized.expand([(1,), (2,)]) def test_opt(self, n_obj): if n_obj == 2: @@ -51,11 +61,7 @@ def test_opt(self, n_obj): # 300 generations will find x=(0,0), 200 or less will find x=(1,1) optOptions = {"maxGen": 200} - if sys.platform == "win32": - warnings.warn( - "test_nsga2_multi_objective.py fails on windows with two objectives! Skipping for now.", stacklevel=2 - ) - return + sol = self.optimize(optOptions=optOptions) tol = 1e-2 if n_obj == 1: @@ -71,3 +77,6 @@ def test_opt(self, n_obj): if __name__ == "__main__": unittest.main() + unittest.main() + unittest.main() + unittest.main() From 283c21b4e51a7dbb83d93500009b8ef52c95ca98 Mon Sep 17 00:00:00 2001 From: Neil Wu Date: Tue, 15 Aug 2023 16:12:14 -0700 Subject: [PATCH 3/5] add an nsga2 test to rosenbrock --- tests/test_rosenbrock.py | 3 ++- tests/testing_utils.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_rosenbrock.py b/tests/test_rosenbrock.py index b590d605..b10615fb 100644 --- a/tests/test_rosenbrock.py +++ b/tests/test_rosenbrock.py @@ -50,6 +50,7 @@ class TestRosenbrock(OptTest): "CONMIN": 1e-9, "PSQP": 1e-8, "ParOpt": 1e-8, + "NSGA2": 1e-6, } optOptions = { "SLSQP": {"ACC": 1e-10}, @@ -146,7 +147,7 @@ def test_snopt_hotstart_starting_from_grad(self): # The first is from a call we deleted and the second is the call after 'last' self.assertEqual(self.ng, 2) - @parameterized.expand(["IPOPT", "SLSQP", "PSQP", "CONMIN", "NLPQLP", "ParOpt"]) + @parameterized.expand(["IPOPT", "SLSQP", "PSQP", "CONMIN", "NLPQLP", "ParOpt", "NSGA2"]) def test_optimization(self, optName): self.optName = optName if optName == "IPOPT" and sys.platform == "win32": diff --git a/tests/testing_utils.py b/tests/testing_utils.py index b0bccd73..9d5a8a55 100644 --- a/tests/testing_utils.py +++ b/tests/testing_utils.py @@ -61,7 +61,7 @@ def get_dict_distance(d, d2): } # these are optimizers which are installed by default -DEFAULT_OPTIMIZERS = {"SLSQP", "PSQP", "CONMIN", "ALPSO", "NSGA2"} +DEFAULT_OPTIMIZERS = {"SLSQP", "PSQP", "CONMIN", "ALPSO"} # Define gradient-based optimizers GRAD_BASED_OPTIMIZERS = {"CONMIN", "IPOPT", "NLPQLP", "ParOpt", "PSQP", "SLSQP", "SNOPT"} From ebd3e014ceadc6519b27d6cb694d0feab1a4f846 Mon Sep 17 00:00:00 2001 From: Neil Wu Date: Tue, 15 Aug 2023 17:28:14 -0700 Subject: [PATCH 4/5] fix tests --- tests/test_nsga2_multi_objective.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_nsga2_multi_objective.py b/tests/test_nsga2_multi_objective.py index e4f716f9..614ff187 100644 --- a/tests/test_nsga2_multi_objective.py +++ b/tests/test_nsga2_multi_objective.py @@ -3,7 +3,6 @@ # Standard Python modules import sys import unittest -import warnings # External modules from numpy.testing import assert_allclose @@ -19,6 +18,7 @@ class TestNSGA2(OptTest): name = "quadratic" optName = "NSGA2" + histFileName = None def setUp(self): try: @@ -77,6 +77,3 @@ def test_opt(self, n_obj): if __name__ == "__main__": unittest.main() - unittest.main() - unittest.main() - unittest.main() From 7391afb31df03492f2f96095bd541f9560ab8d38 Mon Sep 17 00:00:00 2001 From: Neil Wu Date: Wed, 16 Aug 2023 09:53:49 -0700 Subject: [PATCH 5/5] remove nsga2 from rosenbrock --- tests/test_rosenbrock.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_rosenbrock.py b/tests/test_rosenbrock.py index b10615fb..b590d605 100644 --- a/tests/test_rosenbrock.py +++ b/tests/test_rosenbrock.py @@ -50,7 +50,6 @@ class TestRosenbrock(OptTest): "CONMIN": 1e-9, "PSQP": 1e-8, "ParOpt": 1e-8, - "NSGA2": 1e-6, } optOptions = { "SLSQP": {"ACC": 1e-10}, @@ -147,7 +146,7 @@ def test_snopt_hotstart_starting_from_grad(self): # The first is from a call we deleted and the second is the call after 'last' self.assertEqual(self.ng, 2) - @parameterized.expand(["IPOPT", "SLSQP", "PSQP", "CONMIN", "NLPQLP", "ParOpt", "NSGA2"]) + @parameterized.expand(["IPOPT", "SLSQP", "PSQP", "CONMIN", "NLPQLP", "ParOpt"]) def test_optimization(self, optName): self.optName = optName if optName == "IPOPT" and sys.platform == "win32":