Skip to content

Commit

Permalink
Make nsga2 tests optional + docs update (#351)
Browse files Browse the repository at this point in the history
* update docs for NSGA2

* make nsga2 tests optional

* add an nsga2 test to rosenbrock

* fix tests

* remove nsga2 from rosenbrock
  • Loading branch information
ewu63 authored Aug 22, 2023
1 parent 7e01f2c commit 304177c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
5 changes: 0 additions & 5 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 12 additions & 6 deletions tests/test_nsga2_multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Standard Python modules
import sys
import unittest
import warnings

# External modules
from numpy.testing import assert_allclose
Expand All @@ -19,6 +18,14 @@
class TestNSGA2(OptTest):
name = "quadratic"
optName = "NSGA2"
histFileName = None

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"]
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit 304177c

Please sign in to comment.