[SciPy-user] Automatic Differentiation with PYADOLC and Removing Boost::Python dependency

Sebastian Walter sebastian.walter@gmail....
Thu Mar 26 07:22:03 CDT 2009


hey, thanks for the bug report!

Yes, that's something I have expected since I didn't have the chance
to compile it on a 64bit system.
I was a little lax with the integers! I guess I'll have to use
npy_intp instead of int in some places.
Shouldn't take too long to fix, but I have to set up a 64bit Linux first.






On Thu, Mar 26, 2009 at 12:35 PM, Nils Wagner
<nwagner@iam.uni-stuttgart.de> wrote:
> On Thu, 26 Mar 2009 10:50:24 +0100
>  Sebastian Walter <sebastian.walter@gmail.com> wrote:
>> Hello,
>>
>> I have implemented a wrapper for  the C++ Automatic
>>Differentiation
>> (AD) tool ADOL-C.
>> You can use it to differentiate complex algorithms to
>>arbitrary order.
>> It works quite well with numpy.
>>
>> You can have a look at it at
>>http://github.com/b45ch1/pyadolc .
>>
>> EXAMPLE USAGE:
>> ==============
>> compute the Jacobian J of
>> f(x) = numpy.dot(A,x), where A is an (N,M) array
>>
>>
>> --------------- get_started.py ----------------------
>> import numpy
>> from adolc import *
>>
>> N = M = 10
>> A = numpy.zeros((M,N))
>> A[:] = [[ 1./N +(n==m) for n in range(N)] for m in
>>range(M)]
>>
>>
>> def f(x):
>>       return numpy.dot(A,x)
>>
>> # tape a function evaluation
>> ax = numpy.array([adouble(0) for n in range(N)])
>> trace_on(1)
>> independent(ax)
>> ay = f(ax)
>> dependent(ay)
>> trace_off()
>>
>>
>> x = numpy.array([n+1 for n in range(N)])
>>
>> # compute jacobian of f at x
>> J = jacobian(1,x)
>>
>> # compute gradient of f at x
>> if M==1:
>>       g = gradient(1,x)
>>
>> --------------- end get_started.py
>>----------------------
>>
>>
>> PERFORMANCE:
>> =============
>>
>> It is really fast compared to existing  AD tools for
>>Python as for
>> example Scientific.Functions.Derivatives.
>> Benchmark available at
>> http://github.com/b45ch1/pyadolc/blob/239a18c773c19a71bb5508dee175473a2fad7c83/tests/speed_comparison_pyadolc_ScientificPythonFunctionsDerivatives/pyadolc_vs_scientific_python.py
>>
>> compute hessian of:
>> def f(x):
>>       return 0.5*dot(x,dot(A,x))
>>
>> Runtime comparison:
>> adolc: elapsed time = 0.000411 sec
>> Scientific: elapsed time = 0.041264 sec
>> ratio time  adolc/Scientific Python:  0.009961
>>
>> I.e.  pyadolc  is a factor 100 faster.
>>
>>
>>
>> Removing Boost::Python dependency ?
>> ===============================
>>
>> I have used Boost::Python to wrap it, but I am not happy
>>with that
>> additional dependency!
>> So I wondered if someone could give me advice how to
>>avoid users
>> having to download and install boost::python to use
>>pyadolc.
>> (include boost::python sources ? port to C API?)
>>
>>
>> best regards,
>> Sebastian Walter
>> _______________________________________________
>> SciPy-user mailing list
>> SciPy-user@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
> Hi all,
>
> I tried to install pyadolc on an x86_64 box.
>
> python setup.py build
> running build
> running config_cc
> unifing config_cc, config, build_clib, build_ext, build
> commands --compiler options
> running config_fc
> unifing config_fc, config, build_clib, build_ext, build
> commands --fcompiler options
> running build_src
> building extension "_adolc" sources
> running build_ext
> customize UnixCCompiler
> customize UnixCCompiler using build_ext
> customize UnixCCompiler
> customize UnixCCompiler using build_ext
> building '_adolc' extension
> compiling C++ sources
> C compiler: g++ -pthread -fno-strict-aliasing -DNDEBUG -g
> -O3 -Wall -fPIC
>
> creating build
> creating build/temp.linux-x86_64-2.5
> compile options:
> '-I/data/home/nwagner/local/lib/python2.5/site-packages/numpy/core/include
> -I./adolc-2.0.0
> -I/data/home/nwagner/local/lib/python2.5/site-packages/numpy/core/include
> -I/data/home/nwagner/local/include/python2.5 -c'
> extra options: '-ftemplate-depth-100
> -DBOOST_PYTHON_DYNAMIC_LIB'
> g++: ./py_adolc.cpp
> ./num_util.h: In function `boost::python::numeric::array
> num_util::makeNum(T*, npy_intp) [with T = double]':
> ./py_adolc.cpp:62:   instantiated from here
> ./num_util.h:76: Fehler: »npy_intp*« kann nicht nach
> »int*« in argument passing umgewandelt werden
> ./num_util.h: In function `boost::python::numeric::array
> num_util::makeNum(T*, std::vector<npy_intp,
> std::allocator<npy_intp> >) [with T = double]':
> ./py_adolc.cpp:86:   instantiated from here
> ./num_util.h:94: Fehler: »npy_intp*« kann nicht nach
> »int*« in argument passing umgewandelt werden
> ./num_util.h: In function `boost::python::numeric::array
> num_util::makeNum(T*, std::vector<npy_intp,
> std::allocator<npy_intp> >) [with T = short int]':
> ./py_adolc.cpp:417:   instantiated from here
> ./num_util.h:94: Fehler: »npy_intp*« kann nicht nach
> »int*« in argument passing umgewandelt werden
> ./num_util.h: In function `boost::python::numeric::array
> num_util::makeNum(T*, npy_intp) [with T = double]':
> ./py_adolc.cpp:62:   instantiated from here
> ./num_util.h:76: Fehler: »npy_intp*« kann nicht nach
> »int*« in argument passing umgewandelt werden
> ./num_util.h: In function `boost::python::numeric::array
> num_util::makeNum(T*, std::vector<npy_intp,
> std::allocator<npy_intp> >) [with T = double]':
> ./py_adolc.cpp:86:   instantiated from here
> ./num_util.h:94: Fehler: »npy_intp*« kann nicht nach
> »int*« in argument passing umgewandelt werden
> ./num_util.h: In function `boost::python::numeric::array
> num_util::makeNum(T*, std::vector<npy_intp,
> std::allocator<npy_intp> >) [with T = short int]':
> ./py_adolc.cpp:417:   instantiated from here
> ./num_util.h:94: Fehler: »npy_intp*« kann nicht nach
> »int*« in argument passing umgewandelt werden
> error: Command "g++ -pthread -fno-strict-aliasing -DNDEBUG
> -g -O3 -Wall -fPIC
> -I/data/home/nwagner/local/lib/python2.5/site-packages/numpy/core/include
> -I./adolc-2.0.0
> -I/data/home/nwagner/local/lib/python2.5/site-packages/numpy/core/include
> -I/data/home/nwagner/local/include/python2.5 -c
> ./py_adolc.cpp -o build/temp.linux-x86_64-2.5/py_adolc.o
> -ftemplate-depth-100 -DBOOST_PYTHON_DYNAMIC_LIB" failed
> with exit status 1
>
>
> How can I fix the problem ?
>
> Nils
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-user mailing list