Skip to content

Commit

Permalink
added an experimental_tests.py file to run some tests that are likely…
Browse files Browse the repository at this point in the history
… to be trouble

improved the tape equivalence example: uses the <<= operator to reduce the num_max_lives
adouble( adub(x)) now works
  • Loading branch information
b45ch1 committed Jul 14, 2009
1 parent de419cb commit ce06df9
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 16 deletions.
3 changes: 2 additions & 1 deletion adolc.py
Expand Up @@ -45,8 +45,9 @@ def adouble(x):
""" """
if numpy.isscalar(x): if numpy.isscalar(x):
return _adolc.adouble(float(x)) return _adolc.adouble(float(x))
elif isinstance(x,_adolc.adouble): elif isinstance(x,_adolc.adouble) or isinstance(x,_adolc.adub):
return _adolc.adouble(x) return _adolc.adouble(x)

else: else:
x = numpy.asarray(x, dtype=float) x = numpy.asarray(x, dtype=float)
shp = numpy.shape(x) shp = numpy.shape(x)
Expand Down
5 changes: 4 additions & 1 deletion tests/.gitignore
@@ -1,2 +1,5 @@
jac_pat.mtx jac_pat.mtx
!*.png !*.png

*.tap
tape_0.tex
30 changes: 30 additions & 0 deletions tests/experimental_tests.py
@@ -0,0 +1,30 @@
import numpy
from adolc import *
def test_big_tape():
"""
Hmm, this should raise an error because num_max_lives is bigger than the value buffer
"""
N = 65534*4

ay = adouble(0.)
ax = adouble(0.)
x = 1.

# usual way: leads to increasing locints
trace_on(0)
independent(ax)
ay = ax
for i in range(N):
ay = ay * ay

dependent(ay)
trace_off()

print tapestats(0)
print function(0,[1.])
#tape_to_latex(0,numpy.array([1.]),numpy.array([0.]))



if __name__ == "__main__":
test_big_tape()
25 changes: 25 additions & 0 deletions tests/speed_comparison_PyADOLC_ADOLC/SConstruct.EXAMPLE
@@ -0,0 +1,25 @@
adolc_include_path = '/home/basti/workspace/adolc-2.0.0'
adolc_library_path = '/home/basti/workspace/adolc-2.0.0/adolc/.libs'

LIBS = ['adolc',
]
LIBPATH = [
adolc_library_path,
]
INCLUDEPATH = [
adolc_include_path,
'/usr/include/python2.5'
]


env = Environment(
CPPPATH = INCLUDEPATH,
CXXFLAGS= "-ftemplate-depth-100 -Wall -O2",
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, i.e. get mylib.so instead of libmylib.so
)
Default('.')
my_executable = env.Program(target='benchmark.exe', source=['benchmark.cpp'])

3 changes: 3 additions & 0 deletions tests/speed_comparison_PyADOLC_ADOLC/benchmark.py
Expand Up @@ -24,6 +24,9 @@ def benchmark(f,N,M,message):
dependent(ay) dependent(ay)
trace_off() trace_off()
#tape_to_latex(1,x,y) #tape_to_latex(1,x,y)

print 'N=%d,M=%d'%(N,M)

runtime_taping = time.time() - start_time runtime_taping = time.time() - start_time
print 'PyADOLC\tfunction taping:\t........\telapsed time: %f'%runtime_taping print 'PyADOLC\tfunction taping:\t........\telapsed time: %f'%runtime_taping


Expand Down
19 changes: 6 additions & 13 deletions tests/tape_equivalence_PyADOLC_ADOLC/pyadolc.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
from adolc import * from adolc import *
import numpy as npy import numpy as npy

N = 20 N = 20


ay = adouble(0.) ay = adouble(0.)
Expand All @@ -20,25 +19,19 @@




# if necessary: call the garbage collector and therefore start with smaller locints # if necessary: call the garbage collector and therefore start with smaller locints
del(ay)
del(ax) del(ax)
ay = adouble(0.) del(ay)
ax = adouble(0.)
x = 1. x = 1.
tmpay = adouble(0.)




trace_on(10) trace_on(10)
ax.is_independent(x) ax = adouble(1.)
independent(ax)
ay = ax ay = ax
for i in range(N): for i in range(N):
ay = ay * ay ay <<= ay * ay
if i%1 == 0:
tmpay <<= ay dependent(ay)
del(ay)
ay = tmpay

depends_on(ay)
trace_off() trace_off()


tape_to_latex(9,npy.array([x]),npy.array([0])) tape_to_latex(9,npy.array([x]),npy.array([0]))
Expand Down
7 changes: 6 additions & 1 deletion tests/unit_test.py
Expand Up @@ -168,7 +168,7 @@ def test_dependent():
bx = dependent(ax) bx = dependent(ax)
assert numpy.prod( ax == bx ) assert numpy.prod( ax == bx )





def test_hov_ti_reverse(): def test_hov_ti_reverse():
"""compute the first columnt of the hessian of f = x_1 x_2 x_3""" """compute the first columnt of the hessian of f = x_1 x_2 x_3"""
Expand Down Expand Up @@ -818,6 +818,11 @@ def eval_h_adolc(x, lagrange, obj_factor, flag, user_data = None):
H_adolc = H_adolc.todense() H_adolc = H_adolc.todense()
assert_array_almost_equal( H, H_adolc.T) assert_array_almost_equal( H, H_adolc.T)











#def test_gradient_and_jacobian_and_hessian(): #def test_gradient_and_jacobian_and_hessian():
Expand Down

0 comments on commit ce06df9

Please sign in to comment.