Skip to content

Commit

Permalink
Switch to using BaseSolver (#193)
Browse files Browse the repository at this point in the history
* switched to using BaseSolver

* updated setup.py

* updated init

* added checkDefaultOptions

* fixed default option type

* updated default SNOPT options

* renamed def_options

* more overhaul of pySNOPT

* removed very old numpy warning

* added back on set/get options since those are mandatory

* updated init API

* made IPOPT also not use default options list

* bump baseclasses version

* renamed optimizer pages due to sphinx being weird

* added autodoc mock import for baseclasses

* updated capitalization in SNOPT

* fixed bug in ALPSO

* updated _on_setOption etc.

* updated SNOPT doc

* bump baseclasses version

* version bump

* addressed comments
  • Loading branch information
ewu63 authored Jan 11, 2021
1 parent 09f11d2 commit 1c2bc25
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 599 deletions.
3 changes: 3 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions.extend(["numpydoc", "ext.optimizertable"])

# mock import for autodoc
autodoc_mock_imports = ["baseclasses"]
18 changes: 9 additions & 9 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ To get started, please see the :ref:`install` and the :ref:`quickstart`.
:caption: Optimizers
:hidden:

optimizers/pysnopt
optimizers/pyipopt
optimizers/pyslsqp
optimizers/pynlpqlp
optimizers/pynsga2
optimizers/pypsqp
optimizers/pyparopt
optimizers/pyconmin
optimizers/pyalpso
optimizers/SNOPT
optimizers/IPOPT
optimizers/SLSQP
optimizers/NLPQLP
optimizers/NSGA2
optimizers/PSQP
optimizers/ParOpt
optimizers/CONMIN
optimizers/ALPSO
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions doc/optimizers/pyipopt.rst → doc/optimizers/IPOPT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ Here we explain a basic setup using MUMPS as the linear solver, together with ME

Options
-------
Please refer to the `IPOPT website <https://coin-or.github.io/Ipopt/OPTIONS.html>`__ for complete listing of options.
The following are the options which are set by default within pyOptSparse.
All other options take the default value with IPOPT unless specified by the user.

.. optimizertable:: pyoptsparse.pyIPOPT.pyIPOPT.IPOPT
:type: options

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions doc/optimizers/pysnopt.rst → doc/optimizers/SNOPT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ The current version of SNOPT being tested is v7.7.5, although v7.7.1 is also exp

Options
-------
The default values come directly from SNOPT, which is why they are not displayed in the table below.
Please refer to the user manual for those options.
Note that there are two key differences:
Please refer to the SNOPT user manual for a complete listing of options and their default values.
The following are the options set in Python for the wrapper.

- The SNOPT option ``Proximal iterations limit`` has its default value changed to 10000, in order to fully solve the proximal point problem to optimality
- The option ``Save major iteration variables`` is unique to the Python wrapper, and takes a list of values which can be saved at each iteration to the History file.
Expand All @@ -40,10 +39,10 @@ Note that there are two key differences:
- ``slack``
- ``lambda``
- ``condZHZ``
- The option ``Start`` corresponds to the value directly passed to the SNOPT kernel, and will be overwritten if another option, e.g. ``Cold start`` is supplied.

.. optimizertable:: pyoptsparse.pySNOPT.pySNOPT.SNOPT
:type: options
:nodefvalues:


Informs
Expand Down
2 changes: 1 addition & 1 deletion pyoptsparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.3.0"
__version__ = "2.4.0"

from .pyOpt_history import History
from .pyOpt_variable import Variable
Expand Down
17 changes: 4 additions & 13 deletions pyoptsparse/pyALPSO/pyALPSO.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ALPSO(Optimizer):
- pll_type -> STR: ALPSO Parallel Implementation (None, SPM- Static, DPM- Dynamic, POA-Parallel Analysis), *Default* = None
"""

def __init__(self, *args, **kwargs):
def __init__(self, raiseError=True, options={}):

from . import alpso

Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(self, *args, **kwargs):
str,
"ALPSO.out",
], # We could probably remove fileout flag if filename or fileinstance is given
"seed": [float, 0], # Random Number Seed (0 - Auto-Seed based on time clock)
"seed": [int, 0], # Random Number Seed (0 - Auto-Seed based on time clock)
"HoodSize": [int, 40], # Number of Neighbours of Each Particle
"HoodModel": [
str,
Expand All @@ -92,10 +92,10 @@ def __init__(self, *args, **kwargs):
1,
], # Selfless Neighbourhood Model (0 - Include Particle i in NH i, 1 - Don't Include Particle i)
"Scaling": [int, 1], # Design Variables Scaling Flag (0 - no scaling, 1 - scaling between [-1, 1])
"parallelType": [str, ""], # Type of parallelization ('' or 'EXT')
"parallelType": [str, ["", "EXT"]], # Type of parallelization ('' or 'EXT')
}
self.informs = {}
Optimizer.__init__(self, "ALPSO", category, self.defOpts, self.informs, *args, **kwargs)
super().__init__("ALPSO", category, defaultOptions=self.defOpts, informs=self.informs, options=options)

def __call__(self, optProb, storeHistory=None, **kwargs):
"""
Expand Down Expand Up @@ -172,9 +172,6 @@ def objconfunc(x):
if opt("fileout") not in [0, 1, 2, 3]:
raise Error("Incorrect fileout Setting")

if opt("seed") == 0:
self.setOption("seed", time.time())

# Run ALPSO
t0 = time.time()
# fmt: off
Expand Down Expand Up @@ -223,12 +220,6 @@ def _on_setOption(self, name, value):
except ImportError:
raise ImportError("pyALPSO: ALPSO EXT shared library failed to import.")

else:
raise ValueError("parallel_type must be either '' or 'EXT'.")

def _on_getOption(self, name, value):
pass

def _communicateSolution(self, sol):
if sol is not None:
sol.userObjCalls = self.optProb.comm.allreduce(sol.userObjCalls)
Expand Down
12 changes: 3 additions & 9 deletions pyoptsparse/pyCONMIN/pyCONMIN.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class CONMIN(Optimizer):
CONMIN Optimizer Class - Inherited from Optimizer Abstract Class
"""

def __init__(self, raiseError=True, *args, **kwargs):
def __init__(self, raiseError=True, options={}):
name = "CONMIN"
category = "Local Optimizer"
self.defOpts = {
"ITMAX": [int, 1e4], # Maximum Number of Iterations
"ITMAX": [int, int(1e4)], # Maximum Number of Iterations
"DELFUN": [float, 1e-6], # Objective Relative Tolerance
"DABFUN": [float, 1e-6], # Objective Absolute Tolerance
"ITRM": [int, 5],
Expand All @@ -55,7 +55,7 @@ def __init__(self, raiseError=True, *args, **kwargs):
raise Error("There was an error importing the compiled conmin module")

self.set_options = []
Optimizer.__init__(self, name, category, self.defOpts, self.informs, *args, **kwargs)
super().__init__(name, category, defaultOptions=self.defOpts, informs=self.informs, options=options)

# CONMIN needs Jacobians in dense format
self.jacType = "dense2d"
Expand Down Expand Up @@ -260,9 +260,3 @@ def cnmngrad(n1, n2, x, f, g, ct, df, a, ic, nac):
sol = self._communicateSolution(sol)

return sol

def _on_setOption(self, name, value):
pass

def _on_getOption(self, name, value):
pass
Loading

0 comments on commit 1c2bc25

Please sign in to comment.