Python test fails
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
libadjoint |
Fix Committed
|
Wishlist
|
Unassigned |
Bug Description
Hi,
On r410, built on MacOS X 10.6.8 using g++, I have problems with the python test named test_adjoint_
If I run 'FC="" CC=g++ make test' in libadjoint source directory, after a successful build (see bug #1134511 about how I got a working build), all C tests pass, but the python test fails, with this output:
Traceback (most recent call last):
File "./test_
from libadjoint.
File "/Users/
from libadjoint import *
File "/Users/
import libadjoint.
ImportError: No module named python_utils
test_
Failure: non-zero exit code from test
Interestingly, when I run the code in test_adjoint_
In [12]: libadjoint.
-------
AttributeError Traceback (most recent call last)
<ipython-
----> 1 libadjoint.
/Users/
10 def adj_test_
11 assert isinstance(
---> 12 clib.adj_
13
14 def handle_error(ierr):
AttributeError: 'module' object has no attribute 'adj_test_assert'
Thanks in advance for your help !
Hi!
This is because you're trying to do two things that are really awkward together. The first is to compile C code with a C++ compiler. underscore. If you do:
The second is trying to compile on OSX. It seems there's a bug in the OSX version of g++ that puts leading underscores in front of all symbols it compiles, even with -fno-leading-
g++ -g -O0 -fPIC -Iinclude/ -Wall -Wextra -Wunused-parameter -Wunsafe- loop-optimizati ons -Wno-write-strings -Wpointer-arith -ggdb3 -fstack- protector- all -fno-leading- underscore -c -o obj/adj_ adjointer_ routines. o src/adj_ adjointer_ routines. c adjointer_ routines. o | grep _adj
nm obj/adj_
you'll see that the OSX g++ has put a leading underscore in front of all the symbol names (e.g. it should be adj_timestep_count instead of _adj_timestep_ count). When the Python bindings look for the symbols, it looks for the function name without the underscore, which is why the Python bindings are failing. This is despite the presence of the -fno-leading- underscore in the command line, which is supposed to fix exactly this problem.
I'd strongly suggest just forgetting about linking libadjoint to PETSc: it *really* isn't necessary for 99% of the desired uses of libadjoint/ dolfin- adjoint. That way, you can compile libadjoint with a normal C compiler. If you're super keen to link against PETSc, compile PETSc with C language support.
I'd like to emphasise that these issues you're having are caused by a) bugs in the OSX operating system b) the way PETSc has been compiled. I've tried to work around these in libadjoint, but it seems like I can't.