GithubHelp home page GithubHelp logo

pyipopt's Introduction

PyIpopt

PyIpopt is a python module that allows you to use Ipopt in Python. It is developed by Eric Xu when he was a PhD student at Washington University and issued under the BSD license.

Installation

Dependencies

PyIpopt depends on the following packages:

  1. A compiler and a linker, e.g. gcc, ld
  2. Ipopt
  3. Numpy
  4. Python.h (part of the python source code, you can download it from Python.org)

Install

First, get the latest source code using:

$ git clone http://github.com/xuy/pyipopt.git

In your PyIpopt folder, edit setup.py to reflect the configuration of your system, then do

$ python setup.py build
$ sudo python setup.py install

Test

$ python hs071.py

You should be able to see the result of solving the toy problem.

Usage

You can use PyIpopt like this:

import pyipopt
# define your call back functions
nlp = pyipopt.create(...)
nlp.solve(...)
nlp.close()

You can also check out hs071.py to see how to use PyIpopt.

PyIpopt as a module comes with docstring. You can poke around it by using Python's $help()$ command.

Testing

I have included an example

To see if you have PyIpopt ready, use the following command under the pyipopt's directory.

	python hs071.py

The file "hs071.py" contains a toy optimization problem. If everything is OK, pyipopt will invoke Ipopt to solve it for you. This python file is self-documented and can be used as a template for writing your own optimization problems.

Pyipopt is a legitimate Python module, you can inspect it by using standard Python commands like "dir" or "help". All functions in pyipopt are documented in details.

Hessian Estimation: since Hessian estimation is usually tedious, Ipopt can solve problems without Hessian estimation. Pyipopt also supports this feature. The file "hs071.py" demonstrates the idea. If you provide the pyipopt.create function with an "eval_h" callback function as well as the "apply_new" callback function, Ipopt will delegate the Hessian matrix calculation to your function (otherwise Ipopt will approximate Hessian for you).

Contributing

  1. Fork it.
  2. Create a branch (git checkout -b my_pyipopt)
  3. Commit your changes (git commit -am "your awesome message")
  4. Push to the branch (git push origin my_pyipopt)
  5. Create a pull request
  6. Nag me about it if I am lazy.

Troubleshooting

Check Ipopt

PyIpopt links to Ipopt's C library. If that library is not available PyIpopt will fail during module initialization. To check the availability of this library, you can go to $IPOPT_DIR/Ipopt/examples/hs071_c/ and issue $make to ensure you can compile and run the toy example supplied by Ipopt.

Miscellaneous problems

  • Error: import pyipopt ImportError: can not find libipopt.so.0

  • Solution: find it and copy it to a folder that ld can access

  • Error: import pyipopt ImportError: /usr/lib/libipopt.so.0: undefined symbol: _gfortran_XXX

  • Solution: check if your hs071_c example work. It is very likely that your ipopt library is not correctly compiled.

  • Error: import pyipopt ImportError: /usr/lib/libipopt.so.0: undefined symbol: SetIntermediateCallback

  • Solution: SetIntermediateCallback is a function added since Ipopt 3.9.1. (see https://projects.coin-or.org/Ipopt/changeset/1830 ) Make sure you have an Ipopt version >= 3.9.1

  • Error: import pyipopt ImportError: /usr/lib/libipopt.so.0: undefined symbol: ma19ad_

  • Solution: First, use nm /usr/lib/libipopt.so.0 | grep ma19ad_ to see if it is marked with U. It should. This means that libipopt.so.0 is not aware of libcoinhsl.so.0. You can fix this by adding -lcoinhsl in the makefile of pyipopt. It seems to me that this happens in the recent versions of ipopt. Eventually pyipopt will have a better building mechanism, and I will fix this soon.

  • Error: import pyipopt ImportError: /usr/lib/libipopt.so.0: undefined symbol: SomeKindOfSymbol

  • Solution: I can assure you that it is NOT a bug of pyipopt. It is very likely that you did not link the right package when compiling pyipopt. First, use nm /usr/lib/libipopt.so.0 | grep SomeKindOfSymbol to see if this symbol is indeed missing. Do a Google search to find the library file, and add -lWhateverLibrary in the makefile of pyipopt.

    Ipopt is built using various third-party libraries. Different machines may have different set of libraries. You should try to locate these dependencies and indicate them when compiling pyipopt. This is just a limitation of dynamic linking libraries and is not related to Pyipopt. Please do not report a missing symbol error as a "bug" to me unless you are 100% sure it is the problem of pyipopt.

Contact

Eric Xu [email protected]

Software Engineer @ Google

pyipopt's People

Contributors

alexbrc avatar brechtba avatar drestebon avatar ebogart avatar heczis avatar nanthony21 avatar xuy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyipopt's Issues

Weird behavior if coordinate array is not C/F contiguous

I've found that if I pass in a coordinate array that is not internally contiguous, then Ipopt misbehaves. I've made a small change to the Python 3 example to reproduce this behavior. You can see that the derivative checker is getting the user input values of Jacobian wrong. If you replace idx0 by idx1, then the program runs fine again.

diff --git a/examples/hs071_PY3.py b/examples/hs071_PY3.py
index 30049f0..8295f24 100644
--- a/examples/hs071_PY3.py
+++ b/examples/hs071_PY3.py
@@ -36,9 +36,13 @@ def eval_g(x, user_data= None):
         x[0]*x[0] + x[1]*x[1] + x[2]*x[2] + x[3]*x[3]
         ], float_)
 
+idx0=where(ones([2,4]))
+idx1=tuple(a.copy() for a in idx0)
+
 nnzj = 8
 def eval_jac_g(x, flag, user_data = None):
     if flag:
+        return idx0
         return (array([0, 0, 0, 0, 1, 1, 1, 1]),
                 array([0, 1, 2, 3, 0, 1, 2, 3]))
     else:
@@ -88,6 +92,7 @@ def apply_new(x):
     return True
 
 nlp = pyipopt.create(nvar, x_L, x_U, ncon, g_L, g_U, nnzj, nnzh, eval_f, eval_grad_f, eval_g, eval_jac_g)
+nlp.str_option('derivative_test', 'first-order')
 
 x0 = array([1.0, 5.0, 5.0, 1.0])
 pi0 = array([1.0, 1.0])

Here is the output.

[PyIPOPT] Ipopt will use Hessian approximation.

[PyIPOPT] Problem created
Going to call solve
x0 = [ 1.  5.  5.  1.]

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

This is Ipopt version 3.12, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).

Starting derivative checker for first derivatives.

* jac_g [    0,    0] =  4.0526274556533458e+01 v  ~  2.8661580872880940e+01  [ 4.140e-01]
* jac_g [    1,    0] =  1.4264140070585769e+01 v  ~  2.3330427399003071e+00  [ 5.114e+00]
* jac_g [    0,    1] =  7.7050646628947046e+00 v  ~  1.1864693442554596e+01  [ 3.506e-01]
* jac_g [    1,    1] =  0.0000000000000000e+00    ~  5.6359394300006009e+00  [ 1.000e+00]
* jac_g [    0,    2] =  2.3330427581750257e+00 v  ~  7.7050647328635344e+00  [ 6.972e-01]
* jac_g [    1,    2] =  0.0000000000000000e+00    ~  8.6785376971135495e+00  [ 1.000e+00]
* jac_g [    0,    3] =  8.6785377453353192e+00 v  ~  1.4264139896977037e+01  [ 3.916e-01]
* jac_g [    1,    3] =  0.0000000000000000e+00    ~  4.6878883546277272e+00  [ 1.000e+00]

Derivative checker detected 8 error(s).

Number of nonzeros in equality constraint Jacobian...:        3
Number of nonzeros in inequality constraint Jacobian.:        7
Number of nonzeros in Lagrangian Hessian.............:        0

*** Error in `python': free(): invalid next size (fast): 0x0000000001e2d0a0 ***
Aborted

loading pyipopt...

I got everything to compile (under python 2.7) but get the following when i try to run the example - this is related to an issue posted but I don't see an obvious fix...


Class-MBP:examples clasajacobson$ python hs071.py
Traceback (most recent call last):
File "hs071.py", line 6, in
import pyipopt
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyipopt/init.py", line 16, in
from pyipoptcore import *
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyipopt/pyipoptcore.so, 2): Symbol not found: __ZNSs4_Rep20_S_empty_rep_storageE
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyipopt/pyipoptcore.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyipopt/pyipoptcore.so

Symbol not found: _PyInt_AsLong in python3

Thanks a lot for adding python 3 support. Compiling and installing works fine, but I do get the following error when trying to import pyipopt (pyipopt runs great under python 3.7 with the same ipopt library):

import pyipopt
ImportError Traceback (most recent call last)
in ()
----> 1 import pyipopt
/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyipopt/init.py in ()
14
15 from ipoptconst import *
---> 16 from pyipoptcore import *
17 from ipoptunconstrained import fmin_unconstrained
18
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyipopt/pyipoptcore.so, 2): Symbol not found: _PyInt_AsLong
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyipopt/pyipoptcore.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pyipopt/pyipoptcore.so

segmentation fault occurred when use pyipopt

I'm trying to use the pyipopt to solve an NLP problem. After I executed the python code, a segmentation fault occurred. The following are the returned information:

[PyIPOPT] Ipopt will use Hessian approximation.

[PyIPOPT] Problem created


This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit http://projects.coin-or.org/Ipopt


This is Ipopt version 3.12.4, running with linear solver ma27.

[Callback:E] eval_jac_g
[PyIPOPT] return from eval_jac_g is null

I was wondering if someone has any clue about why this happened.

Documentation on apply_new

I've done some searching but haven't found an explanation of what the apply_new function does. I started with

def apply_new(x):
    return True

as the examples show. However I have found that returning false improves performance a bit but I'm not sure why.

repeated "PyDebug" output

I apologize in advance for being new to the pyipopt interface -- thank you for the incredible work on this project. I run a simple instance of a NLP that I want to solve using IPOPT via pyipopt. The output from the IPOPT solver command

x, zl, zu, constraint_multipliers, obj, status = nlp.solve(x0)

is severely contaminated with lines of

PyDebug NUMBER

, where NUMBER is a 6-decimal place number such as 0.000000 or 21.746642. The above line is printed several hundreds of times as part of the output, approximately 150 times before the derivative checker and problem summary, and another 18 times between each iteration. I noticed that for larger scale problems, the frequency of the "PyDebug" output goes up, much faster than the number of iterations, and this starts to occupy a lot of clock time very quickly.

Some sample output from my actual program (I am happy to post the relevant parts of it if you think that helps, but it is fairly standard). Note, however, that when running the example file "hs071_PY3.py", I do not get any "PyDebug" output. I wonder what is causing the above output, and how I can suppress it (or what I should do to fix the underlying problem)?

******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************

This is Ipopt version 3.12, running with linear solver ma27.

Starting derivative checker for first derivatives.

Starting derivative checker for second derivatives.

[Logspam] built arglist for eval_h
[Logspam] Python function eval_h returns non-NULL
PyDebug 0.000000
PyDebug 0.000000
[...many more lines of this and similar ones...]
PyDebug 0.000000

No errors detected by derivative checker.

[Logspam] built arglist for eval_h
[Logspam] Python function eval_h returns non-NULL
Number of nonzeros in equality constraint Jacobian...: 18
Number of nonzeros in inequality constraint Jacobian.: 180
Number of nonzeros in Lagrangian Hessian.............: 18

Total number of variables............................: 18
variables with only lower bounds: 18
variables with lower and upper bounds: 0
variables with only upper bounds: 0

Total number of equality constraints.................: 1
Total number of inequality constraints...............: 30
inequality constraints with only lower bounds: 0
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 30

PyDebug 1.969484
PyDebug 1.790440
PyDebug 1.392636
PyDebug 1.969484
PyDebug 1.790440
PyDebug 1.392636
PyDebug 1.969484
PyDebug 1.790440
PyDebug 1.392636
PyDebug 1.969484
PyDebug 1.790440
PyDebug 1.392636
PyDebug 1.969484
PyDebug 1.790440
PyDebug 1.392636
PyDebug 1.969484
PyDebug 1.790440
PyDebug 1.392636
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 5.1340941e+01 3.33e-16 4.64e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0
PyDebug 1.883636
[...many more lines of this and similar ones...]
PyDebug 35.356713
21 4.5426289e+00 1.62e-09 1.05e-08 -8.6 1.03e-04 - 1.00e+00 1.00e+00h 1
22 4.5426289e+00 6.55e-10 4.32e-09 -9.0 6.55e-05 - 1.00e+00 1.00e+00h 1

Number of Iterations....: 22

                               (scaled)                 (unscaled)

Objective...............: 4.5426289179813661e+00 4.5426289179813661e+00
Dual infeasibility......: 4.3226662511009695e-09 4.3226662511009695e-09
Constraint violation....: 6.5500968537968163e-10 6.5500968537968163e-10
Complementarity.........: 1.4991089664955258e-09 1.4991089664955258e-09
Overall NLP error.......: 4.3226662511009695e-09 4.3226662511009695e-09

Number of objective function evaluations = 23
Number of objective gradient evaluations = 23
Number of equality constraint evaluations = 23
Number of inequality constraint evaluations = 23
Number of equality constraint Jacobian evaluations = 23
Number of inequality constraint Jacobian evaluations = 23
Number of Lagrangian Hessian evaluations = 22
Total CPU secs in IPOPT (w/o function evaluations) = 0.078
Total CPU secs in NLP function evaluations = 0.012

EXIT: Optimal Solution Found.

Please don't depend on optional Ipopt libraries

This section:

        libraries=[
            'ipopt', 'coinblas',
            #'coinhsl',
            'coinmumps',
            'coinmetis',
            'coinlapack','dl','m',
            ],

is wrong. You depend on libraries 'coinblas', 'coinmumps', 'coinmetis', 'coinlapack', that are only built optionally when Ipopt builds them from its bundled sources.

On FreeBSD, for example, 'coinblas' and 'coinlapack' don't exist.

Additionally, 'dl' doesn't exist on FreeBSD. It is a linux-only library.

ImportError: libipopt.so.1

Eric,

I'm not able to run 'hs071.py' example... I've got problems in importing 'pyipoptcore'...

I've checked my IPOPT as described in Troubleshooting section and it worked fine.

By running 'python hs071.py' I've got the following error:
File "hs071.py", line 6, in
import pyipopt
File "/usr/local/lib/python2.7/dist-packages/pyipopt/init.py", line 12, in
from pyipoptcore import *
ImportError: libipopt.so.1: cannot open shared object file: No such file or directory

May be important to report that when I've built pyipopt I've got some warnings, mainly concerning NumPy:
$ python setup.py build
running build
running build_py
running build_ext
building 'pyipoptcore' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include/coin/ -I/usr/include/python2.7 -c src/callback.c -o build/temp.linux-x86_64-2.7/src/callback.o
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:15,
from src/hook.h:7,
from src/callback.c:36:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
^
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include/coin/ -I/usr/include/python2.7 -c src/pyipoptcoremodule.c -o build/temp.linux-x86_64-2.7/src/pyipoptcoremodule.o
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:15,
from src/hook.h:7,
from src/pyipoptcoremodule.c:9:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
^
src/pyipoptcoremodule.c: In function ‘set_intermediate_callback’:
src/pyipoptcoremodule.c:470:15: warning: variable ‘myowndata’ set but not used [-Wunused-but-set-variable]
DispatchData myowndata;
^
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/callback.o build/temp.linux-x86_64-2.7/src/pyipoptcoremodule.o -L/usr/local/lib -lipopt -lblas -lcoinmumps -lcoinmetis -llapack -ldl -lm -o build/lib.linux-x86_64-2.7/pyipopt/pyipoptcore.so

Cheers!

ImportError: libcoinblas.so.1: cannot open shared object file: No such file or directory

Hi,

I am trying to install, I did I procedure described without warning or errors, but when I try to call "import pyipopt" the following error appears:

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/pyipopt/init.py", line 16, in
from pyipoptcore import *
ImportError: libcoinblas.so.1: cannot open shared object file: No such file or directory

It is very strange to me because in my virtual-machine (VM) the installation is working perfectly, but now I created a dual boot using Ubuntu 14.04 LTS (the same version from VM).

Any idea what’s going on?

Cheers,

int integers are allowed but not properly cast

If the user passes an array of ints into nlp.create then the c extension will improperly interpret this data as floats without giving any indication of an error. For example numpy.array([1,1,1,1]) become {0.0,0.0,0.0,0.0} and numpy.array([-1,-1,-1,-1]) become {-inf,-inf,-inf,-inf}

Memory leak

Hi Eric,

I found that repeatedly solving problems used up a lot of memory even if I did not store the results. This turned out to be because some Py_XDECREF calls at the end of solve() are inside a conditional which doesn't normally execute.

I moved those statements back out of the conditional, which fixed the memory issue, and made a few other tweaks: not creating an integer object for the status code inside the Py_BuildValue call in solve() (which was creating an extra reference to the integer), calling PyType_Ready for IpoptProblemType in the module initialization code (which fixed a weird issue I'd been having where trying to use IPython's tab completion to list a problem's methods and attributes led to a segfault,) and freeing the python object in problem_dealloc.

I put up a branch with these changes: https://github.com/ebogart/pyipopt/tree/memory

Thanks!

Example hs071.py returns wrong solution x

Hello,
I have a problem with running the example hs071.py. I have installed Ubuntu (11.10), IPOPT (vers. 3.10.1, the examples work fine), python (2.7.2) and numpy (1.5.1). Installing pyipopt (0.8.1) works without any errors. I can run the example hs071.py. The Output is:

Going to call solve
[ 1. 5. 5. 1.]


This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit http://projects.coin-or.org/Ipopt


This is Ipopt version 3.10.1, running with linear solver ma27.

Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 0

Total number of variables............................: 4
variables with only lower bounds: 0
variables with lower and upper bounds: 4
variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 1
inequality constraints with only lower bounds: 1
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 0

iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 1.6109693e+01 1.12e+01 5.28e-01 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
1 1.7420709e+01 7.49e-01 2.40e+01 -0.3 8.13e-01 - 3.20e-01 1.00e+00f 1
2 1.7120453e+01 2.14e-01 2.00e-01 -0.6 1.02e+00 - 9.97e-01 1.00e+00h 1
3 1.6979032e+01 1.70e-01 8.49e-02 -1.6 1.18e-01 - 9.72e-01 1.00e+00h 1
4 1.6972554e+01 7.69e-02 1.20e-02 -3.2 8.01e-02 - 1.00e+00 1.00e+00h 1
5 1.7013661e+01 6.75e-04 9.50e-03 -4.9 1.00e-02 - 1.00e+00 1.00e+00h 1
6 1.7014018e+01 1.96e-06 3.49e-04 -6.1 1.09e-03 - 1.00e+00 1.00e+00h 1
7 1.7014017e+01 1.47e-09 2.15e-07 -8.2 3.02e-05 - 1.00e+00 1.00e+00h 1
8 1.7014017e+01 7.11e-15 1.69e-09 -11.0 1.17e-08 - 1.00e+00 1.00e+00h 1

Number of Iterations....: 8

                               (scaled)                 (unscaled)

Objective...............: 1.7014017140224176e+01 1.7014017140224176e+01
Dual infeasibility......: 1.6853176362439800e-09 1.6853176362439800e-09
Constraint violation....: 7.1054273576010019e-15 7.1054273576010019e-15
Complementarity.........: 1.0002952000760580e-11 1.0002952000760580e-11
Overall NLP error.......: 1.6853176362439800e-09 1.6853176362439800e-09

Number of objective function evaluations = 9
Number of objective gradient evaluations = 9
Number of equality constraint evaluations = 9
Number of inequality constraint evaluations = 9
Number of equality constraint Jacobian evaluations = 9
Number of inequality constraint Jacobian evaluations = 9
Number of Lagrangian Hessian evaluations = 0
Total CPU secs in IPOPT (w/o function evaluations) = 0.028
Total CPU secs in NLP function evaluations = 0.004

EXIT: Optimal Solution Found.
Solution of the primal variables, x
[ 6.93315118e-310 6.93315118e-310 5.00000000e+000 1.00000000e+000]
Solution of the bound multipliers, z_L and z_U
[ 1.08787121e+00 2.67165388e-12 3.54465533e-12 2.63564701e-11] [ 2.49999763e-12 3.89104702e-11 8.48283408e-12 2.76198339e-12]
Objective value

f(x*) = 17.0140171402

According to this output the resulting parameter vector is x = [ 6.93315118e-310 6.93315118e-310 5.00000000e+000 1.00000000e+000]. Running the (mathematical similar) example hs071.c from IPOPT returns:

Solution of the primal variables, x
x[0] = 1.000000e+00
x[1] = 4.749269e+00
x[2] = 3.817510e+00
x[3] = 1.367870e+00

This solution differs from from the one derived by pyipopt. However, z_L, z_U and the value of the objective are similar in hs071.c and hs071.py. It seems so, that hs071.py computes the correct x, but does not return it correclty (in my case). When printing x in hs071.py in each evaluation of the objective by adding the line 'print x' to the function 'def eval_f(x, user_data = None):', on the last call during the optimization prozess it returns [ 0.99999999 4.74299964 3.82114998 1.37940829], e.g. the similar solution as hs071.c returns.

It seems that the optimization process works well, but the result will not be passed back to python correctly. Btw. the similar problem also occurs in other testproblems I wrote. Can you reproduce this error? If you need additional informations, just let me know. Thank you.

Anyway, thank you for providing a wrapper from python to IPOPT!

Best regards,
Jan Schumann-Bischoff

Cannot set tolerance or maximum iteration

I haven't found how to set the tolerance value on the constraints and objective value or the maximum number of iteration.

Is that possible through pyipopt ? It is possible through ipopt's C++ interface.

Solver Options PyIPOPT

After seeing PR-27, I am able to figure out how to provide solver options in pyipopt using nlp.str_option. But I am not aware what all options are available ?

Basically I want to just switch of the verbosity (print) of the solver and also want to change the default solver (which is mumps).

trying to install on mac os x

I am having difficulty with the install. I pulled a binary of ipopt and edited setup.py but have an error on the build...


/usr/bin/clang -bundle -undefined dynamic_lookup -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/lib/db48 build/temp.macosx-10.10-x86_64-2.7/src/callback.o build/temp.macosx-10.10-x86_64-2.7/src/pyipoptcoremodule.o -L/Users/clasajacobson/ipopt/lib -lipopt -lblas -lcoinmumps -lcoinmetis -llapack -ldl -lm -o build/lib.macosx-10.10-x86_64-2.7/pyipopt/pyipoptcore.so
ld: library not found for -lcoinmetis
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit status 1

Errors in running hs071.py

I install the ipopt by home-brew on Mac os x, and change the setup.py to adjust the home-brew:
'''
pyipopt_extension = Extension(
'pyipoptcore',
FILES,
#extra_link_args=['-Wl,--rpath','-Wl,'+ IPOPT_LIB],
library_dirs=[IPOPT_LIB],
libraries=[
'ipopt', 'blas',
#'hsl',
'cmumps',
'dmumps',
'zmumps',
'smumps',
'mumps_common',
'mpiseq',
'pord',
#'coinmetis',
'lapack','dl','m',
],
include_dirs=[numpy_include, IPOPT_INC],
)
'''

However, I found the following errors when running hs071.py:

[PyIPOPT] Ipopt will use Hessian approximation.

[PyIPOPT] Problem created
Going to call solve
[ 1. 5. 5. 1.]


This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit http://projects.coin-or.org/Ipopt


This is Ipopt version 3.11.10, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).

[Callback:E] eval_jac_g
[Callback:R] eval_jac_g(1)
[Callback:R] eval_jac_g
Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 0

[Callback:E] eval_grad_f
[Callback:R] eval_grad_f
[Callback:E] eval_jac_g
[Callback:R] eval_jac_g(2)
[Callback:R] eval_jac_g
[Callback:E] eval_g
[Callback:R] eval_g
[Callback:E] eval_jac_g
[Callback:R] eval_jac_g(2)
[Callback:R] eval_jac_g
[Callback:E] eval_grad_f
[Callback:R] eval_grad_f
Python(7768,0x7fff76e7c310) malloc: *** error for object 0xfff907aa00027100: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Is it a memory leaking problem?

from pyipoptcore import * --> libipopt.so.1: cannot open shared object file: No such file or directory

Hi,

I tried to install pyipopt, it seems that everything is ok. Then I run the test file examples/hs071.py, this error happens. After that, I try just to "import pyipopt" from python, and the same error.

I open the folder pyipoptpackage and there are only ipoptconst.py and ipoptunconstrained.py, without the pyipoptcore.py file.

I am a new babie with pyipot and ipopt, so if anyone can help me or give me a hint how to solve it, all are very appreciated.

Symbol not found: __gfortran_adjustl on mac OS El Capitan

I am trying to install pyipopt on mac OS X 10.11.1 El Capitan.
I am just getting started with UNIX systems, but I managed to compile the Ipopt library from source and the hs071_c example runs without any issues.
I run the instalation of pyipopt as instructed. Changed the setup.py file in order to point to the Ipopt library, and the build and install didn't throw any errors. However, when i try to test it and import pyipopt, it throws:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyipopt/__init__.py", line 16, in <module> from pyipoptcore import * ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyipopt/pyipoptcore.cpython-35m-darwin.so, 2): Symbol not found: __gfortran_adjustl Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyipopt/pyipoptcore.cpython-35m-darwin.so Expected in: flat namespace in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyipopt/pyipoptcore.cpython-35m-darwin.so

Please let me know if you know of any successful installations on El Capitan.
Thanks.

I have ported your code to Python3.

Thank for your contribution. I'm a master student on power system optimization. I'm very fond of Ipopt and Python language. It's very nice that you write python code for people using Ipopt. Your code is written under Python2, but I'd like to use Python3. Luckily @drestebon has done some major jobs(#14) to partially port your code to Python3. I forked you code(https://github.com/facat/py3ipopt) and did some small modifications based on drestebon's contribution. Now all your example can run under Python3. I will maintain my branch as possible as I can.

Compile error: cannot find -lcoinmumps -- requires coin, not just ipopt?

I get the error "cannot find -lcoinmumps, -lcoinmetis" on building. setup.py build.
Do I need another package other than ipopt from coin-or?

user@host ~/Downloads/Ipopt-3.11.3/pyipopt $ C_INCLUDE_PATH=$HOME/bin/ipopt/include/coin/ LIBRARY_PATH=$HOME/bin/ipopt/lib/ LD_LIBRARY_PATH=$HOME/bin/ipopt/lib/ python setup.py build running build running build_py running build_ext building 'pyipoptcore' extension x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/home/user/.local/lib64/python2.7/site-packages/numpy/core/include -I/usr/local/include/coin/ -I/usr/include/python2.7 -c src/callback.c -o build/temp.linux-x86_64-2.7/src/callback.o In file included from /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0, from /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17, from /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:15, from src/hook.h:7, from src/callback.c:36: /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp] x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/home/user/.local/lib64/python2.7/site-packages/numpy/core/include -I/usr/local/include/coin/ -I/usr/include/python2.7 -c src/pyipoptcoremodule.c -o build/temp.linux-x86_64-2.7/src/pyipoptcoremodule.o In file included from /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0, from /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:17, from /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:15, from src/hook.h:7, from src/pyipoptcoremodule.c:9: /home/user/.local/lib64/python2.7/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp] x86_64-pc-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,--as-needed -L. build/temp.linux-x86_64-2.7/src/callback.o build/temp.linux-x86_64-2.7/src/pyipoptcoremodule.o -L/usr/local/lib -L/usr/lib64 -lipopt -lblas -lcoinmumps -lcoinmetis -llapack -ldl -lm -lpython2.7 -o build/lib.linux-x86_64-2.7/pyipopt/pyipoptcore.so /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lcoinmumps /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lcoinmetis collect2: ld returned 1 exit status error: command 'x86_64-pc-linux-gnu-gcc' failed with exit status 1

PyIPOPT provides different result than IPOPT's Java Interface

I am experiencing some very strange behaviour on the attached problem (TestProblem.py.txt).
When I try to solve the problem using IPOPT's java interface it works without issues as you can see in javaOutput.txt. I double checked the result with Matlab's fmincon and it is correct.

However, when I use pyipopt it converges to an infeasible point. To me this is incredibly strange as I checked the objective, constraint, gradient, and hessian functions against the ones implemented in java and they provide the exact same results. You can compare with the values from javaOutputCheckFunctions.txt (note that the hessian in the java implementation requires only the lower or upper triangular as the matrix is symmetric).

Moreover, the first iteration of the IPOPT solver is the same in both cases, i.e. java and python. However, from the second iteration they start to be different. It is as if the python interface doesn't pass correctly the jacobian/hessian information and the solver takes it into a different direction.

I would highly appreciate it if you have time to take a look at this.

javaOutput.txt
javaOutputCheckFunctions.txt
TestProblem.py.txt

ImportError: /usr/local/lib/python2.7/dist-packages/pyipopt/pyipoptcore.so: undefined symbol: _ZTVN10__cxxabiv117__class_type_infoE

Pyipopt used to work on this computer, but after trying to make Ipopt interface with Matlab, pyipopt has since stopped working. Installation of Ipopt and pyipopt produces no errors. Ipopt's hs071_c works fine.

When I try to run pyipopt's example hs071.py, or any other python code that uses pyipopt, this error gets produced:

Traceback (most recent call last):
File "hs071.py", line 6, in
import pyipopt
File "/usr/local/lib/python2.7/dist-packages/pyipopt/init.py", line 16, in
from pyipoptcore import *
ImportError: /usr/local/lib/python2.7/dist-packages/pyipopt/pyipoptcore.so: undefined symbol: _ZTVN10__cxxabiv117__class_type_infoE

I have uninstalled and reinstalled Ipopt and pyipopt various times, but the error still gets thrown when hs071.py is run.

Running on Ubuntu 16.04 dual-booted with Windows 10

memory corruption

I'm using Python 3.5.2 x64 on Linux with Numpy 1.11.2 and the latest PyIpopt. The following code returns a segmentation fault, unless the lines in eval_jac_g are commented out. The commented lines do not alter i and/or j as they are already in int64 format, but they do create a copy of the data. I'm suspecting this to be a bug in pyipopt, since Valgrind shows many errors related to invalid reads/writes.

import numpy as np
import pyipopt

A = np.matrix([[1.0, 0, 1], [2,3,1]])
p = np.transpose(np.matrix([[0.0],[10]]))
I,J = A.shape

nvar = J
ncon = I

x_L = np.zeros((nvar), dtype=float)
x_U = np.ones((nvar), dtype=float) * float('inf')

g_L = np.zeros(ncon)
g_U = np.ones((ncon), dtype=float) * 10.0

def eval_f(x):
  return 0.0

def eval_grad_f(x):
  return np.array([0, 0, 0], np.float_);

def eval_g(x):
  return np.squeeze(np.asarray(np.dot(A, x)))

nnzj = np.count_nonzero(A)
def eval_jac_g(x, flag):
  if flag:
    i,j = np.nonzero(A)
#    i = i.astype(np.int64)
#    j = j.astype(np.int64)
    return i,j
  else:
    return np.squeeze(np.asarray(A[np.nonzero(A)], dtype = float))

nnzh = np.count_nonzero(A)

nlp = pyipopt.create(nvar, x_L, x_U, ncon, g_L, g_U, nnzj, nnzh, eval_f, eval_grad_f, eval_g, eval_jac_g)

x0 = np.ones(nvar, dtype = float)
x, zl, zu, constraint_multipliers, obj, status = nlp.solve(x0)

IP opt path for setup

Hi

I was trying to install this package and in setup.py I see the path to ipopt is hard-coded to IPOPT_DIR = '/usr/local/'.
Since I am installing it in a docker image, I was thinking that an environment variable containing the path to ipopt installation should make this a bit more flexible.
What do you think if I make a PR for this?

Thanks

Setup on MacOS with Homebrew IpOpt

Hi everyone, I just want to document my setup on MacOS, as this may help other users. Please find the instructions below.

First, install IpOpt from Homebrew (this is a temporary solution until the formula is accepted in homebrew-core):

brew install dartsim/dart/ipopt

This should install the optional libraries, including OpenBLAS, if not already installed. Next, clone the pyipopt git repository to a local directory and enter that directory:

git clone http://github.com/xuy/pyipopt.git
cd pyipopt

Next, modify two variables in the setup.py configuration file as follows:

nano setup.py
IPOPT_DIR = '/usr/local/Cellar/ipopt/3.12.9/'
libraries = ['ipopt', 'openblas', 'dmumps', 'metis', 'lapack', 'dl', 'm']

Finally, install the pyipopt package:

python setup.py build
python setup.py install

Everything should work.

nlp can only be solved once

If you try to call solve on an nlp object after it has already been solved you will get an error saying that the nlp object is Null. This means that you need to create a new nlp every time you want to solve. There are situations where you would want to solve the same problem for various different values of x0. Is there a way that the nlp object could be persistent?

libipopt.so.0: undefined symbol: MPI_Init

This problem occurred to after installation and running the example hs071.py.
Anyway found its caused by the missing Mumps library and I could fixed it with adding 'dmumps-4.10.0' (version may vary) to setup.py -->libraries.

So I fixed, just wanted to share the solution.

Other adjustments to make setup.py work

Other changes (probably lines 50 to 60) you may have to do consist in removing the coin prefix (e.g. 'coinlapack' -> 'lapack')
Another change is in IPOPT_INC = os.path.join(IPOPT_DIR, 'include/coin/').
You might have to to change it in IPOPT_INC = os.path.join(IPOPT_DIR, 'include/coin-or/')

Enable Approximation of the Hessian by Quasi Newton

I am implementing a problem where symbolic calculation of the hessian is prohibitively difficult. Luckily Ipopt has an option to approximate the Hessian of the Lagrangian by a limited-memory quasi-Newton method (L-BFGS). This feature can be toggled by setting the option hessian_approximation to the value "limited-memory". See the IPOPT documentation below.

The question is thus, how can hessian_approximation be set to limited-memory using pyipopt?

As alluded to in the HS071 example would it be something like:
nlp.str_option('hessian_approximation', 'limited-memory')

A related question on the HS071 example, eval_h is not passed to pyipopt.create even though it is one of the required problem functions per section 3.2 of the introduction to IPOPT document if limited-memory hessian_approximation is not enabled. Does this imply that hessian approximation defaults to limited-memory if a function for calculating the hessian is not provided?

Thank you for your time.

QUASI_NEWTON Hessian Approximation Option
https://coin-or.github.io/Ipopt/SPECIALS.html#QUASI_NEWTON

HS071 Example
https://github.com/xuy/pyipopt/blob/master/examples/hs071.py#L111

Introduction to IPOPT
https://projects.coin-or.org/Ipopt/browser/stable/3.10/Ipopt/doc/documentation.pdf?format=raw

Exception: failed to find ipopt lib

When I download pyiopt and execute the setup.py file,a Exception: failed to find ipopt lib occurs. But I'm sure I've downloaded the ipopt package.How to solve the problem?I would appreciate if anyone could help me out

release 0.8?

it's been 11 years since the 0.7 release, which is no longer available to download. It would be handy to publish an 0.8 release so that a recent version pyipopt can be distributed via package managers, etc.

Same return values (of eval_jac_g) in python yield different results in IPOPT

Hi,
I noticed that I get different results from IPOPT when returning the very same arrays (in terms of numpy.array_equal(a,b)) as sparsity structure for the constraint Jacobian.

This is the code:

matrix = np.array([0.,0.,0.,0.,0.,0.,1.,1.,1.,0.],
                 [0.,0.,0.,1.,1.,0.,0.,1.,0.,0.])

matrix_sparse = matrix[np.nonzero(matrix)]

def eval_jac_g(x, flag, user_data=None):
    if flag:
        rows1, cols1 = numpy.nonzero(matrix)
        cols2 = numpy.array([6,7,8,3,4,7])
        rows2 = numpy.array([0,0,0,1,1,1])
        print numpy.array_equal(rows1, rows2) # returns True
        print numpy.array_equal(cols1, cols2) # returns True
        return (rows1, cols1)                   # or (rows2, cols2)
    else:
        return matrix_sparse

I checked that np.array_equal(rows1,rows2) == True, same for cols. However, if I run my code, then I get different results: Assigning the arrays manually (rows1, cols1) gives me a successful run of IPOPT whereas (rows2, cols2) gives an "The index of a matrix is out of range." error from MA27.

I am quite clueless about how this can happen. Any ideas?
I can provide a full example if necessary.

Undefined symbol sgenv_

When trying to import pyipopt it appears the following error:
ImportError: /home/manuel/CoinIpopt/lib/libcoinhsl.so.0: undefined symbol: sgenv_
What can the problem may be?
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.