Skip to content

Commit 61d8b83

Browse files
ewu63kanekosh
andauthored
Make swig mandatory and therefore NSGA2 a default optimizer (#435)
* make swig mandatory and therefore nsga2 a default optimizer * make wrapper raise error * missing quote * do not skip nsga2 tests * version bump * flake8 --------- Co-authored-by: Shugo Kaneko <49300827+kanekosh@users.noreply.github.com>
1 parent 3b50b66 commit 61d8b83

File tree

8 files changed

+37
-49
lines changed

8 files changed

+37
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ALPSO, CONMIN, IPOPT, NLPQLP, NSGA2, PSQP, SLSQP, ParOpt and SNOPT are currently
2323

2424
We do not provide the source code for SNOPT and NLPQLP, due to their restrictive license requirements.
2525
Please contact the authors of the respective optimizers if you wish to obtain them.
26-
Furthermore, ParOpt and IPOPT are available as a open source package but must be installed separately.
26+
Furthermore, ParOpt and IPOPT are available as open source packages but must be installed separately.
2727
Please see the documentation page of each optimizer for purchase and installation instructions.
2828

2929
## Integration into other frameworks

doc/install.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pyOptSparse has the following dependencies:
3434
We recommend ``gcc`` and ``gfortran`` which can be installed via the package manager for your operating system.
3535

3636
Please make sure these are installed and available for use.
37-
In order to use NSGA2, SWIG (v1.3+) is also required, which can be installed via the package manager.
3837
Python dependencies are automatically handled by ``pip``, so they do not need to be installed separately.
3938

4039
.. note::

pyoptsparse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.13.1"
1+
__version__ = "2.13.2"
22

33
from .pyOpt_history import History
44
from .pyOpt_variable import Variable

pyoptsparse/pyNSGA2/meson.build

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
1-
swig = find_program('swig', required: false)
1+
swig = find_program('swig', required: true)
22

3-
if swig.found()
4-
nsga2_source = custom_target('nsga2_wrap.c',
5-
input : ['source/swig/nsga2.i'],
6-
output : ['nsga2_wrap.c'],
7-
command: ['swig', '-o', 'pyoptsparse/pyNSGA2/nsga2_wrap.c', '-python', '-interface', 'nsga2', '@INPUT@']
8-
)
3+
nsga2_source = custom_target('nsga2_wrap.c',
4+
input : ['source/swig/nsga2.i'],
5+
output : ['nsga2_wrap.c'],
6+
command: ['swig', '-o', 'pyoptsparse/pyNSGA2/nsga2_wrap.c', '-python', '-interface', 'nsga2', '@INPUT@']
7+
)
98

10-
py3_target.extension_module('nsga2',
11-
'source/allocate.c',
12-
'source/auxiliary.c',
13-
'source/crossover.c',
14-
'source/crowddist.c',
15-
'source/decode.c',
16-
'source/dominance.c',
17-
'source/eval.c',
18-
'source/fillnds.c',
19-
'source/initialize.c',
20-
'source/list.c',
21-
'source/merge.c',
22-
'source/mutation.c',
23-
'source/nsga2.c',
24-
'source/rand.c',
25-
'source/rank.c',
26-
'source/report.c',
27-
'source/sort.c',
28-
'source/tourselect.c',
29-
nsga2_source,
30-
include_directories: 'source',
31-
dependencies : py3_dep,
32-
subdir: 'pyoptsparse/pyNSGA2',
33-
link_language: 'c',
34-
install : false)
35-
else
36-
message('SWIG was not found, therefore NSGA2 will not be built.')
37-
endif
9+
py3_target.extension_module('nsga2',
10+
'source/allocate.c',
11+
'source/auxiliary.c',
12+
'source/crossover.c',
13+
'source/crowddist.c',
14+
'source/decode.c',
15+
'source/dominance.c',
16+
'source/eval.c',
17+
'source/fillnds.c',
18+
'source/initialize.c',
19+
'source/list.c',
20+
'source/merge.c',
21+
'source/mutation.c',
22+
'source/nsga2.c',
23+
'source/rand.c',
24+
'source/rank.c',
25+
'source/report.c',
26+
'source/sort.c',
27+
'source/tourselect.c',
28+
nsga2_source,
29+
include_directories: 'source',
30+
dependencies : py3_dep,
31+
subdir: 'pyoptsparse/pyNSGA2',
32+
link_language: 'c',
33+
install : false)
3834

3935
#python_sources = [
4036
# '__init__.py',

pyoptsparse/pyNSGA2/pyNSGA2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# import the compiled module
1818
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
19-
nsga2 = try_import_compiled_module_from_path("nsga2", THIS_DIR)
19+
nsga2 = try_import_compiled_module_from_path("nsga2", THIS_DIR, raise_warning=True)
2020

2121

2222
class NSGA2(Optimizer):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build-system]
2-
requires = ["setuptools>=42", "meson>=0.60.0", "ninja", "numpy>=2.0"]
2+
requires = ["setuptools>=42", "meson>=0.60.0", "ninja", "numpy>=2.0", "swig"]
33
build-backend = "setuptools.build_meta"

tests/test_nsga2_multi_objective.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Test NSGA2."""
1+
"""Test NSGA2."""
22

33
# Standard Python modules
44
import unittest
@@ -19,13 +19,6 @@ class TestNSGA2(OptTest):
1919
optName = "NSGA2"
2020
histFileName = None
2121

22-
def setUp(self):
23-
try:
24-
# First party modules
25-
from pyoptsparse.pyNSGA2 import nsga2 # noqa: F401
26-
except ImportError:
27-
raise unittest.SkipTest("Optimizer not available: NSGA2")
28-
2922
def objfunc(self, xdict):
3023
x = xdict["x"]
3124
y = xdict["y"]

tests/testing_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_dict_distance(d, d2):
5959
}
6060

6161
# these are optimizers which are installed by default
62-
DEFAULT_OPTIMIZERS = {"SLSQP", "PSQP", "CONMIN", "ALPSO"}
62+
DEFAULT_OPTIMIZERS = {"SLSQP", "PSQP", "CONMIN", "ALPSO", "NSGA2"}
6363

6464
# Define gradient-based optimizers
6565
GRAD_BASED_OPTIMIZERS = {"CONMIN", "IPOPT", "NLPQLP", "ParOpt", "PSQP", "SLSQP", "SNOPT"}

0 commit comments

Comments
 (0)