GalacticDynamics-Oxford / Agama

Action-based galaxy modeling framework
Other
76 stars 38 forks source link

Problems of installing agama on mac osx #21

Closed Coroico2 closed 1 year ago

Coroico2 commented 2 years ago

I have problems on installing Agama on my mac osx (10.15.7, Catalina) When I do pip install agama I get this message that openMP is not supported... -Any idea?

Thanks a lot for your feedback! Mathias

Collecting agama Using cached https://files.pythonhosted.org/packages/e4/41/e89578bc985f05166687f2500c0f522f2bfc732705c75400fb5a83ddc305/agama-1.00.tar.gz Running /private/var/folders/d0/d081jvpd35j9s1wrjm5sjg280000gn/T/pip-install-otxxdm2v/agama/setup.py Downloading the latest version of package from github Building wheels for collected packages: agama Building wheel for agama (setup.py) ... \ ==== Checking supported compiler options and available libraries ====

\Warning, OpenMP is not supported If you're compiling on MacOS with clang, you'd better install another compiler such as GCC Do you want to continue without OpenMP? [Y/N]

ld: symbol(s) not found for architecture x86_64 clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation) Trying the options provided by python3.7-config --ldflags Trying the following options for linking against Python library x86_64-apple-darwin13.4.0-clang++ -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -fPIC -Wall -O2 -std=c++11 -march=native -Wno-missing-field-initializers test.cpp -o ./agamatest.so -I"/Users/schultheis/opt/anaconda3/include/python3.7m" -I"/Users/schultheis/opt/anaconda3/lib/python3.7/site-packages/numpy/core/include" -shared -fPIC -L/Users/schultheis/opt/anaconda3/lib/python3.7/config-3.7m-darwin -lpython3.7m -ldl -framework CoreFoundation ld: warning: -pie being ignored. It is only used when linking a main executable ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libdl.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libdl.tbd ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd ld: symbol dyld_stub_binder not found (normally in libSystem.dylib). Needed to perform lazy binding to function _PyCapsule_GetPointer for architecture x86_64 clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation) error: Could not compile test program which uses libpython3.7

ERROR: Failed building wheel for agama

eugvas commented 2 years ago

hi Mathias, that's an obscure failure and I couldn't find anything relevant in the internet. can you try downloading the github repo and running the setup script directly (as python setup.py install), then recording the full output - might be more informative than from pip. also try running the attached simple setup script that builds a dummy extension module - the only purpose is to look at the command-line options that it uses in compiling it; can you then post them as well. testsetup.py.txt

Coroico2 commented 2 years ago

I send you attached the log file when I run it downloading the github repo

And here is the output of the script

Hope this helps!

Cheers

Mathias

running build_ext building 'agamatest' extension creating build creating build/temp.macosx-10.9-x86_64-3.7 x86_64-apple-darwin13.4.0-clang -fno-strict-aliasing -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O3 -Wall -Wstrict-prototypes -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O3 -pipe -fdebug-prefix-map=${SRC_DIR}=/usr/local/src/conda/${PKG_NAME}-${PKG_VERSION} -fdebug-prefix-map=/Users/schultheis/opt/anaconda3=/usr/local/src/conda-prefix -flto -Wl,-export_dynamic -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O3 -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -D_FORTIFY_SOURCE=2 -mmacosx-version-min=10.9 -I/Users/schultheis/opt/anaconda3/include/python3.7m -c agamatest.cpp -o build/temp.macosx-10.9-x86_64-3.7/agamatest.o clang-4.0: warning: -Wl,-export_dynamic: 'linker' input unused [-Wunused-command-line-argument] creating build/lib.macosx-10.9-x86_64-3.7 x86_64-apple-darwin13.4.0-clang++ -bundle -undefined dynamic_lookup -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/schultheis/opt/anaconda3/lib -L/Users/schultheis/opt/anaconda3/lib -flto -Wl,-export_dynamic -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/schultheis/opt/anaconda3/lib -L/Users/schultheis/opt/anaconda3/lib -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -D_FORTIFY_SOURCE=2 -mmacosx-version-min=10.9 -arch x86_64 build/temp.macosx-10.9-x86_64-3.7/agamatest.o -o build/lib.macosx-10.9-x86_64-3.7/agamatest.cpython-37m-darwin.so ld: warning: -pie being ignored. It is only used when linking a main executable ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd log.docx

eugvas commented 2 years ago

ok, so the log file now has another, unrelated error, which seems equally obscure to me: "pointer is missing nullability type specifier" - this appears to be an error related to the Objective-C language, not to C++. I found that it can be disabled by adding -Wno-nullability-completeness to the compilation flags (line 129 of setup.py, CXXFLAGS += ['-fPIC', ... ] -- add another entry to this list). Then it was complaining about not supporting OpenMP, which is not a critical error (you should answer "Y" when asked whether to continue compilation without it). While Mac OS 10.9 is not a particularly recent version, I believe the code should compile on even older systems (tested on 10.6.8). Since the test example seems to compile without trouble, one could simply borrow [some of] the compilation flags from it, but I'm puzzled as to why doesn't it run into the same troubles as the setup script.. It might also happen that the compilation process and the options used by default do depend on the name of the compiler program, even if it's just a symlink to another executable file. In the log file, the name is spelled as c++, assigned on line 174 of the setup script, whereas in the compilation of the test example, a fully qualified name x86_64-apple-darwin13.4.0-clang++ is used instead. Perhaps you could try putting that into line 174.

Coroico2 commented 2 years ago

Thanks a lot for your suugestions. Just to be sure -where should I add here the option -Wno-nullability-completeness try: CXXFLAGS = os.environ['CFLAGS'].split()

except KeyError: CXXFLAGS = []
try: LINK_FLAGS = os.environ['LDFLAGS'].split()
except KeyError: LINK_FLAGS = []
# default compilation flags for both the shared library and all example programs that use it
if MSVC:
    CXXFLAGS += ['/W3', '-wd4244', '-wd4267', '/O2', '/EHsc', '/nologo']
    LINK_DIR_FLAG = '/LIBPATH:'  # prefix for library search path
    COMPILE_OUT_FLAG = '/Fe:'    # prefix for output file

And also for the c++ Is is like this try: CC = os.environ['x86_64-apple-darwin13.4.0-clang++'] ?

Thanks again

eugvas commented 2 years ago

where should I add here the option -Wno-nullability-completeness

line 129 of setup.py CXXFLAGS += ['-fPIC', '-Wall', '-O2', '-Wno-nullability-completeness']

And also for the c++

line 174 of setup py: if CC=='cc': CC='x86_64-apple-darwin13.4.0-clang++'

Coroico2 commented 2 years ago

Thanks a lot -I run it but I get similar errors -attached the log file log2.docx

eugvas commented 2 years ago

well, only if "superficially similar". now it first produces another bunch of obscure complaints, as if compiling a C++ code with a C compiler. Then somehow calms down and fails because of being unable to find Python librararies - but this time you are using system-bundled Python 2.7 rather than Anaconda Python 3.7 as in the first attempt. I get completely confused over all this! By the way, in my Mac OS installation, Python 2.7 is found exactly at the same location and it compiles all fine... ok, try the following:

Coroico2 commented 2 years ago

Thanks so much -it seems to work -I could run also the test 27 TESTS PASSED, NONE FAILED, 1 UNKNOWN.

So a quick question -AGAMA is now installed under /Users/schultheis/Downloads/agama-1.0 -is there a way that I can run it also general on other directories or I have to go always to this directory in order to run agama

Thanks again so much for your help and I am eager now to start using AGAMA

eugvas commented 2 years ago

ah great! when you run python setup.py install it compiles the whole thing in the current folder, then copies the shared library agama.so and other stuff into the standard folder where Python keeps third-party modules (***/site-packages/). So you should be able to write import agama in a python script running in any folder across the entire system. If you need to run any of the executable files that also got compiled together with the shared library, they are also copied to site-packages, but not added to the system search path or anything, so you'd need to run them explicitly from the folder /Users/schultheis/Downloads/agama-1.0/exe or wherever you wish to move it, or add that folder to PATH. Note that the shared library agama.so, or a symlink to it, should be present in the same folder as the executable file.

Coroico2 commented 2 years ago

Thanks so much again for you help and your quick response -I really appreciate it!! Cheers Mathias

Coroico2 commented 2 years ago

Hi again I could run nicely the AGAMA code -just a quick question I could not find the information to calculate the total Energy and also zmax - what would be the easiest way to calculate this Thanks a lot again Cheers Mathias

eugvas commented 2 years ago

assuming that X is an array of shape Nx6 (position and velocity in cartesian coords), the total energy is E = pot.potential(X[:,0:3]) + 0.5*numpy.sum(X[:,3:6]**2, axis=1) zmax - depends on what exactly do you mean by this. You can integrate orbits and compute their maximum z pretty easily; if you need a plausible estimate, here is a trick: a good proxy for zmax is Rmax sqrt(Jz / (Jz + abs(Jphi))) af = agama.ActionFinder(pot) Jr,Jz,Jphi = af(X).T `zmax = pot.Rmax(E) (Jz / (abs(Jphi)+Jz))**0.5`

Coroico2 commented 2 years ago

Thanks a lot!