Skip to content

Commit

Permalink
Updated informs (#138)
Browse files Browse the repository at this point in the history
* updated informs for all optimizers, and also added tests

* removed IPOPT copying in travis since it is compiled separately now

* Delete opt_hist.hst

The file is too old to be relevant, there is no need to provide a history file in the repo.
  • Loading branch information
ewu63 authored Jul 10, 2020
1 parent 4f14c19 commit 772566c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 26 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ env:
- DOCKER_MOUNT_DIR=/home/mdolabuser/travis/$REPO_NAME
- SNOPT_DIR=$DOCKER_WORKING_DIR/pyoptsparse/pySNOPT/source
- NLPQLP_DIR=$DOCKER_WORKING_DIR/pyoptsparse/pyNLPQLP/source
- IPOPT_DIR=$DOCKER_WORKING_DIR/pyoptsparse/pyIPOPT/Ipopt
jobs:
- DOCKER_TAG=py2-latest
- DOCKER_TAG=py3-stable
Expand All @@ -43,7 +42,7 @@ before_install:
install:
# We back up the proprietary source codes first
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker exec -it app /bin/bash -c "cp -r $SNOPT_DIR \$HOME/SNOPT && cp -r $NLPQLP_DIR \$HOME/NLPQLP && cp -r $IPOPT_DIR \$HOME/IPOPT";
docker exec -it app /bin/bash -c "cp -r $SNOPT_DIR \$HOME/SNOPT && cp -r $NLPQLP_DIR \$HOME/NLPQLP";
fi
# We thrown away the existing repo in Docker, and copy the new one in-place
- docker exec -it app /bin/bash -c "rm -rf $DOCKER_WORKING_DIR && cp -r $DOCKER_MOUNT_DIR $DOCKER_WORKING_DIR"
Expand All @@ -52,7 +51,7 @@ install:
- docker exec -it app /bin/bash -c ". \$HOME/.bashrc_mdolab && pip install testflo==1.3.5"
# Copy back the proprietary codes
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker exec -it app /bin/bash -c "cp -r \$HOME/NLPQLP/* $NLPQLP_DIR/ && cp -r \$HOME/SNOPT/* $SNOPT_DIR/ && cp -r \$HOME/IPOPT/ $IPOPT_DIR";
docker exec -it app /bin/bash -c "cp -r \$HOME/NLPQLP/* $NLPQLP_DIR/ && cp -r \$HOME/SNOPT/* $SNOPT_DIR/";
fi
# Build and install
- docker exec -it app /bin/bash -c ". \$HOME/.bashrc_mdolab && cd $DOCKER_WORKING_DIR && pip install -e ."
Expand Down
Binary file removed postprocessing/opt_hist.hst
Binary file not shown.
8 changes: 5 additions & 3 deletions pyoptsparse/pyNLPQLP/pyNLPQLP.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(self, raiseError=True, *args, **kwargs):
8: "The starting point violates a lower or upper bound.",
9: "Wrong input parameter, i.e., MODE, LDL decomposition in D and C (in case of MODE=1), IPRINT, IOUT",
10: "Internal inconsistency of the quadratic subproblem, division by zero.",
11: "More than MAXFUN successive non-evaluable function calls.",
100: (
"The solution of the quadratic programming subproblem has been"
+ " terminated with an error message and IFAIL is set to IFQL+100,"
Expand Down Expand Up @@ -236,7 +237,7 @@ def nlgrad(m, me, mmax, n, f, g, df, dg, x, active, wa):

if os.path.isfile(go("iFile")):
os.remove(go("iFile"))
ifail = 0
ifail = np.array(0, dtype=int)
# Run NLPQL
t0 = time.time()
# fmt: off
Expand All @@ -259,9 +260,10 @@ def nlgrad(m, me, mmax, n, f, g, df, dg, x, active, wa):
self.hist.close()

# Store Results
inform = np.asscalar(ifail)
sol_inform = {}
# sol_inform['value'] = inform
# sol_inform['text'] = self.informs[inform[0]]
sol_inform["value"] = inform
sol_inform["text"] = self.informs[inform]

# Create the optimization solution
sol = self._createSolution(optTime, sol_inform, ff, xs)
Expand Down
7 changes: 4 additions & 3 deletions pyoptsparse/pyPSQP/pyPSQP.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def pdcon(n, k, x, dg):
return dg

# Setup argument list values
iterm = 0
iterm = np.array(0, int)
gmax = 0.0
cmax = 0.0
opt = self.getOption
Expand Down Expand Up @@ -255,9 +255,10 @@ def pdcon(n, k, x, dg):
self.optProb.comm.bcast(-1, root=0)

# Store Results
inform = np.asscalar(iterm)
sol_inform = {}
# sol_inform['value'] = inform
# sol_inform['text'] = self.informs[inform[0]]
sol_inform["value"] = inform
sol_inform["text"] = self.informs[inform]
if self.storeHistory:
self.metadata["endTime"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self.metadata["optTime"] = optTime
Expand Down
7 changes: 4 additions & 3 deletions pyoptsparse/pySLSQP/pySLSQP.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def slgrad(m, me, la, n, f, g, df, dg, x):
if os.path.isfile(ifile):
os.remove(ifile)

mode = 0
mode = np.array(0, int)
mineq = m - meq + 2 * (n + 1)
lsq = (n + 1) * ((n + 1) + 1) + meq * ((n + 1) + 1) + mineq * ((n + 1) + 1)
lsi = ((n + 1) - meq + 1) * (mineq + 2) + 2 * mineq
Expand Down Expand Up @@ -257,9 +257,10 @@ def slgrad(m, me, la, n, f, g, df, dg, x):
self.optProb.comm.bcast(-1, root=0)

# Store Results
inform = np.asscalar(mode)
sol_inform = {}
# sol_inform['value'] = inform
# sol_inform['text'] = self.informs[inform[0]]
sol_inform["value"] = inform
sol_inform["text"] = self.informs[inform]

# Create the optimization solution
sol = self._createSolution(optTime, sol_inform, ff, xs)
Expand Down
3 changes: 2 additions & 1 deletion pyoptsparse/pySNOPT/pySNOPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,10 @@ def __call__(
snopt.closeunit(self.options["iSumm"][1])

# Store Results
inform = np.asscalar(inform)
sol_inform = {}
sol_inform["value"] = inform
sol_inform["text"] = self.informs[inform[0]]
sol_inform["text"] = self.informs[inform]

# Create the optimization solution
sol = self._createSolution(optTime, sol_inform, ff, xs[:nvar], multipliers=pi)
Expand Down
39 changes: 28 additions & 11 deletions test/test_hs071.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ def optimize(
assert_allclose(sol.lambdaStar["con"], self.lambdaStar, atol=tol, rtol=tol)
return sol

def test_snopt(self):
test_name = "hs071_SNOPT"
optOptions = {
"Print file": "{}.out".format(test_name),
"Summary file": "{}_summary.out".format(test_name),
}
self.optimize("snopt", 1e-6, optOptions=optOptions)

def test_slsqp_setDV(self):
"""
Test that setDV works as expected, even with scaling/offset
Expand Down Expand Up @@ -218,13 +210,34 @@ def test_slsqp_scaling_offset_optProb(self):
con_scaled = scaled_values["con"][0]
assert_allclose(con_scaled, con_orig * conScale, atol=1e-12, rtol=1e-12)

def test_snopt(self):
test_name = "hs071_SNOPT"
optOptions = {
"Print file": "{}.out".format(test_name),
"Summary file": "{}_summary.out".format(test_name),
}
sol = self.optimize("snopt", 1e-6, optOptions=optOptions)
self.assertEqual(sol.optInform["value"], 1)
optOptions["Major iterations limit"] = 1
sol = self.optimize("snopt", 1e-6, optOptions=optOptions, check_solution=False)
self.assertEqual(sol.optInform["value"], 32)

def test_slsqp(self):
optOptions = {"IFILE": "hs071_SLSQP.out"}
self.optimize("slsqp", 1e-6, optOptions=optOptions)
sol = self.optimize("slsqp", 1e-6, optOptions=optOptions)
self.assertEqual(sol.optInform["value"], 0)
# now we set max iteration to 1 and verify that we get a different inform
optOptions["MAXIT"] = 1
sol = self.optimize("slsqp", 1e-6, optOptions=optOptions, check_solution=False)
self.assertEqual(sol.optInform["value"], 9)

def test_nlpqlp(self):
optOptions = {"iFile": "hs071_NLPQLP.out"}
self.optimize("nlpqlp", 1e-6, optOptions=optOptions)
sol = self.optimize("nlpqlp", 1e-6, optOptions=optOptions)
self.assertEqual(sol.optInform["value"], 0)
optOptions["maxIt"] = 1
sol = self.optimize("nlpqlp", 1e-6, optOptions=optOptions, check_solution=False)
self.assertEqual(sol.optInform["value"], 1)

def test_ipopt(self):
optOptions = {"print_level": 5, "output_file": "hs071_IPOPT.out"}
Expand Down Expand Up @@ -253,7 +266,11 @@ def test_conmin(self):

def test_psqp(self):
optOptions = {"IFILE": "hs071_PSQP.out"}
self.optimize("psqp", 1e-6, optOptions=optOptions)
sol = self.optimize("psqp", 1e-6, optOptions=optOptions)
self.assertEqual(sol.optInform["value"], 4)
optOptions["MIT"] = 1
sol = self.optimize("psqp", 1e-6, optOptions=optOptions, check_solution=False)
self.assertEqual(sol.optInform["value"], 11)

def test_paropt(self):
optOptions = {"output_file": "hs071_ParOpt.out"}
Expand Down
4 changes: 2 additions & 2 deletions test/test_snopt_user_termination.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_obj(self):
self.assertEqual(termcomp.obj_count, 3)

# Exit code for user requested termination.
self.assertEqual(sol.optInform["value"][0], 71)
self.assertEqual(sol.optInform["value"], 71)

def test_sens(self):
termcomp = TerminateComp(max_sens=3)
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_sens(self):
self.assertEqual(termcomp.sens_count, 4)

# Exit code for user requested termination.
self.assertEqual(sol.optInform["value"][0], 71)
self.assertEqual(sol.optInform["value"], 71)


if __name__ == "__main__":
Expand Down

0 comments on commit 772566c

Please sign in to comment.