mctools / dgcode

DGCode: the coding framework of the ESS Detector Group. For more information, refer to https://confluence.esss.lu.se/display/DGCODE/CodingFramework
Other
2 stars 1 forks source link

Allow installation of dependencies via conda #10

Closed tkittel closed 8 months ago

tkittel commented 1 year ago

This might already be possible, but we should try to find a bullet proof recipe. For now I am collecting notes in this issue.

tkittel commented 1 year ago

I have a feeling that in principle this will be very easy, if we completely skip the whole dgdepfixer issue. However, to do that we need to work with vanilla versions of e.g. Geant4 and OpenSceneGraph which might complicate matters. At the very least we need to update Geant4 to a more recent versions (cf. #2)

tkittel commented 1 year ago

Playing around, here is an environment.yml which I think works (it needs more testing though):

name: dgcode
channels:
  - nodefaults
  - conda-forge
dependencies:
  - python=3.10
  - clang=14.0.6
  - clangxx=14.0.6
  - compilers
  - numpy
  - matplotlib
  - cmake
  - git
  - gdb
  - valgrind
  - pip
  - pip:
    - ptpython==3.0.20
variables:
  DGCODE_FORCEVAR_CC: clang
  DGCODE_FORCEVAR_CXX: clang++
  DGCODE_BOOTSTRAP_SKIP_DGDEPFIXER_CHECK: 1
  URL_DGCODE: git@github.com:mctools/dgcode.git
  URL_DGCODE_VAL: git@github.com:mctools/dgcode_val.git
  URL_DGCODE_DG_PROJECTS: git@github.com:ess-dg/dgcode_projects.git
  URL_DGCODE_DG_PRIVATE_PROJECTS: git@github.com:mctools/dgcode_private_projects.git

It needs DGCODE_BOOTSTRAP_SKIP_DGDEPFIXER_CHECK support in bootstrap.sh and different python detection, which is WIP in the tk_devel branch. (added to main)

I also didn't add geant4/openscenegraph/root to the list yet. For Geant4 it might not work unless we migrate to the latest version.

As a test (because I was debugging an unrelated clang14 issue) the .yml above uses 4 lines to enable usage of the clang14 compiler, obviously those 4 lines should in general be left out. I also pinned the python version for similar reasons.

(update: replaced CC/CXX with DGCODEFORCEVAR... versions, see comment below)

tkittel commented 1 year ago

Update: The CC and CXX variables in the .yml above does not actually get set (rather: they get overridden somehow). Perhaps we need DGCODE_FORCEVAR_CC / DGCODE_FORCEVAR_CXX for bootstrap.sh to restore the CC/CXX? update: this is now supported

tkittel commented 1 year ago

Trying again with the .yml above, but this time with clang=10, clang++=10, python=3.8, I ran into problem during the link stage of packages (not on DGBoost, Core, or Utils, but on later packages like MCPL). It was solved if I added $CONDA_PREFIX/lib to my LD_LIBRARY_PATH. Perhaps we need to add rpath to that dir when conda is detected?

update: the same issue also happened in a different environment where the clang/python related lines were absent. So in general we need to add the CONDA_PREFIX/lib to LD_LIBRARY_PATH, or presumably, to rpath.

tkittel commented 1 year ago

Today I was trying to be a bit less ambitious and simply try to set up a minimal conda environment in which to configure and build a standalone Geant4 example (geant4 example B1). So I tried:

name: dgcode
channels:
  - nodefaults
  - conda-forge
dependencies:
  - cmake
  - compilers
  - geant4
  - expat
variables:
  - DGCODE_BOOTSTRAP_SKIP_DGDEPFIXER_CHECK: 1

The compilers package seems to be crucial, as it drags in all of sorts of basic system headers: https://github.com/conda-forge/compilers-feedstock/blob/main/recipe/meta.yaml

The expat package was needed for some reason, possibly the geant4-feedstock recipe has it missing in the run section, not sure.

With all that, a naive CMake attempt (on the B1 example) still fails:

  Could NOT find EXPAT: Found unsuitable version "2.2.9", but required is at
  least "2.5.0" (found /usr/lib/x86_64-linux-gnu/libexpat.so)
Call Stack (most recent call first):
  /home/tkittel/scr/miniforge_install/miniforge_installed/envs/g411_standalone/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:592 (_FPHSA_FAILURE_MESSAGE)
  /home/tkittel/scr/miniforge_install/miniforge_installed/envs/g411_standalone/share/cmake-3.24/Modules/FindEXPAT.cmake:65 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  /home/tkittel/scr/miniforge_install/miniforge_installed/envs/g411_standalone/share/cmake-3.24/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /home/tkittel/scr/miniforge_install/miniforge_installed/envs/g411_standalone/lib/Geant4-11.0.3/Geant4Config.cmake:268 (find_dependency)
  CMakeLists.txt:15 (find_package)

because cmake is not looking correctly inside the $CONDA_PREFIX. Obviously we need to pass some variables, as in the '$CMAKE_ARGSused in conda recipesbuild.sh` scripts.

update: investigating a bit further, I realised that I now suddenly seems to have the CMAKE_ARGS env var set, possibly because I re-activated my conda environment AFTER installing the compilers meta-package. So inside conda, we should be sure to 1) always have the compilers dependency and 2) invoke cmake ... as cmake ${CMAKE_ARGS} ...

tkittel commented 1 year ago

Summary of lessons learnt today:

tkittel commented 1 year ago

Tests like ess_mcpltests_testflags probably need to be conda-aware (or at least look at LDFLAGS etc.) as well.

tkittel commented 1 year ago

ess_skeletonsp_sim -n1 seg-faults, not sure if it is g4 or conda related. In any case, I should check there is also a unit test for this command. update:

==61867== Invalid read of size 8
 504 ==61867==    at 0x7731792: G4GSMottCorrection::GetMottCorrectionFactors(double, double, int, double&, double&, double&) (in /home/tkittel/scr/miniforge_install/miniforge_insta\
     lled/envs/g4_v11/lib/libG4processes.so)

update: this was a bug in G4 (see #2).

tkittel commented 1 year ago

Related to the issue of $CONDA_PREFIX/lib needing to be added to LD_LIBRARY_PATH, is the issue that we do not recompile automatically if changing the LD_LIBRARY_PATH (not even if running with dgbuild -i).

tkittel commented 1 year ago

I think we need to look for $CONDA_PREFIX in bootstrap.sh and dgbuild, and make them conda-aware:

tkittel commented 1 year ago

Working on this again. Adding a list here with notes for myself: