Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nsga2 tests optional + docs update #351

Merged
merged 5 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry to have checked this too late @nwu63 , but I don't really get the point of this step here. Can't we remove this altogether? We are already skipping all n_obj == 2 tests by default on all platforms. Is this related to an additional test that testflo runs on windows?
Locally I only have the last two tests of this stack:

about to run test_nsga2_multi_objective.py:TestNSGA2.test_opt .\test_nsga2_multi_objective.py:TestNSGA2.test_opt  ... SKIP (00:00:0.00, 0 MB)
test_nsga2_multi_objective.py fails on windows with two objectives! Skipping for now.
    about to run test_nsga2_multi_objective.py:TestNSGA2.test_opt_0 .\test_nsga2_multi_objective.py:TestNSGA2.test_opt_0 ... OK (00:00:4.17, 0 MB)
    about to run test_nsga2_multi_objective.py:TestNSGA2.test_opt_1 .\test_nsga2_multi_objective.py:TestNSGA2.test_opt_1  ... SKIP (00:00:0.00, 0 MB)
skip flaky NSGA2 tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This skips all tests on Windows, the below skips all multiobjective tests, so the only tests being run are the single-objective tests on linux.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the idea (and that is what I was expecting) but that printout in my comment is from the Windows test log - apparently the single-objective test is running on Windows? Or is it a Testflo fluke?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that the skipIf doesn't play nicely with parameterized. However this is actually what we want---the single objective test should pass on Windows and we should test it, while the multi-objective test appears to be flat out broken. Let me throw together a PR to update this.

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
Loading