My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 13: Seg fault if NLP has no constraints
1 person starred this issue and may be notified of changes. Back to list
Status:  Invalid
Owner:  ----
Closed:  Mar 2011


 
Project Member Reported by herbschi...@gmail.com, Nov 17, 2010
If you try running an example without constraints, you get 

SystemError: ../Objects/tupleobject.c:101: bad argument to internal function
Segmentation fault

I am running on a 64-bit Linux system.

Here is an example. I am not sure I wrote it properly for this no constraint case.

'''
 Testing the Ipopt Python module 
 on the simple case of a paraboloid with no constraints
'''

import pyipopt
from numpy import *

nvar = 2
x_L = ones((nvar), dtype=float_) * -100.0
x_U = ones((nvar), dtype=float_) *  100.0

ncon = 0

g_L = array([])
g_U = array([]) 

def eval_f(x, user_data = None):
       return ( x[0] - 2.0 ) ** 2 + ( x[1] - 3.0 ) ** 2

def eval_grad_f(x, user_data = None):
	grad_f = array([
               2.0 * ( x[0] - 2.0 ),
               2.0 * ( x[1] - 3.0 )
 		], float_)
	return grad_f;
	
def eval_g(x, user_data= None):
           return array([
	], float_)

nnzj = 0
def eval_jac_g(x, flag, user_data = None):
		return array([ ])
		
nnzh = 3
def eval_h(x, lagrange, obj_factor, flag, user_data = None):
	if flag:
		hrow = [0, 1, 1]
		hcol = [0, 0, 1]
		return (array(hcol), array(hrow))
	else:
		values = zeros((3), float_)
		values[0] = obj_factor * (2)
		values[1] = 0
		values[2] = obj_factor * (2)
		return values

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 = array([10.0, 10.0])

user_data = ( 1.234, 9.876 )

x, zl, zu, obj = nlp.solve(x0, user_data)
nlp.close()

print "Solution of the primal variables, x"
print x

print "Solution of the bound multipliers, z_L and z_U"
print zl, zu

print "Objective value"
print "f(x*) =", obj



Nov 23, 2010
Project Member #1 herbschi...@gmail.com
I found out that Pyipopt is fine. It's my code that needed fixing! Using the following eval_jac_g function works fine. I wonder why Ipopt calls the eval_jac_g function even when it was told that their are no constraints. 

def eval_jac_g(x, flag, user_data = None):
        if flag:
                return ([ ], [])
        else:
                return array([ ])

Mar 10, 2011
Project Member #2 xu.mathena
(No comment was entered for this change.)
Status: Invalid

Powered by Google Project Hosting