b45ch1/pyadolc — Issue #10: Segmentation fault by deriving a sparse hessian
Author: jansb
Created: 2012-02-05 09:59:58+00:00
State: open

Hello,
I have a problem with deriving a sparse hessian with colpack. I have installed pyadolv with ADOLC (2.2.1), colpack (1.04). By certain functions I am interested in the sparse hessian I receive a segmentation fault, but deriving the dense and sparse jacoban and the dense hessian works. Here is an example:

================begin code===================
import adolc as adolc
import numpy as np

N = 3

def F(x):
# y = np.sum((x)**2)
y = np.sum(x**2)+np.cos(x[0]*x[1])
return y

x = np.random.rand(N)

# Trace F
adolc.trace_on(0)
x = adolc.adouble(x)
adolc.independent(x)
y = F(x)
adolc.dependent(y)
adolc.trace_off()

x = np.random.rand(N)

print "Derive jacobian (in this case it is the gradient):"
print "========================================================="
print "x0:", x
print "Dense jacobian:", adolc.jacobian(0,x)

options = np.array([0,0,0,0],dtype=int)

result = adolc.colpack.sparse_jac_no_repeat(0,x,options)

nnz = np.asarray(result[0],dtype=int)
rind = np.asarray(result[1],dtype=int)
cind = np.asarray(result[2],dtype=int)
values = np.asarray(result[3],dtype=float)

print "Sparse jacobian:"
print "nnz:", nnz
print "rind:", rind
print "cind:", cind
print "values:", values

print "\t\t"

print "Derive hessian:"
print "==============="

print "x0:", x
print "Dense hessian:", adolc.hessian(0,x)

options = np.array([0,0],dtype=int)

result = adolc.colpack.sparse_hess_no_repeat(0,x,options)

nnz = np.asarray(result[0],dtype=int)
rind = np.asarray(result[1],dtype=int)
cind = np.asarray(result[2],dtype=int)
values = np.asarray(result[3],dtype=float)

print "Sparse hessian:"
print "nnz:", nnz
print "rind:", rind
print "cind:", cind
print "values:", values
================end code===================

This example works fine. The dense and sparse jacobian and hessian are derived correctly. If I change the function F(x) to

def F(x):
y = np.sum((x)**2)
# y = np.sum(x**2)+np.cos(x[0]*x[1])
return y

the sparse hessian cannot be derived. The output is in this case:

=========output begin===========
Derive jacobian (in this case it is the gradient):
=========================================================
x0: [ 0.44752912 0.87604657 0.28732819]
Dense jacobian: [[ 0.89505824 1.75209313 0.57465638]]
Sparse jacobian:
nnz: 3
rind: [0 0 0]
cind: [0 1 2]
values: [ 0.89505824 1.75209313 0.57465638]

Derive hessian:
===============
x0: [ 0.44752912 0.87604657 0.28732819]
Dense hessian: [[ 2. 0. 0.]
[ 0. 2. 0.]
[ 0. 0. 2.]]
Speicherzugriffsfehler # THE GERMAN WORD FOR SEGMENTATION FAULT
=========output end===========

The sparse hessian and its non-zero pattern cannot be derived. Can you reproduce this behaviour?
Thank you for your help!

Best regards,
Jan S.-B.