Skip to content

Commit 6278bca

Browse files
authored
Merge branch 'main' into fixNSGA2Bug
2 parents 2561d61 + 6c877b4 commit 6278bca

File tree

17 files changed

+117
-122
lines changed

17 files changed

+117
-122
lines changed

doc/install.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ If you plan to modify pyOptSparse, installing with the developer option, i.e. wi
6868
Some optimizers are proprietary, and their sources are not distributed with pyOptSparse.
6969
To use them, please follow the instructions on specific optimizer pages.
7070

71+
To see the list of installed optimizers, use the following:
72+
73+
.. prompt:: bash
74+
75+
python -c "import pyoptsparse; print(pyoptsparse.list_optimizers())"
76+
7177
Specifying compilers
7278
~~~~~~~~~~~~~~~~~~~~
7379
To specify a non-default compiler (e.g. something other than ``/usr/bin/gcc``), meson recognizes certain `special environment variables <https://mesonbuild.com/Reference-tables.html#compiler-and-linker-selection-variables>`__.

pyoptsparse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .pyOpt_constraint import Constraint
77
from .pyOpt_objective import Objective
88
from .pyOpt_optimization import Optimization
9-
from .pyOpt_optimizer import Optimizer, OPT, Optimizers
9+
from .pyOpt_optimizer import Optimizer, OPT, Optimizers, list_optimizers
1010
from .pyOpt_solution import Solution
1111

1212
# Now import all the individual optimizers

pyoptsparse/pyALPSO/pyALPSO.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
# Local modules
1414
from . import alpso
15-
from ..pyOpt_error import Error
1615
from ..pyOpt_optimizer import Optimizer
1716

1817
# isort: off
@@ -161,10 +160,10 @@ def objconfunc(x):
161160
self.setOption("minInnerIter", opt("maxInnerIter"))
162161

163162
if opt("stopCriteria") not in [0, 1]:
164-
raise Error("Incorrect Stopping Criteria Setting")
163+
raise ValueError("Incorrect Stopping Criteria Setting")
165164

166165
if opt("fileout") not in [0, 1, 2, 3]:
167-
raise Error("Incorrect fileout Setting")
166+
raise ValueError("Incorrect fileout Setting")
168167

169168
# Run ALPSO
170169
t0 = time.time()

pyoptsparse/pyCONMIN/pyCONMIN.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import numpy as np
1313

1414
# Local modules
15-
from ..pyOpt_error import Error
1615
from ..pyOpt_optimizer import Optimizer
1716
from ..pyOpt_utils import try_import_compiled_module_from_path
1817

@@ -194,7 +193,7 @@ def cnmngrad(n1, n2, x, f, g, ct, df, a, ic, nac):
194193
if self.getOption("IPRINT") >= 0 and self.getOption("IPRINT") <= 4:
195194
iprint = self.getOption("IPRINT")
196195
else:
197-
raise Error("IPRINT option must be >= 0 and <= 4")
196+
raise ValueError("IPRINT option must be >= 0 and <= 4")
198197

199198
iout = self.getOption("IOUT")
200199
ifile = self.getOption("IFILE")

pyoptsparse/pyNLPQLP/pyNLPQLP.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pyNLPQLP - A pyOptSparse wrapper for Schittkowski's NLPQLP
33
optimization algorithm.
44
"""
5+
56
# Standard Python modules
67
import datetime
78
import os
@@ -11,7 +12,6 @@
1112
import numpy as np
1213

1314
# Local modules
14-
from ..pyOpt_error import Error
1515
from ..pyOpt_optimizer import Optimizer
1616
from ..pyOpt_utils import try_import_compiled_module_from_path
1717

@@ -225,10 +225,10 @@ def nlgrad(m, me, mmax, n, f, g, df, dg, x, active, wa):
225225
d = np.zeros(nmax)
226226
go = self.getOption
227227
if go("iPrint") < 0 or go("iPrint") > 4:
228-
raise Error("Incorrect iPrint option. Must be >=0 and <= 4")
228+
raise ValueError("Incorrect iPrint option. Must be >=0 and <= 4")
229229

230230
if not (go("mode") >= 0 and go("mode") <= 18):
231-
raise Error("Incorrect mode option. Must be >= 0 and <= 18.")
231+
raise ValueError("Incorrect mode option. Must be >= 0 and <= 18.")
232232

233233
if os.path.isfile(go("iFile")):
234234
os.remove(go("iFile"))

pyoptsparse/pyNSGA2/pyNSGA2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import numpy as np
1212

1313
# Local modules
14-
from ..pyOpt_error import Error
1514
from ..pyOpt_optimizer import Optimizer
1615
from ..pyOpt_utils import try_import_compiled_module_from_path
1716

@@ -161,7 +160,7 @@ def objconfunc(nreal, nobj, ncon, x, f, g):
161160
if self.getOption("PrintOut") >= 0 and self.getOption("PrintOut") <= 2:
162161
printout = self.getOption("PrintOut")
163162
else:
164-
raise Error("Incorrect option PrintOut")
163+
raise ValueError("Incorrect option PrintOut")
165164

166165
seed = self.getOption("seed")
167166
if seed == 0:

pyoptsparse/pyOpt_constraint.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88

99
# Local modules
10-
from .pyOpt_error import Error, pyOptSparseWarning
10+
from .pyOpt_error import pyOptSparseWarning
1111
from .pyOpt_types import Dict1DType
1212
from .pyOpt_utils import INFINITY, _broadcast_to_array, convertToCOO
1313

@@ -204,7 +204,7 @@ def finalize(self, variables: OrderedDict, dvOffset, index: int):
204204
try:
205205
self.wrt = list(self.wrt)
206206
except Exception:
207-
raise Error(f"The 'wrt' argument to constraint '{self.name}' must be an iterable list")
207+
raise TypeError(f"The 'wrt' argument to constraint '{self.name}' must be an iterable list")
208208

209209
# We allow 'None' to be in the list...they are null so
210210
# just pop them out:
@@ -214,7 +214,7 @@ def finalize(self, variables: OrderedDict, dvOffset, index: int):
214214
# *actually* are variables
215215
for dvGroup in self.wrt:
216216
if dvGroup not in variables:
217-
raise Error(
217+
raise KeyError(
218218
f"The supplied dvGroup '{dvGroup}' in 'wrt' for the {self.name} constraint, does not exist. "
219219
+ "It must be added with a call to addVar() or addVarGroup()."
220220
)
@@ -254,7 +254,7 @@ def finalize(self, variables: OrderedDict, dvOffset, index: int):
254254
# sparse constraints.
255255

256256
if self.linear:
257-
raise Error(
257+
raise ValueError(
258258
"The 'jac' keyword to argument to addConGroup() must be supplied for a linear constraint. "
259259
+ f"The constraint in error is {self.name}."
260260
)
@@ -274,7 +274,7 @@ def finalize(self, variables: OrderedDict, dvOffset, index: int):
274274
else:
275275
# First sanitize input:
276276
if not isinstance(self.jac, dict):
277-
raise Error(
277+
raise TypeError(
278278
"The 'jac' keyword argument to addConGroup() must be a dictionary. "
279279
+ f"The constraint in error is {self.name}."
280280
)
@@ -301,7 +301,7 @@ def finalize(self, variables: OrderedDict, dvOffset, index: int):
301301

302302
# Generically check the shape:
303303
if self.jac[dvGroup]["shape"][0] != self.ncon or self.jac[dvGroup]["shape"][1] != ndvs:
304-
raise Error(
304+
raise ValueError(
305305
f"The supplied Jacobian for dvGroup {dvGroup}' in constraint {self.name}, was the incorrect size. "
306306
+ f"Expecting a Jacobian of size ({self.ncon}, {ndvs}) but received a Jacobian of size "
307307
+ f"({self.jac[dvGroup]['shape'][0]}, {self.jac[dvGroup]['shape'][1]})."

pyoptsparse/pyOpt_error.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,6 @@
55
"""
66

77

8-
class Error(Exception):
9-
"""
10-
Format the error message in a box to make it clear this
11-
was a expliclty raised exception.
12-
"""
13-
14-
def __init__(self, message):
15-
msg = "\n+" + "-" * 78 + "+" + "\n" + "| pyOptSparse Error: "
16-
i = 21
17-
for word in message.split():
18-
if len(word) + i + 1 > 78: # Finish line and start new one
19-
msg += " " * (79 - i) + "|\n| " + word + " "
20-
i = 2 + len(word) + 1
21-
else:
22-
msg += word + " "
23-
i += len(word) + 1
24-
msg += " " * (79 - i) + "|\n" + "+" + "-" * 78 + "+" + "\n"
25-
print(msg)
26-
self.message = message
27-
super().__init__(message)
28-
29-
def __str__(self):
30-
return self.message
31-
32-
338
class pyOptSparseWarning:
349
"""
3510
Format a warning message

pyoptsparse/pyOpt_history.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sqlitedict import SqliteDict
99

1010
# Local modules
11-
from .pyOpt_error import Error, pyOptSparseWarning
11+
from .pyOpt_error import pyOptSparseWarning
1212
from .pyOpt_utils import EPS
1313

1414

@@ -53,7 +53,7 @@ def __init__(self, fileName, optProb=None, temp=False, flag="r"):
5353
)
5454
self._processDB()
5555
else:
56-
raise Error("The flag argument to History must be 'r' or 'n'.")
56+
raise ValueError("The flag argument to History must be 'r' or 'n'.")
5757
self.temp = temp
5858
self.fileName = fileName
5959

@@ -578,7 +578,7 @@ def getValues(self, names=None, callCounters=None, major=True, scale=False, stac
578578
allNames.add("xuser")
579579
# error if names isn't either a DV, con or obj
580580
if not names.issubset(allNames):
581-
raise Error(
581+
raise KeyError(
582582
"The names provided are not one of DVNames, conNames or objNames.\n"
583583
+ f"The names must be a subset of {allNames}"
584584
)

0 commit comments

Comments
 (0)