Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved the installation description, added "known to work machines"…

…, removed 3D plots from the unit test, copied setup.py to setup.py.EXAMPLE
  • Loading branch information...
commit 2ab01afdba8a0cc8a67c33d54767e0fc40780aed 1 parent 72ea6fc
Sebastian F. Walter authored
17 README.rst
View
@@ -64,25 +64,32 @@ EXAMPLE USAGE::
REQUIREMENTS:
+ * Known to work for Ubuntu Linux, Python 2.6, NumPy 1.3.0, Boost:Python 1.40.0
* Python and Numpy, both with header files
* ADOL-C version 2.1.0 http://www.coin-or.org/projects/ADOL-C.xml
* boost::python from http://www.boost.org/
* scons build tool
OPTIONAL REQUIREMENTS:
- * For sparse Jacobians and Hessians: http://www.cscapes.org/coloringpage/software.htm
+ * For sparse Jacobians and Hessians: ColPack 1.0.0 http://www.cscapes.org/coloringpage/software.htm
INSTALLATION:
* CHECK REQUIREMENTS: Make sure you have ADOL-C (version 2.1 and above), ColPack (version 1.0.0 and above) the boost libraries and numpy installed. All with header files.
- * BUILD ADOL-C: run e.g. ``/configure --enable-sparse --with-colpack=/home/b45ch1/workspace/ColPack/build
- && make``. You should then have a folder ``~/workspace/ADOL-C-2.1.0/ADOL-C/src`` with ``adolc.h`` in it. You don't have to run ``make install``.
+ * BUILD ADOL-C:
+ * run ``./configure --enable-sparse --with-colpack=/home/b45ch1/workspace/ColPack/build``
+ * run ``make``
+ * You don't have to run ``make install``.
+ * You should then have a folder ``~/workspace/ADOL-C-2.1.0/ADOL-C`` with ``adolc/adolc.h`` in it.
* DOWNLAD PYADOLC: ``cd ~`` and then ``git clone git://github.com/b45ch1/pyadolc.git``
* BUILD PYADOL:
* change to the folder ``~/pyadolc`` and rename the file ``setup.py.EXAMPLE`` to ``setup.py``.
* Adapt ``setup.py`` to fit your system. In particular, you have to set the paths to your ADOL-C installation and boost python.
- * Run ``python setup.py build``. A new folder with a name similar to ``~/pyadolc/build/lib.linux-x86_64-2.6`` should be generated.
- * TEST YOUR INSTALLATION: Change directory to ``~/pyadolc/build/lib.linux-x86_64-2.6`` and run ``python -c "import adolc; adolc.test()"``. All tests should pass.
+ * run ``python setup.py build``. A new folder with a name similar to ``~/pyadolc/build/lib.linux-x86_64-2.6`` should be generated.
+ * run ``python setup.py install`` to install pyadolc to your system.
+ * TEST YOUR INSTALLATION:
+ * Change directory to ``~/pyadolc/build/lib.linux-x86_64-2.6``
+ * run ``python -c "import adolc; adolc.test()"``. All tests should pass.
* You can also use scons (if you have it) instead of using setup.py
* If anything goes wrong, please file a bug report.
25 SConstruct.EXAMPLE
View
@@ -5,27 +5,25 @@ import numpy
# -1: CUSTOMIZE THIS TO FIT YOUR SYSTEM !!!
-adolc_include_path = '/u/walter/workspace/ADOL-C-2.1.0/ADOL-C/src'
-adolc_library_path = '/u/walter/workspace/ADOL-C-2.1.0/ADOL-C/src/.libs'
+adolc_include_path = '/home/b45ch1/workspace/ADOL-C/trunk/ADOL-C/'
+adolc_library_path = '/home/b45ch1/workspace/ADOL-C/trunk/ADOL-C/src/.libs'
-colpack_include_path = '/u/walter/workspace/colpack/build/include'
-colpack_library_path = '/u/walter/workspace/colpack/build/lib'
+colpack_include_path = '/home/b45ch1/workspace/ColPack/build/include'
+colpack_lib_path = '/home/b45ch1/workspace/ColPack/build/lib'
LIBS = ['adolc',
'boost_python',
- 'colpack',
+ 'ColPack',
]
LIBPATH = [
+ colpack_lib_path,
adolc_library_path,
- colpack_library_path,
]
INCLUDEPATH = [
- adolc_include_path,
colpack_include_path,
+ adolc_include_path,
]
-
-
# 0: setup the command line parsing
AddOption('--prefix',
dest='prefix',
@@ -40,7 +38,7 @@ env = Environment(
TMPBUILD = '/tmp/builddir',
CPPPATH=[distutils.sysconfig.get_python_inc(),numpy.get_include()] + INCLUDEPATH,
CXXFLAGS="-ftemplate-depth-100 -DBOOST_PYTHON_DYNAMIC_LIB -O2 -Wall",
- LIBPATH=["/usr/lib/python2.5/config"] + LIBPATH,
+ LIBPATH= LIBPATH,
LIBS= LIBS,
RPATH = LIBPATH, #include information where shared libraries can be found to avoid errors like: "ImportError: libboost_python-gcc42-mt-1_34_1.so.1.34.1: cannot open shared object file: No such file or directory"
SHLIBPREFIX="", #gets rid of lib prefix
@@ -49,8 +47,11 @@ env = Environment(
Export('env')
Export('adolc_include_path')
SConscript('adolc/SConscript')
-#SConscript('adolc/sparse/SConscript')
+SConscript('adolc/sparse/SConscript')
+SConscript('adolc/colpack/SConscript')
+
+# SConscript('tests/misc_tests/adolc_tiny_unit_test/SConscript')
-env.Install( target='./build/adolc/', source = ['adolc/__init__.py','adolc/wrapped_functions.py', 'adolc/cgraph.py','adolc/_adolc.so'])
+# env.Install( target='./build/adolc/', source = ['adolc/__init__.py','adolc/wrapped_functions.py', 'adolc/cgraph.py','adolc/_adolc.so'])
#env.Install( target='./build/adolc/sparse/', source = ['adolc/sparse/__init__.py', 'adolc/sparse/_colpack.so', 'adolc/sparse/wrapped_functions.py'])
550 adolc/colpack/tests/test_wrapped_functions.py
View
@@ -7,8 +7,9 @@
from adolc import *
class SparseFunctionalityTests(TestCase):
+
- def test_jac_pat(self):
+ def test_sparse_jac_no_repeat(self):
N = 3 # dimension
M = 2 # codimension
def vector_f(x):
@@ -24,351 +25,306 @@ def vector_f(x):
trace_off()
options = numpy.array([1,1,0,0],dtype=int)
- pat = sparse.jac_pat(1,x,options)
-
- pat = numpy.asarray(pat,dtype=int)
- correct_pat = numpy.array([[0,1],[1,2]], dtype=int)
- assert_array_equal(pat, correct_pat)
-
- # def test_sparse_jac_no_repeat(self):
- # N = 3 # dimension
- # M = 2 # codimension
- # def vector_f(x):
- # return numpy.array([x[0]*x[1],x[1]*x[2]])
-
- # x = numpy.array([1.*n +1. for n in range(N)])
- # ax = adouble(x)
-
- # trace_on(1)
- # independent(ax)
- # ay = vector_f(ax)
- # dependent(ay)
- # trace_off()
-
- # options = numpy.array([1,1,0,0],dtype=int)
- # result = sparse.sparse_jac_no_repeat(1,x,options)
- # correct_nnz = 4
- # correct_rind = numpy.array([0,0,1,1])
- # corrent_cind = numpy.array([0,1,1,2])
- # correct_values = numpy.array([2.,1.,3.,2.])
-
- # assert_equal(result[0], correct_nnz)
- # assert_array_equal(result[1], correct_rind)
- # assert_array_equal(result[2], corrent_cind)
- # assert_array_almost_equal(result[3], correct_values)
-
- # def test_sparse_jac_with_repeat(self):
- # N = 3 # dimension
- # M = 2 # codimension
- # def vector_f(x):
- # return numpy.array([x[0]*x[1],x[1]*x[2]])
-
- # x = numpy.array([1.*n +1. for n in range(N)])
- # ax = adouble(x)
-
- # trace_on(1)
- # independent(ax)
- # ay = vector_f(ax)
- # dependent(ay)
- # trace_off()
+ result = colpack.sparse_jac_no_repeat(1,x,options)
+ correct_nnz = 4
+ correct_rind = numpy.array([0,0,1,1])
+ corrent_cind = numpy.array([0,1,1,2])
+ correct_values = numpy.array([2.,1.,3.,2.])
+
+ assert_equal(result[0], correct_nnz)
+ assert_array_equal(result[1], correct_rind)
+ assert_array_equal(result[2], corrent_cind)
+ assert_array_almost_equal(result[3], correct_values)
+
+ def test_sparse_jac_with_repeat(self):
+ N = 3 # dimension
+ M = 2 # codimension
+ def vector_f(x):
+ return numpy.array([x[0]*x[1],x[1]*x[2]])
- # options = numpy.array([1,1,0,0],dtype=int)
+ x = numpy.array([1.*n +1. for n in range(N)])
+ ax = adouble(x)
+
+ trace_on(1)
+ independent(ax)
+ ay = vector_f(ax)
+ dependent(ay)
+ trace_off()
- # # first call
- # result = sparse.sparse_jac_no_repeat(1,x,options)
+ options = numpy.array([1,1,0,0],dtype=int)
- # # second call
- # x = numpy.array([1.*n +2. for n in range(N)])
- # result = sparse.sparse_jac_repeat(1,x, result[0], result[1], result[2], result[3])
+ # first call
+ result = colpack.sparse_jac_no_repeat(1,x,options)
- # correct_nnz = 4
- # correct_rind = numpy.array([0,0,1,1])
- # corrent_cind = numpy.array([0,1,1,2])
- # correct_values = numpy.array([3.,2.,4.,3.])
+ # second call
+ x = numpy.array([1.*n +2. for n in range(N)])
+ result = colpack.sparse_jac_repeat(1,x, result[0], result[1], result[2], result[3])
- # assert_equal(result[0], correct_nnz)
- # assert_array_equal(result[1], correct_rind)
- # assert_array_equal(result[2], corrent_cind)
- # assert_array_almost_equal(result[3], correct_values)
+ correct_nnz = 4
+ correct_rind = numpy.array([0,0,1,1])
+ corrent_cind = numpy.array([0,1,1,2])
+ correct_values = numpy.array([3.,2.,4.,3.])
- def test_hess_pat(self):
- N = 3 # dimension
+ assert_equal(result[0], correct_nnz)
+ assert_array_equal(result[1], correct_rind)
+ assert_array_equal(result[2], corrent_cind)
+ assert_array_almost_equal(result[3], correct_values)
+ def test_sparse_hess_no_repeat(self):
+ N1 = 3 # dimension
def scalar_f(x):
return x[0]*x[1] + x[1]*x[2] + x[2]*x[0]
+
+ def scalar_f2(x):
+ return x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2]
- x = numpy.array([1.*n +1. for n in range(N)])
- ax = adouble(x)
+ x1 = numpy.array([1.*n +1. for n in range(N1)])
+ ax1 = adouble(x1)
trace_on(1)
- independent(ax)
- ay = scalar_f(ax)
+ independent(ax1)
+ ay = scalar_f(ax1)
dependent(ay)
trace_off()
- option = 0
- pat = sparse.hess_pat(1,x,option)
- pat = numpy.asarray(pat,dtype=int)
-
- correct_pat = numpy.array([[1,2],[0,2], [0,1]], dtype=int)
- assert_array_equal(pat, correct_pat)
-
+ options = numpy.array([0,0],dtype=int)
+ result = colpack.sparse_hess_no_repeat(1, x1, options)
+ correct_nnz = 3
- # def test_sparse_hess_no_repeat(self):
- # N1 = 3 # dimension
- # def scalar_f(x):
- # return x[0]*x[1] + x[1]*x[2] + x[2]*x[0]
-
- # def scalar_f2(x):
- # return x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2]
+ correct_rind = numpy.array([0,0,1])
+ corrent_cind = numpy.array([1,2,2])
+ correct_values = numpy.array([1.,1.,1.])
- # x1 = numpy.array([1.*n +1. for n in range(N1)])
- # ax1 = adouble(x1)
-
- # trace_on(1)
- # independent(ax1)
- # ay = scalar_f(ax1)
- # dependent(ay)
- # trace_off()
-
- # options = numpy.array([0,0],dtype=int)
- # result = sparse.sparse_hess_no_repeat(1, x1, options)
- # correct_nnz = 3
-
- # correct_rind = numpy.array([0,0,1])
- # corrent_cind = numpy.array([1,2,2])
- # correct_values = numpy.array([1.,1.,1.])
-
- # assert_equal(result[0], correct_nnz)
- # assert_array_equal(result[1], correct_rind)
- # assert_array_equal(result[2], corrent_cind)
- # assert_array_almost_equal(result[3], correct_values)
+ assert_equal(result[0], correct_nnz)
+ assert_array_equal(result[1], correct_rind)
+ assert_array_equal(result[2], corrent_cind)
+ assert_array_almost_equal(result[3], correct_values)
- # N2 = 4
- # x2 = numpy.array([1.*n +1. for n in range(N2)])
+ N2 = 4
+ x2 = numpy.array([1.*n +1. for n in range(N2)])
- # trace_on(2)
- # ax2 = adouble(x2)
- # independent(ax2)
- # ay = scalar_f2(ax2)
- # dependent(ay)
- # trace_off()
+ trace_on(2)
+ ax2 = adouble(x2)
+ independent(ax2)
+ ay = scalar_f2(ax2)
+ dependent(ay)
+ trace_off()
- # options = numpy.array([0,0],dtype=int)
- # for i in range(10):
- # result = sparse.sparse_hess_no_repeat(2, x2, options)
+ options = numpy.array([0,0],dtype=int)
+ for i in range(10):
+ result = colpack.sparse_hess_no_repeat(2, x2, options)
- # def test_sparse_hess_repeat(self):
- # N = 3 # dimension
+ def test_sparse_hess_repeat(self):
+ N = 3 # dimension
- # def scalar_f(x):
- # return x[0]**3 + x[0]*x[1] + x[1]*x[2] + x[2]*x[0]
+ def scalar_f(x):
+ return x[0]**3 + x[0]*x[1] + x[1]*x[2] + x[2]*x[0]
- # x = numpy.array([1.*n +1. for n in range(N)])
- # ax = adouble(x)
+ x = numpy.array([1.*n +1. for n in range(N)])
+ ax = adouble(x)
- # trace_on(1)
- # independent(ax)
- # ay = scalar_f(ax)
- # dependent(ay)
- # trace_off()
+ trace_on(1)
+ independent(ax)
+ ay = scalar_f(ax)
+ dependent(ay)
+ trace_off()
- # options = numpy.array([1,1],dtype=int)
+ options = numpy.array([1,1],dtype=int)
- # # first call
- # result = sparse.sparse_hess_no_repeat(1,x,options)
+ # first call
+ result = colpack.sparse_hess_no_repeat(1,x,options)
- # # second call
- # x = numpy.array([1.*n +2. for n in range(N)])
- # result = sparse.sparse_hess_repeat(1,x, result[1], result[2], result[3])
+ # second call
+ x = numpy.array([1.*n +2. for n in range(N)])
+ result = colpack.sparse_hess_repeat(1,x, result[1], result[2], result[3])
- # correct_nnz = 4
+ correct_nnz = 4
- # correct_rind = numpy.array([0,0,0,1])
- # corrent_cind = numpy.array([0,1,2,2])
- # correct_values = numpy.array([6*x[0],1.,1.,1.])
+ correct_rind = numpy.array([0,0,0,1])
+ corrent_cind = numpy.array([0,1,2,2])
+ correct_values = numpy.array([6*x[0],1.,1.,1.])
- # assert_equal(result[0], correct_nnz)
- # assert_array_equal(result[1], correct_rind)
- # assert_array_equal(result[2], corrent_cind)
- # assert_array_almost_equal(result[3], correct_values)
+ assert_equal(result[0], correct_nnz)
+ assert_array_equal(result[1], correct_rind)
+ assert_array_equal(result[2], corrent_cind)
+ assert_array_almost_equal(result[3], correct_values)
- # def test_sparse_problem(self):
- # return 0
- # import scipy.sparse
+ def test_sparse_problem(self):
+ return 0
+ import scipy.sparse
- # nvar = 4
- # ncon = 2
-
- # def eval_f(x, user_data = None):
- # assert len(x) == 4
- # return x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2]
-
- # def eval_grad_f(x, user_data = None):
- # assert len(x) == 4
- # grad_f = numpy.array([
- # x[0] * x[3] + x[3] * (x[0] + x[1] + x[2]) ,
- # x[0] * x[3],
- # x[0] * x[3] + 1.0,
- # x[0] * (x[0] + x[1] + x[2])
- # ])
- # return grad_f;
+ nvar = 4
+ ncon = 2
+
+ def eval_f(x, user_data = None):
+ assert len(x) == 4
+ return x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2]
+
+ def eval_grad_f(x, user_data = None):
+ assert len(x) == 4
+ grad_f = numpy.array([
+ x[0] * x[3] + x[3] * (x[0] + x[1] + x[2]) ,
+ x[0] * x[3],
+ x[0] * x[3] + 1.0,
+ x[0] * (x[0] + x[1] + x[2])
+ ])
+ return grad_f;
- # def eval_g(x, user_data= None):
- # assert len(x) == 4
- # return numpy.array([
- # x[0] * x[1] * x[2] * x[3],
- # x[0]*x[0] + x[1]*x[1] + x[2]*x[2] + x[3]*x[3]
- # ])
-
- # nnzj = 8
- # def eval_jac_g(x, flag, user_data = None):
- # if flag:
- # return (numpy.array([0, 0, 0, 0, 1, 1, 1, 1]),
- # numpy.array([0, 1, 2, 3, 0, 1, 2, 3]))
- # else:
- # assert len(x) == 4
- # return numpy.array([ x[1]*x[2]*x[3],
- # x[0]*x[2]*x[3],
- # x[0]*x[1]*x[3],
- # x[0]*x[1]*x[2],
- # 2.0*x[0],
- # 2.0*x[1],
- # 2.0*x[2],
- # 2.0*x[3] ])
+ def eval_g(x, user_data= None):
+ assert len(x) == 4
+ return numpy.array([
+ x[0] * x[1] * x[2] * x[3],
+ x[0]*x[0] + x[1]*x[1] + x[2]*x[2] + x[3]*x[3]
+ ])
+
+ nnzj = 8
+ def eval_jac_g(x, flag, user_data = None):
+ if flag:
+ return (numpy.array([0, 0, 0, 0, 1, 1, 1, 1]),
+ numpy.array([0, 1, 2, 3, 0, 1, 2, 3]))
+ else:
+ assert len(x) == 4
+ return numpy.array([ x[1]*x[2]*x[3],
+ x[0]*x[2]*x[3],
+ x[0]*x[1]*x[3],
+ x[0]*x[1]*x[2],
+ 2.0*x[0],
+ 2.0*x[1],
+ 2.0*x[2],
+ 2.0*x[3] ])
- # nnzh = 10
- # def eval_h(x, lagrange, obj_factor, flag, user_data = None):
- # if flag:
- # hrow = [0, 1, 1, 2, 2, 2, 3, 3, 3, 3]
- # hcol = [0, 0, 1, 0, 1, 2, 0, 1, 2, 3]
- # return (numpy.array(hcol,dtype=int), numpy.array(hrow,dtype=int))
- # else:
- # values = numpy.zeros((10), numpy.float_)
- # values[0] = obj_factor * (2*x[3])
- # values[1] = obj_factor * (x[3])
- # values[2] = 0
- # values[3] = obj_factor * (x[3])
- # values[4] = 0
- # values[5] = 0
- # values[6] = obj_factor * (2*x[0] + x[1] + x[2])
- # values[7] = obj_factor * (x[0])
- # values[8] = obj_factor * (x[0])
- # values[9] = 0
- # values[1] += lagrange[0] * (x[2] * x[3])
-
- # values[3] += lagrange[0] * (x[1] * x[3])
- # values[4] += lagrange[0] * (x[0] * x[3])
-
- # values[6] += lagrange[0] * (x[1] * x[2])
- # values[7] += lagrange[0] * (x[0] * x[2])
- # values[8] += lagrange[0] * (x[0] * x[1])
- # values[0] += lagrange[1] * 2
- # values[2] += lagrange[1] * 2
- # values[5] += lagrange[1] * 2
- # values[9] += lagrange[1] * 2
- # return values
-
-
- # x0 = numpy.array([1.0, 5.0, 5.0, 1.0])
-
- # # check that adolc gives the same answers as derivatives calculated by hand
- # trace_on(1)
- # ax = adouble(x0)
- # independent(ax)
- # ay = eval_f(ax)
- # dependent(ay)
- # trace_off()
-
- # trace_on(2)
- # ax = adouble(x0)
- # independent(ax)
- # ay = eval_g(ax)
- # dependent(ay)
- # trace_off()
+ nnzh = 10
+ def eval_h(x, lagrange, obj_factor, flag, user_data = None):
+ if flag:
+ hrow = [0, 1, 1, 2, 2, 2, 3, 3, 3, 3]
+ hcol = [0, 0, 1, 0, 1, 2, 0, 1, 2, 3]
+ return (numpy.array(hcol,dtype=int), numpy.array(hrow,dtype=int))
+ else:
+ values = numpy.zeros((10), numpy.float_)
+ values[0] = obj_factor * (2*x[3])
+ values[1] = obj_factor * (x[3])
+ values[2] = 0
+ values[3] = obj_factor * (x[3])
+ values[4] = 0
+ values[5] = 0
+ values[6] = obj_factor * (2*x[0] + x[1] + x[2])
+ values[7] = obj_factor * (x[0])
+ values[8] = obj_factor * (x[0])
+ values[9] = 0
+ values[1] += lagrange[0] * (x[2] * x[3])
+
+ values[3] += lagrange[0] * (x[1] * x[3])
+ values[4] += lagrange[0] * (x[0] * x[3])
+
+ values[6] += lagrange[0] * (x[1] * x[2])
+ values[7] += lagrange[0] * (x[0] * x[2])
+ values[8] += lagrange[0] * (x[0] * x[1])
+ values[0] += lagrange[1] * 2
+ values[2] += lagrange[1] * 2
+ values[5] += lagrange[1] * 2
+ values[9] += lagrange[1] * 2
+ return values
+
+
+ x0 = numpy.array([1.0, 5.0, 5.0, 1.0])
+
+ # check that adolc gives the same answers as derivatives calculated by hand
+ trace_on(1)
+ ax = adouble(x0)
+ independent(ax)
+ ay = eval_f(ax)
+ dependent(ay)
+ trace_off()
+
+ trace_on(2)
+ ax = adouble(x0)
+ independent(ax)
+ ay = eval_g(ax)
+ dependent(ay)
+ trace_off()
- # trace_on(3)
- # ax = adouble(x0)
- # independent(ax)
- # ay = eval_g(ax)
- # dependent(ay[0])
- # trace_off()
+ trace_on(3)
+ ax = adouble(x0)
+ independent(ax)
+ ay = eval_g(ax)
+ dependent(ay[0])
+ trace_off()
- # trace_on(4)
- # ax = adouble(x0)
- # independent(ax)
- # ay = eval_g(ax)
- # dependent(ay[1])
- # trace_off()
+ trace_on(4)
+ ax = adouble(x0)
+ independent(ax)
+ ay = eval_g(ax)
+ dependent(ay[1])
+ trace_off()
- # def eval_f_adolc(x, user_data = None):
- # return function(1,x)[0]
+ def eval_f_adolc(x, user_data = None):
+ return function(1,x)[0]
- # def eval_grad_f_adolc(x, user_data = None):
- # return gradient(1,x)
+ def eval_grad_f_adolc(x, user_data = None):
+ return gradient(1,x)
- # def eval_g_adolc(x, user_data= None):
- # return function(2,x)
+ def eval_g_adolc(x, user_data= None):
+ return function(2,x)
- # def eval_jac_g_adolc(x, flag, user_data = None):
- # options = numpy.array([1,1,0,0],dtype=int)
- # result = sparse.sparse_jac_no_repeat(2,x,options)
- # if flag:
- # return (numpy.asarray(result[1],dtype=int), numpy.asarray(result[2],dtype=int))
- # else:
- # return result[3]
+ def eval_jac_g_adolc(x, flag, user_data = None):
+ options = numpy.array([1,1,0,0],dtype=int)
+ result = colpack.sparse_jac_no_repeat(2,x,options)
+ if flag:
+ return (numpy.asarray(result[1],dtype=int), numpy.asarray(result[2],dtype=int))
+ else:
+ return result[3]
- # def eval_h_adolc(x, lagrange, obj_factor, flag, user_data = None):
- # options = numpy.array([0,0],dtype=int)
- # assert numpy.ndim(x) == 1
- # assert numpy.size(x) == 4
- # result_f = sparse.sparse_hess_no_repeat(1, x, options)
- # result_g0 = sparse.sparse_hess_no_repeat(3, x,options)
- # result_g1 = sparse.sparse_hess_no_repeat(4, x,options)
- # Hf = scipy.sparse.coo_matrix( (result_f[3], (result_f[1], result_f[2])), shape=(4, 4))
- # Hg0 = scipy.sparse.coo_matrix( (result_g0[3], (result_g0[1], result_g0[2])), shape=(4, 4))
- # Hg1 = scipy.sparse.coo_matrix( (result_g1[3], (result_g1[1], result_g1[2])), shape=(4, 4))
+ def eval_h_adolc(x, lagrange, obj_factor, flag, user_data = None):
+ options = numpy.array([0,0],dtype=int)
+ assert numpy.ndim(x) == 1
+ assert numpy.size(x) == 4
+ result_f = colpack.sparse_hess_no_repeat(1, x, options)
+ result_g0 = colpack.sparse_hess_no_repeat(3, x,options)
+ result_g1 = colpack.sparse_hess_no_repeat(4, x,options)
+ Hf = scipy.sparse.coo_matrix( (result_f[3], (result_f[1], result_f[2])), shape=(4, 4))
+ Hg0 = scipy.sparse.coo_matrix( (result_g0[3], (result_g0[1], result_g0[2])), shape=(4, 4))
+ Hg1 = scipy.sparse.coo_matrix( (result_g1[3], (result_g1[1], result_g1[2])), shape=(4, 4))
- # H = Hf + Hg0 + Hg1
- # H = H.tocoo()
+ H = Hf + Hg0 + Hg1
+ H = H.tocoo()
- # if flag:
- # hrow = H.row
- # hcol = H.col
- # return (numpy.array(hcol,dtype=int), numpy.array(hrow,dtype=int))
-
- # else:
- # values = numpy.zeros((10), float)
- # values[:] = H.data
- # return values
-
- # # function of f
- # assert_almost_equal(eval_f(x0), eval_f_adolc(x0))
+ if flag:
+ hrow = H.row
+ hcol = H.col
+ return (numpy.array(hcol,dtype=int), numpy.array(hrow,dtype=int))
+
+ else:
+ values = numpy.zeros((10), float)
+ values[:] = H.data
+ return values
+
+ # function of f
+ assert_almost_equal(eval_f(x0), eval_f_adolc(x0))
- # # gradient of f
- # assert_array_almost_equal(eval_grad_f(x0), eval_grad_f_adolc(x0))
+ # gradient of f
+ assert_array_almost_equal(eval_grad_f(x0), eval_grad_f_adolc(x0))
- # # function of g
- # assert_array_almost_equal(eval_g(x0), function(2,x0))
+ # function of g
+ assert_array_almost_equal(eval_g(x0), function(2,x0))
- # # sparse jacobian of g
- # assert_array_equal(eval_jac_g_adolc(x0,True)[0], eval_jac_g(x0,True)[0])
- # assert_array_equal(eval_jac_g_adolc(x0,True)[1], eval_jac_g(x0,True)[1])
- # assert_array_equal(eval_jac_g_adolc(x0,False), eval_jac_g(x0,False))
+ # sparse jacobian of g
+ assert_array_equal(eval_jac_g_adolc(x0,True)[0], eval_jac_g(x0,True)[0])
+ assert_array_equal(eval_jac_g_adolc(x0,True)[1], eval_jac_g(x0,True)[1])
+ assert_array_equal(eval_jac_g_adolc(x0,False), eval_jac_g(x0,False))
- # # sparse hessian of the lagrangian
- # lagrange = numpy.ones(2,dtype=float)
- # obj_factor = 1.
- # x0 = numpy.random.rand(4)
- # result = (eval_h(x0, lagrange, obj_factor, False), eval_h(x0, lagrange, obj_factor, True))
- # result_adolc = (eval_h_adolc(x0, lagrange, obj_factor, False), eval_h_adolc(x0, lagrange, obj_factor, True))
- # H = scipy.sparse.coo_matrix( result, shape=(4, 4))
- # H_adolc = scipy.sparse.coo_matrix( result_adolc, shape=(4, 4))
- # H = H.todense()
- # H_adolc = H_adolc.todense()
- # assert_array_almost_equal( H, H_adolc.T)
+ # sparse hessian of the lagrangian
+ lagrange = numpy.ones(2,dtype=float)
+ obj_factor = 1.
+ x0 = numpy.random.rand(4)
+ result = (eval_h(x0, lagrange, obj_factor, False), eval_h(x0, lagrange, obj_factor, True))
+ result_adolc = (eval_h_adolc(x0, lagrange, obj_factor, False), eval_h_adolc(x0, lagrange, obj_factor, True))
+ H = scipy.sparse.coo_matrix( result, shape=(4, 4))
+ H_adolc = scipy.sparse.coo_matrix( result_adolc, shape=(4, 4))
+ H = H.todense()
+ H_adolc = H_adolc.todense()
+ assert_array_almost_equal( H, H_adolc.T)
if __name__ == '__main__':
41 adolc/tests/test_wrapped_functions_complicated.py
View
@@ -162,47 +162,6 @@ def dO_tilde(u):
U = 100*numpy.ones((M,M),dtype=float)
Z,s = projected_gradients(u,O_tilde,dO_tilde,[L,U])
-
-
- # THIS CODE BELOW ONLY WORKS FOR MATPLOTLIB 0.91X
- try:
- import pylab
- import matplotlib.axes3d as p3
-
- x = y = range(numpy.shape(Z)[0])
- X,Y = numpy.meshgrid(x_grid,y_grid)
-
- fig=pylab.figure()
- ax = p3.Axes3D(fig)
- ax.plot_wireframe(X,Y,Z)
-
- xs = Z + s
- for n in range(M):
- for m in range(M):
- ax.plot3d([x_grid[m],x_grid[m]], [ y_grid[n], y_grid[n]], [Z[n,m], xs[n,m]], 'r')
- ax.set_xlabel('X')
- ax.set_ylabel('Y')
- ax.set_zlabel('Z')
- pylab.title('Minimal Surface')
- pylab.savefig('./3D_plot.png')
- pylab.savefig('./3D_plot.eps')
-
- #pylab.show()
- except:
- print '3d plotting with matplotlib failed'
- pass
-
- # Plot with MAYAVI
- try:
- import enthought.mayavi.mlab as mlab
- mlab.figure()
- mlab.view(azimuth=130)
- s = mlab.surf(x, y, Z, representation='wireframe', warp_scale='auto', line_width=1.)
- mlab.savefig('./mayavi_3D_plot.png')
- #mlab.show()
-
- except:
- pass
class TestChemicalReaction(TestCase):
24 setup.py.EXAMPLE
View
@@ -17,11 +17,14 @@ from numpy.distutils.misc_util import get_numpy_include_dirs
# ADAPT THIS TO FIT YOUR SYSTEM
extra_compile_args = ['-ftemplate-depth-100 -DBOOST_PYTHON_DYNAMIC_LIB']
-include_dirs = [get_numpy_include_dirs(),'/home/b45ch1/workspace/ADOL-C/trunk/ADOL-C/src']
-library_dirs = ['/home/b45ch1/workspace/ADOL-C/trunk/ADOL-C/src/.libs']
-libraries = ['boost_python','adolc']
-
+include_dirs = [get_numpy_include_dirs()[0],'/home/b45ch1/workspace/ADOL-C/trunk/ADOL-C','/home/b45ch1/workspace/ColPack/build/include']
+library_dirs = ['/home/b45ch1/workspace/ADOL-C/trunk/ADOL-C/src/.libs','/home/b45ch1/workspace/ColPack/build/lib']
+libraries = ['boost_python','adolc', 'ColPack']
+print ''
+print 'please check that the following settings are correct for your system'
+print 'include_dirs = %s\n'%str(include_dirs)
+print 'library_dirs = %s\n'%str(library_dirs)
# PACKAGE INFORMATION
CLASSIFIERS = """\
@@ -135,10 +138,15 @@ options_dict.update({
'packages' :packages,
'ext_package' : 'adolc',
'ext_modules': [Extension('_adolc', ['adolc/src/py_adolc.cpp', 'adolc/src/num_util.cpp'],
- include_dirs = ['adolc/src'] + include_dirs,
- library_dirs = library_dirs,
- runtime_library_dirs = library_dirs,
- libraries = libraries),
+ include_dirs = ['adolc/src'] + include_dirs,
+ library_dirs = library_dirs,
+ runtime_library_dirs = library_dirs,
+ libraries = libraries),
+ Extension('sparse/_sparse', ['adolc/sparse/src/py_sparse_adolc.cpp', 'adolc/sparse/src/num_util.cpp'],
+ include_dirs = ['adolc/sparse/src'] + include_dirs,
+ library_dirs = library_dirs,
+ runtime_library_dirs = library_dirs,
+ libraries = libraries),
Extension('sparse/_sparse', ['adolc/sparse/src/py_sparse_adolc.cpp', 'adolc/sparse/src/num_util.cpp'],
include_dirs = ['adolc/sparse/src'] + include_dirs,
library_dirs = library_dirs,
Please sign in to comment.
Something went wrong with that request. Please try again.