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

Automatic download and build of MOAB #969

Merged
merged 33 commits into from
Feb 6, 2025
Merged

Conversation

bam241
Copy link
Member

@bam241 bam241 commented Dec 4, 2024

Description

Add capability to automate pull and build MOAB at DAGMC building time

This is redondant with #964

Motivation and Context

This is part of the project from @shimwell on getting a pip install for OpenMC with DAGMC.

Changes

tweaked a little bit the findMOAB.cmake

  • add a make files that contains the proper ExternalProject configuration
  • add a CMAKE variable to enable pull and build and change the dips and link for the other DAGMC library

Behavior

Nothing changes if DDL_DEPS is not set at ON on Cmake configuration.
Otherwise pull build MOAB from MOAB repo builds it, and build the DAGMC lib against it.

Changelog file

  • Done

This is very much inspired by @ahnaf-tahmid-chowdhury work on PyNE cmake.

This works is sponsored by Proxima Fusion

@bam241
Copy link
Member Author

bam241 commented Dec 4, 2024

@ahnaf-tahmid-chowdhury @shimwell @gonuke even if this is still a draft, feel free to provide any feed back!

Comment on lines 122 to 123
else()
# message(FATAL_ERROR "Could not find MOAB")
Copy link
Member Author

Choose a reason for hiding this comment

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

This should still return a fatal_error if ExternalProject encounters an issue

@bam241
Copy link
Member Author

bam241 commented Dec 4, 2024

The safeguard I added should be improve... (i.e.: have them only MOAB download is triggered...)

@bam241 bam241 marked this pull request as ready for review December 6, 2024 06:42
@bam241 bam241 requested a review from gonuke December 6, 2024 06:54
@bam241
Copy link
Member Author

bam241 commented Dec 6, 2024

@gonuke this still needs some polishing here and there, but I think this is ready for a first opinion.

@bam241 bam241 force-pushed the auto_moab branch 2 times, most recently from d49d208 to 45feb89 Compare December 6, 2024 11:32
Copy link
Member

@ahnaf-tahmid-chowdhury ahnaf-tahmid-chowdhury left a comment

Choose a reason for hiding this comment

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

Thank you very much for the update. I have a few comments for improvement.

-DBUILD_SHARED_LIBS:BOOL=ON
-DENABLE_HDF5:BOOL=ON
-DHDF5_ROOT:PATH=${HDF5_ROOT}
-DCMAKE_INSTALL_RPATH=${HDF5_ROOT}/lib:${MOAB_INSTALL_PREFIX}/lib

Choose a reason for hiding this comment

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

This method may work here for now, but may create trouble while working with scikit-build-core depended project. However, I am not sure here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no experience about scikit-build-core, maybe we shall fix it, if the problem occurs ?

Copy link
Member

Choose a reason for hiding this comment

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

I believe MOAB master branch now has scikit-build core while version 5.5.1 does not.

Perhaps changing the moab version to master would provide a quick way of checking if this continues to work

      GIT_REPOSITORY https://bitbucket.org/fathomteam/moab.git
      GIT_TAG ${moab_version}

Copy link
Member Author

Choose a reason for hiding this comment

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

Trying it now.

Choose a reason for hiding this comment

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

Just to mention @bam241 tried this with the master branch of MOAB (which has scikit build core) and reported that it works

Copy link
Member Author

Choose a reason for hiding this comment

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

have a doubt about what I did, I'll try one more time

Copy link
Member

Choose a reason for hiding this comment

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

Any final resolution on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have tested this against MOAB master, this works.

Test on 5fe643b
checked the proper work of this against MOAB Master branch

@jon-proximafusion
Copy link

jon-proximafusion commented Dec 10, 2024

Testing locally with this docker file and it compiles for me
Note this points to Bam's fork and this PR branch
Also note, this example is very minimal with no DD, Embree, Pyne

FROM ubuntu:24.04

RUN apt-get update -y
RUN apt-get install git cmake libhdf5-serial-dev g++ libeigen3-dev -y 

RUN mkdir DAGMC && \
	cd DAGMC && \
	git clone --single-branch --branch auto_moab --depth 1 https://github.com/bam241/DAGMC.git && \
	mkdir build && \
	cd build && \
	cmake ../DAGMC -DBUILD_TALLY=ON \
                   -DBUILD_STATIC_EXE=OFF \
                   -DBUILD_STATIC_LIBS=OFF \
                   -DCMAKE_INSTALL_PREFIX=/DAGMC/ \
                   -DBUILD_UWUW=OFF \
                   -DPULL_INSTALL_MOAB=ON && \
	make -j install

@bam241
Copy link
Member Author

bam241 commented Dec 12, 2024

Test on 5fe643b
checked the proper work of this against MOAB Master branch

@jon-proximafusion
Copy link

jon-proximafusion commented Jan 9, 2025

IMO this PR makes building DAGMC easier for users. Currently we ask users to compile MOAB and then compile DAGMC passing some of the info on MOAB to the DAGMC compile. I believe the current situation is overly complicated.

This PR simplifies the compile for users which I think will be appreciated and lowers the bar slightly for installing DAGMC which might help bring in a few more users.

Screenshot From 2025-01-09 17-35-25

Additionally it retains backwards compatibility so if someone does what to compile both MOAB and DAGMC in the current way then they can still do that.

The main change I would suggest is that we make the pull_install_moab variable accept a version number of MOAB and default to the current latest. This would offer greater user control over the automated download. However that could be a follow up PR if desired.

*update this also now allows users to specific the version of MOAB automatically downloaded

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

A few comments trying to streamline and localize these changes.

if (MOAB_CMAKE_CONFIG)

# First check if we are forcing the download of MOAB
if (PULL_INSTALL_MOAB)
Copy link
Member

Choose a reason for hiding this comment

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

Have we thought about whether we put this condition up one level? That is, if we are going to PULL_INSTALL, then we don't call FindPackage at all and just do this macro instead? Then we don't need to mess with the FindMOAB file. I think that will work???

pshriwise
pshriwise previously approved these changes Jan 9, 2025
Copy link
Member

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

I'm nominally on board here and want to make the installation process easier, but I do have concerns. There are secondary dependencies to consider and how we might specify those to the direct dependencies of MOAB. For example, there's a requirement here for an HDF5_ROOT that's expected to be set prior to the CMake call (from what I can tell).

I think what's here really would make the installation process better for all, but I do want to think through these scenarios thoroughly.

-DBUILD_SHARED_LIBS:BOOL=ON
-DENABLE_HDF5:BOOL=ON
-DHDF5_ROOT:PATH=${HDF5_ROOT}
-DCMAKE_INSTALL_RPATH=${HDF5_ROOT}/lib:${MOAB_INSTALL_PREFIX}/lib
Copy link
Member

Choose a reason for hiding this comment

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

Any final resolution on this?

Copy link
Member

@pshriwise pshriwise left a comment

Choose a reason for hiding this comment

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

Sorry, meant to comment not approve.. yet 😄

@bam241
Copy link
Member Author

bam241 commented Jan 9, 2025

💔

@makeclean
Copy link
Contributor

IMO you should also add -DENABLE_FORTRAN=OFF, -DENABLE_BLASLAPCK=OFF you might need to pass an EIGEN3_DIR or something

@bam241
Copy link
Member Author

bam241 commented Jan 10, 2025

@gonuke, I moved this 1 level.

I added a HDF5_macor.cmake file that factories HDF5 search and variables definition.

@shimwell
Copy link
Member

shimwell commented Jan 24, 2025

if PULL_INSTALL_MOAB is defined as ON, then MOAB_VERSION is set to the default "5.5.1"

I might be tempted not to allow "ON" as an option. What do others think?
Reasoning for this suggestion is that:

  • It makes the command more opaque, users won't know what they are getting
  • It adds a maintenance burden as we should keep this tag up to date with latest MOAB release

I might be tempted to use 'latest' or 'develop' as options by that is another topic.

Co-authored-by: Patrick Shriwise <[email protected]>

INCLUDE(ExternalProject)
MESSAGE("HDF5_ROOT: ${HDF5_ROOT}")
SET(MOAB_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/moab")

Choose a reason for hiding this comment

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

It seems MOAB is going to be installed in a custom path, which means only DAGMC will have access to it, as it will use the rpath. This is a good approach, and we can apply the same strategy for HDF5 as well. However, I think we can use the same CMAKE_INSTALL_PREFIX for both DAGMC and MOAB instead of CMAKE_INSTALL_PREFIX}/moab, as there are no conflicts having the same file name.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did put the MOAB installation there, because I though about scenarii where users would already have MOAB installed on it computer but would try an installation of DAGMC against a different version of MOAB.
To avoid conflict, I rather have MOAB installed in the DAGMC install dir, as it is installed through DAGMC.
Also if one would come to uninstall DAGMC by removing the install dir, it would make sense to remove MOAB at the same time.

@rherrero-pf
Copy link

Really like the idea behind this feature so I though I should give it a try. Happy to simplify the install process

Running this and I think the autodownloading of moab assumes that moab is available in the path /DAGMC/moab which in my case is not true.

rm -rf ~/code_development/DAGMC
mkdir ~/code_development/DAGMC
cd ~/code_development/DAGMC
git clone --single-branch --branch auto_moab --depth 1 https://github.com/bam241/DAGMC.git
mkdir build
cd build
cmake ../DAGMC -DBUILD_TALLY=ON \
                -DBUILD_STATIC_EXE=OFF \
                -DBUILD_STATIC_LIBS=OFF \
                -DCMAKE_INSTALL_PREFIX=/DAGMC/ \
                -DBUILD_UWUW=OFF \
                -DPULL_INSTALL_MOAB=ON \
                -DHDF5_ROOT=/usr/lib/x86_64-linux-gnu/hdf5
make -j install
~/code_development$ bash i.sh 
Cloning into 'DAGMC'...
remote: Enumerating objects: 453, done.
remote: Counting objects: 100% (453/453), done.
remote: Compressing objects: 100% (422/422), done.
remote: Total 453 (delta 42), reused 177 (delta 19), pack-reused 0 (from 0)
Receiving objects: 100% (453/453), 18.58 MiB | 21.03 MiB/s, done.
Resolving deltas: 100% (42/42), done.
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/bin/git (found version "2.34.1") 

-- CMAKE_BUILD_TYPE not specified, defaulting to Release
-- CMAKE_BUILD_TYPE: Release

NO MOAB_VERSION specified. Defaulting to 5.5.1
MOAB_VERSION to be installed: 5.5.1
-- MOAB will be downloaded and built
HDF5_ROOT: /usr/lib/x86_64-linux-gnu/hdf5
MOAB_LIBRARY_DIRS: /DAGMC/moab/lib
CMAKE_SHARED_LIBRARY_SUFFIX: .so
CMake Error at /usr/share/cmake-3.22/Modules/ExternalProject.cmake:1754 (file):
  file problem creating directory: /DAGMC/moab
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/ExternalProject.cmake:3668 (_ep_set_directories)
  cmake/MOAB_PullAndMake.cmake:25 (ExternalProject_Add)
  CMakeLists.txt:58 (moab_pull_make)


CMake Error at /usr/share/cmake-3.22/Modules/ExternalProject.cmake:1756 (message):
  dir '/DAGMC/moab' does not exist after file(MAKE_DIRECTORY)
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/ExternalProject.cmake:3668 (_ep_set_directories)
  cmake/MOAB_PullAndMake.cmake:25 (ExternalProject_Add)
  CMakeLists.txt:58 (moab_pull_make)


-- Configuring incomplete, errors occurred!
See also "/home/rherrero/code_development/DAGMC/build/CMakeFiles/CMakeOutput.log".
make: *** No rule to make target 'install'.  Stop.

@bam241
Copy link
Member Author

bam241 commented Feb 3, 2025

Hello @rherrero-pf thanks for testing my working
I am wondering if the problem doesn't come from -DCMAKE_INSTALL_PREFIX=/DAGMC/
are you sure you have the right to write in the /DAGMC folder ?
folder at / are usually protected.

the error you get is: file problem creating directory: /DAGMC/moab

@shimwell
Copy link
Member

shimwell commented Feb 4, 2025

Thanks @bam241

confirming this slightly adapted version works for me

sudo apt-get install libhdf5-serial-dev
sudo apt install libeigen3-dev
rm -rf ~/code_development/DAGMC
mkdir -p ~/code_development/DAGMC
cd ~/code_development/DAGMC
git clone --single-branch --branch develop --depth 1 https://github.com/svalinn/DAGMC.git
mkdir build
cd build
cmake ../DAGMC -DBUILD_TALLY=ON \
              -DBUILD_STATIC_EXE=OFF \
              -DBUILD_STATIC_LIBS=OFF \
              -DCMAKE_INSTALL_PREFIX=$HOME/code_development/DAGMC/ \
              -DBUILD_UWUW=OFF \
              -DPULL_INSTALL_MOAB=5.5.1 \
              -DHDF5_ROOT=/usr/lib/x86_64-linux-gnu/hdf5/serial \
              -DEIGEN3_INCLUDE_DIR=/usr/include/eigen3
# in my case I need to help it find Eigen3 with the line above, hopefully not everyone has to do that?
make -j
make -j install

then when installing openmc one needs to pass the DAGMC path to openmc like this

cd ~/code_development
git clone --single-branch --branch develop --depth 1 https://github.com/openmc-dev/openmc.git
cd openmc
mkdir build
cd build
cmake -DOPENMC_USE_DAGMC=ON -DDAGMC_ROOT=$HOME/code_development/DAGMC -DHDF5_PREFER_PARALLEL=OFF ..
make -j
make -j install
cd ..
python -m pip install .

*updated now that the PR is merged to point to svalinn repo and also includes full openmc instructions

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

looks pretty good - a few final clarifications

CMakeLists.txt Outdated
set(MOAB_VERSION ${PULL_INSTALL_MOAB})

# Ensure MOAB_VERSION
if(${MOAB_VERSION})
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear to me what conditions re true for this? It seems like it would evaluate to true if I DID set the version? but maybe I don't know how this CMake evaluates if(5.5.3), for example?

Copy link
Member Author

Choose a reason for hiding this comment

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

if(<variable>)
True if given a variable that is defined to a value that is not a false constant. False otherwise, including if the variable is undefined. Note that macro arguments are not variables.
``` from https://cmake.org/cmake/help/latest/command/if.html

Copy link
Member

Choose a reason for hiding this comment

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

Is a version string evaluated as a "False" constant then? I would have assumed that a version string would evaluate as True and cause this message and default to happen??

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right I miss understood this. I'll fix it!

Copy link
Member Author

Choose a reason for hiding this comment

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

@gonuke this should take care of it !

CMakeLists.txt Outdated
Comment on lines 52 to 55
if(NOT ${MOAB_VERSION} MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]")
MESSAGE("MOAB_VERSION: ${MOAB_VERSION} not recognized. Defaulting to 5.5.1")
set(MOAB_VERSION "5.5.1")
endif()
Copy link
Member Author

Choose a reason for hiding this comment

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

This should enforce MOAB_VERSION to be shaped as X.Y.Z with X, Y, Z as numbers.

Copy link
Member

Choose a reason for hiding this comment

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

Does this work even if we have a number that takes 2 chars, e.g. 5.5.10

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe not I'll try and fix it if not

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

Suggested fix for number regex

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

Sorry, but you seem to have messed up some indentation... just want that fixed, please.

Comment on lines 259 to 262
if(PULL_INSTALL_MOAB)
target_link_libraries(${lib_name}-shared INTERFACE ${MOAB_LIBRARY_DIRS}/libMOAB${CMAKE_SHARED_LIBRARY_SUFFIX})
add_dependencies(${lib_name}-shared MOAB)
endif()
Copy link
Member

Choose a reason for hiding this comment

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

Can you fix this indentation, please?

Copy link
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

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

LGTM - I'd be happy to have one other person take a last look... @pshriwise ?

@pshriwise
Copy link
Member

Gave this another look today. Thanks @bam241!

@gonuke gonuke merged commit 10b1451 into svalinn:develop Feb 6, 2025
20 checks passed
@gonuke
Copy link
Member

gonuke commented Feb 6, 2025

This caused a test to fail on merge. We have a test that checks to see if we are compatible with the develop branch of HDF5. I am not sure what changed to make this fail - whether it was the HDF5 code changing or something in this build?

@bam241
Copy link
Member Author

bam241 commented Feb 6, 2025

I don't see the failing test.
could you provide a link to it ?
I'll keep looking as well

@bam241
Copy link
Member Author

bam241 commented Feb 6, 2025

found it

@gonuke
Copy link
Member

gonuke commented Feb 6, 2025

It doesn't really matter now, I don't think, since tests pass with the specific version of HDF5, but it may be a sign for the future?

@bam241
Copy link
Member Author

bam241 commented Feb 6, 2025

I think I am the one who broke it:

bam241#4

@bam241
Copy link
Member Author

bam241 commented Feb 6, 2025

I revert the change I did on the findMOAB.cmake (responsible to deal with HDF5) and it works

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.

8 participants