Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make finding Python in build system more robust, update Docker container #2672

Merged
merged 10 commits into from
Dec 22, 2020

Conversation

nilsvu
Copy link
Member

@nilsvu nilsvu commented Dec 17, 2020

Proposed changes

  • Switch to CMake's FindPython
  • Install Pybind11 through pip. This should work on all systems that
    support Python. It means we can use Pybind11's CMake tools,
    don't have to bundle them and don't need special finding-code.

Upgrade instructions

Code review checklist

  • The code is documented and the documentation renders correctly. Run
    make doc to generate the documentation locally into BUILD_DIR/docs/html.
    Then open index.html.
  • The code follows the stylistic and code quality guidelines listed in the
    code review guide.
  • The PR lists upgrade instructions and is labeled bugfix or
    major new feature if appropriate.

Further comments

@nilsvu nilsvu requested a review from nilsdeppe December 17, 2020 15:20
nilsdeppe
nilsdeppe previously approved these changes Dec 17, 2020

# We can't rely on CMake 3.14 quite yet so we backport the `Python::NumPy`
# imported target that FindPython in CMake 3.14+ could also provide.
find_package(NumPy 1.10 REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we/can we check that SciPy was correctly found with finding NumPy? I believe nowadays it is, but I don't know when that changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea to check that, added a fixup

Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Please go ahead and squash :)

nilsdeppe
nilsdeppe previously approved these changes Dec 17, 2020
@nilsdeppe
Copy link
Member

@nilsleiffischer this needs a rebase to fix a (hopefully minor) conflict

@kidder
Copy link
Member

kidder commented Dec 17, 2020

@wthrowe do you want to test this out on your machine?
I need to test this on my machine as well

@wthrowe
Copy link
Member

wthrowe commented Dec 18, 2020

-- Python: /usr/bin/python3.7
-- Python Version: 3.7.9
-- BUILD_PYTHON_BINDINGS: YES
-- Found clang-tidy: /usr/lib/llvm/10/bin/clang-tidy
-- Doxygen: /usr/bin/doxygen
-- Configuring done
CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyDataStructures" links to target "pybind11::headers" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/DataStructures/Python/CMakeLists.txt:6 (spectre_python_add_module)

Followed by a bunch of similar errors.

@nilsvu
Copy link
Member Author

nilsvu commented Dec 18, 2020

@wthrowe could you post the full cmake trace please?

@wthrowe
Copy link
Member

wthrowe commented Dec 18, 2020

$ cmake -DCHARM_ROOT=/usr/include/charm -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang-10 -DCMAKE_CXX_COMPILER=clang++-10 -DCMAKE_Fortran_COMPILER=gfortran -DCMAKE_C_FLAGS=-fPIC\ -march=native\  -DCMAKE_CXX_FLAGS=-fPIC\ -fdiagnostics-color=always\ -ferror-limit=1\ -ftemplate-backtrace-limit=0\ -march=native\  -DCMAKE_Fortran_FLAGS=-march=native\  -DCMAKE_EXE_LINKER_FLAGS=-march=native\ -no-pie\  -DCMAKE_SHARED_LINKER_FLAGS=-march=native\ -no-pie\  -Dpybind11_INCLUDE_DIRS=/usr/include/python3.7m -DBUILD_PYTHON_BINDINGS=YES /home/wthrowe/spectre
-- SpECTRE release version: 2020.12.07
-- The CXX compiler identification is Clang 10.0.1
-- The C compiler identification is Clang 10.0.1
-- The Fortran compiler identification is GNU 7.5.0
-- Check for working CXX compiler: /usr/lib/llvm/10/bin/clang++-10
-- Check for working CXX compiler: /usr/lib/llvm/10/bin/clang++-10 - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/lib/llvm/10/bin/clang-10
-- Check for working C compiler: /usr/lib/llvm/10/bin/clang-10 - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran - works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 - yes
-- Found Git: /usr/bin/git (found version "2.26.2") 
-- Found Yapf: /usr/bin/yapf (found version "0.30.0") 
-- yapf found at: /usr/bin/yapf
-- yapf version: 0.30.0
-- Found Python: /usr/bin/python3.7 (found version "3.7.9") found components: Interpreter 
-- CMAKE_BUILD_TYPE: Debug
-- Found Boost: /usr/include (found suitable version "1.72.0", minimum required is "1.60.0") found components: program_options 
-- Boost include: /usr/include
-- Boost libraries: /usr/lib64/libboost_program_options-mt.so
-- Could not find ccache
-- Found Charm: /usr/bin/charmc (found suitable exact version "6.10.2") 
-- Charm++ built with shared memory parallelism
-- Checking for broken std::array<..., 0>
-- Checking for broken std::array<..., 0> -- works
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'blas'
--   Found blas, version 3.8.0
-- BLAS libs: /usr/lib64/libblas.so
-- BLAS vendor is probably not OpenBLAS. Make sure it doesn't try to do multithreading that might conflict with Charm++ parallelism.
-- Checking for module 'lapack'
--   Found lapack, version 3.8.0
-- Found LAPACK: /usr/lib64/liblapack.so  
-- LAPACK libs: /usr/lib64/liblapack.so
-- Found LIBXSMM: /usr/include (found version "1.8.1") 
-- LIBXSMM libs: /usr/lib64/libxsmm.so
-- LIBXSMM incl: /usr/include
-- LIBXSMM vers: 1.8.1
-- Found Blaze: /usr/include (found suitable version "3.7", minimum required is "3.5") 
-- Blaze incl: /usr/include
-- Blaze vers: 3.7
-- Found Brigand: /usr/include  
-- Brigand include: /usr/include
-- Found Catch: /usr/include/catch2 (found suitable version "2.9.1", minimum required is "2.8.0") 
-- Catch include: /usr/include/catch2
-- Catch version: 2.9.1
-- Google Benchmark libs: /usr/lib64/libbenchmark.so
-- Google Benchmark incl: /usr/include/benchmark
-- Found GSL: /usr/include (found version "2.5") 
-- GSL libs: /usr/lib64/libgsl.so;/usr/lib64/libgslcblas.so
-- GSL incl: /usr/include
-- GSL vers: 2.5
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Found HDF5: /usr/lib64/libhdf5.so;/usr/lib64/libz.so;/usr/lib64/libdl.so;/usr/lib64/libm.so (found version "1.10.5") found components: C 
-- HDF5 libs: /usr/lib64/libhdf5.so/usr/lib64/libz.so/usr/lib64/libdl.so/usr/lib64/libm.so
-- HDF5 incl: /usr/include
-- HDF5 vers: 1.10.5
-- Found JEMALLOC: /usr/include (found version "..") 
-- jemalloc libs: /usr/lib64/libjemalloc.so
-- jemalloc incl: /usr/include
-- jemalloc vers: ..
-- Found Python: /usr/bin/python3.7 (found version "3.7.9") found components: Interpreter Development 
-- Found PythonInterp: /usr/bin/python3.7 (found version "3.7.9") 
-- Found PythonLibs: /usr/lib64/libpython3.7m.so
-- Pybind11 include: /usr/include
-- Found Libsharp: /usr/include  
-- libsharp libs: /usr/lib64/libsharp.a
-- libsharp libs: /usr/lib64/libfftpack.a
-- libsharp libs: /usr/lib64/libc_utils.a
-- libsharp incl: /usr/include
-- Found YAMLCPP: /usr/include  
-- yaml-cpp libs: /usr/lib64/libyaml-cpp.so
-- yaml-cpp incl: /usr/include
-- clang-tidy: /usr/lib/llvm/10/bin/clang-tidy
-- iwyu: Cannot use include-what-you-use with precompiled header. Pass USE_PCH=OFF to CMake to disable the precompiled header.
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.17") found components: doxygen missing components: dot
-- Found Python: /usr/bin/python3.7 (found version "3.7.9") found components: Interpreter 
-- Could NOT find PY_bs4 (missing: PY_BS4) 
-- Could NOT find PY_pybtex (missing: PY_PYBTEX) 
CMake Warning at cmake/SetupDoxygen.cmake:64 (message):
  Doxygen documentation postprocessing is disabled because Python
  dependencies were not found:
Call Stack (most recent call first):
  CMakeLists.txt:117 (include)


CMake Warning at cmake/SetupDoxygen.cmake:67 (message):
  BeautifulSoup4 missing.  Install with: pip install beautifulsoup4
Call Stack (most recent call first):
  CMakeLists.txt:117 (include)


CMake Warning at cmake/SetupDoxygen.cmake:71 (message):
  Pybtex missing.  Install with: pip install pybtex
Call Stack (most recent call first):
  CMakeLists.txt:117 (include)


-- Could NOT find PY_coverxygen (missing: PY_COVERXYGEN) 
-- Found Python: /usr/lib64/libpython3.7m.so (found version "3.7.9") found components: Development 
-- Found Python: /usr/bin/python3.7 (found version "3.7.9") found components: Interpreter 
-- Found NumPy: /usr/lib/python3.7/site-packages/numpy/core/include (found suitable version "1.19.1", minimum required is "1.10") 
-- NumPy ver. 1.19.1 found (include: /usr/lib/python3.7/site-packages/numpy/core/include)
-- NumPy incl: /usr/lib/python3.7/site-packages/numpy/core/include
-- NumPy vers: 1.19.1
-- Found PY_scipy: /usr/lib/python3.7/site-packages/scipy  
-- 
Useful Information:
-- Git Branch: HEAD
-- Git Hash: v2020.12.07
-- Build Directory: /home/wthrowe/spectre-work
-- Source Directory: /home/wthrowe/spectre
-- Bin Directory: /home/wthrowe/spectre-work/bin/
-- CMake Modules Path: /home/wthrowe/spectre/cmake/usr/share/cmake/pybind11
-- CMAKE_CXX_FLAGS: -fPIC -fdiagnostics-color=always -ferror-limit=1 -ftemplate-backtrace-limit=0 -march=native
-- CMAKE_CXX_LINK_FLAGS:  -L/usr/lib64 -fuse-ld=gold
-- CMAKE_CXX_FLAGS_DEBUG: -g -DSPECTRE_DEBUG
-- CMAKE_CXX_FLAGS_RELEASE: -O3 -DNDEBUG
-- CMAKE_EXE_LINKER_FLAGS: -march=native -no-pie
-- CMAKE_BUILD_TYPE: Debug
-- CMAKE_CXX_COMPILER: /usr/lib/llvm/10/bin/clang++-10
-- BUILD_SHARED_LIBS: 
-- USE_PCH: ON
-- ASAN: OFF
-- UBSAN_UNDEFINED: OFF
-- UBSAN_INTEGER: OFF
-- USE_SYSTEM_INCLUDE: ON
-- Python: /usr/bin/python3.7
-- Python Version: 3.7.9
-- BUILD_PYTHON_BINDINGS: YES
-- Found clang-tidy: /usr/lib/llvm/10/bin/clang-tidy
-- Doxygen: /usr/bin/doxygen
-- Configuring done
CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyDataStructures" links to target "pybind11::headers" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/DataStructures/Python/CMakeLists.txt:6 (spectre_python_add_module)


CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyDomainCreators" links to target "pybind11::headers" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/Domain/Creators/Python/CMakeLists.txt:6 (spectre_python_add_module)


CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyDomain" links to target "pybind11::headers" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/Domain/Python/CMakeLists.txt:6 (spectre_python_add_module)


CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyInformer" links to target "pybind11::headers" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/Informer/Python/CMakeLists.txt:6 (spectre_python_add_module)


CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyH5" links to target "pybind11::headers" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/IO/H5/Python/CMakeLists.txt:6 (spectre_python_add_module)


CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyGeneralRelativitySolutions" links to target "pybind11::headers"
  but the target was not found.  Perhaps a find_package() call is missing for
  an IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/PointwiseFunctions/AnalyticSolutions/GeneralRelativity/Python/CMakeLists.txt:6 (spectre_python_add_module)


CMake Error at /usr/share/cmake/Modules/FindPython/Support.cmake:2571 (add_library):
  Target "PyEquationsOfState" links to target "pybind11::headers" but the
  target was not found.  Perhaps a find_package() call is missing for an
  IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPython.cmake:364 (__Python_add_library)
  cmake/SpectreSetupPythonPackage.cmake:91 (Python_add_library)
  src/PointwiseFunctions/Hydro/EquationsOfState/Python/CMakeLists.txt:6 (spectre_python_add_module)


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

@nilsvu
Copy link
Member Author

nilsvu commented Dec 18, 2020

@wthrowe Have you installed pybind11 via pip? Why are you passing pybind11_INCLUDE_DIRS manually to cmake?

@nilsdeppe
Copy link
Member

I'll add that something like pybind11_ROOT should be supported. I don't think we can reasonably force people to install something through pip.

@wthrowe
Copy link
Member

wthrowe commented Dec 18, 2020

@wthrowe Have you installed pybind11 via pip?

No, I installed it from my distro's package.

Why are you passing pybind11_INCLUDE_DIRS manually to cmake?

This is a good question. I assume I added it for some reason in the past, but it doesn't seem to be necessary on develop. Removing it did not fix the errors, though.

@nilsvu
Copy link
Member Author

nilsvu commented Dec 18, 2020

I'll add that something like pybind11_ROOT should be supported. I don't think we can reasonably force people to install something through pip.

Yes it definitely should be supported. I also installed via brew, should work fine.

@wthrowe which version of pybind11 did you install? Please try 2.6.0 or later (they added FindPython support on Aug 19 pybind/pybind11#2370).

@nilsdeppe
Copy link
Member

Question: is there a way we can require a specific version and newer? It sounds like part of the trouble is that? I noticed you updated the docs, not sure if the find(pybind11) command supports requiring a version number

@nilsvu
Copy link
Member Author

nilsvu commented Dec 18, 2020

Sure, added the version requirement to the find_package(pybind11) command (squashed it in).

Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

Copy link
Member

@nilsdeppe nilsdeppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kidder have you tested this on your machine?

@@ -114,7 +114,7 @@ jobs:
|| github.ref != 'refs/heads/develop'
runs-on: ubuntu-latest
container:
image: sxscollaboration/spectrebuildenv:latest
image: nilsleiffischer/spectrebuildenv:pybind11_with_pip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we don't forget: this needs to get set back to the right container

@nilsvu
Copy link
Member Author

nilsvu commented Dec 20, 2020

Added another commit that cleans up the link dependencies for the Pybindings in the build system.

@wthrowe
Copy link
Member

wthrowe commented Dec 21, 2020

@wthrowe which version of pybind11 did you install? Please try 2.6.0 or later (they added FindPython support on Aug 19 pybind/pybind11#2370).

I was using 2.5.0. It works after upgrading to 2.6.0.

@kidder
Copy link
Member

kidder commented Dec 22, 2020

works for me; needs a rebase

- Switch to CMake's FindPython
- Install Pybind11 through pip. This should work on all systems that
  support Python. It means we can use Pybind11's CMake tools,
  don't have to bundle them and don't need special finding-code.
Add missing link dependencies and link explicitly with
pybind11 when including its headers.
@nilsvu
Copy link
Member Author

nilsvu commented Dec 22, 2020

@nilsdeppe @kidder @wthrowe rebased, and added a few more container updates so we don't have to rebuild the container too many times. CI runs over the new container successfully here. I'll push the new container to sxscollaboration/spectrebuildenv:latest once you have approved this PR, so we can rerun CI and merge.

@nilsvu nilsvu changed the title Make finding Python in build system more robust Make finding Python in build system more robust, update Docker container Dec 22, 2020
&& ./build LIBS multicore-linux-x86_64 gcc ${PARALLEL_MAKE_ARG} -g -O0 \
&& ./build charm++ multicore-linux-x86_64 clang ${PARALLEL_MAKE_ARG} -g -O0 \
&& ./build LIBS multicore-linux-x86_64 clang ${PARALLEL_MAKE_ARG} -g -O0 \
&& ./build LIBS multicore-linux-x86_64 gcc \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why build the shared libs here? Linux allows you to mix shared and static libs as long as the static libs are built with -fPIC and our build system doesn't look for Charm++'s shared libs (because they stick them in the wrong directory)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Charm docs say to compile shared libs: https://github.com/UIUC-PPL/charm#building-dynamic-libraries. Then we can pass -charm-shared to charmc --print-building-blocks and get the compiler configuration for shared libs. If we don't do both (have the Charm shared libs compiled and pass the -charm-shared flag) then I don't think they guarantee that things will work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@nilsvu nilsvu merged commit dfe1c6f into sxs-collaboration:develop Dec 22, 2020
@nilsvu nilsvu deleted the cmake_find_python branch December 22, 2020 23:03
@nilsdeppe nilsdeppe mentioned this pull request Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants