Skip to content
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
1 change: 1 addition & 0 deletions .github/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ extends:
IMAGE: auto
ISORT: true
COVERAGE: true
TIMEOUT_BUILD: 30
7 changes: 7 additions & 0 deletions pyoptsparse/pyNSGA2/pyNSGA2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

# Standard Python modules
import datetime
import os
import time

Expand Down Expand Up @@ -179,6 +180,12 @@ def objconfunc(nreal, nobj, ncon, x, f, g):
# fmt: on
optTime = time.time() - t0

if self.storeHistory:
self.metadata["endTime"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self.metadata["optTime"] = optTime
self.hist.writeData("metadata", self.metadata)
self.hist.close()

# Broadcast a -1 to indcate NSGA2 has finished
self.optProb.comm.bcast(-1, root=0)

Expand Down
4 changes: 3 additions & 1 deletion pyoptsparse/testing/pyOpt_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ def check_hist_file(self, tol):
hist = History(self.histFileName, flag="r")
# Metadata checks
metadata = hist.getMetadata()
self.assertEqual(metadata["optimizer"], self.optName)
# NSGA2's official name is NSGA-II
if self.optName != "NSGA2":
self.assertEqual(metadata["optimizer"], self.optName)
metadata_def_keys = [
"optName",
"optOptions",
Expand Down
20 changes: 15 additions & 5 deletions tests/test_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

# First party modules
from pyoptsparse import Optimization
from pyoptsparse.pyOpt_optimizer import Optimizers
from pyoptsparse.testing import OptTest

ALL_OPTIMIZERS = sorted({e.name for e in Optimizers} - {"ParOpt", "NSGA2"})


class TestSphere(OptTest):
## Solve unconstrained Sphere problem.
Expand Down Expand Up @@ -38,7 +41,7 @@ class TestSphere(OptTest):
xStar = {"xvars": np.zeros(N)}

# Tolerances
tol = {"ALPSO": 1e-3}
tol = {k: 5e-2 if k in ["CONMIN", "ALPSO", "NSGA2"] else 1e-6 for k in ALL_OPTIMIZERS}

optOptions = {
"ALPSO": { # sphere
Expand All @@ -48,7 +51,15 @@ class TestSphere(OptTest):
"c2": 1.25, # Social Parameter
"stopCriteria": 0, # 0: maxOuterIter, 1: convergence
"seed": 1235,
}
},
"NSGA2": { # not tested due to NSGA2 testing issues but option is kept here for reference
"PopSize": 32,
"maxGen": 100,
"seed": 123,
},
"SNOPT": {
"Major iterations limit": 10,
},
}

def objfunc(self, xdict):
Expand All @@ -63,8 +74,7 @@ def objfunc(self, xdict):
def sens(self, xdict, _funcs):
self.ng += 1
x = xdict["xvars"]

funcsSens = {"obj": {"xvars": 2 * np.ones(len(x))}}
funcsSens = {"obj": {"xvars": 2 * x}}

fail = False
return funcsSens, fail
Expand All @@ -83,7 +93,7 @@ def setup_optProb(self):
# Objective
self.optProb.addObj("obj")

@parameterized.expand(["ALPSO"])
@parameterized.expand(ALL_OPTIMIZERS)
def test_optimization(self, optName):
self.optName = optName
self.setup_optProb()
Expand Down
Loading