Skip to content

Commit

Permalink
[CMake] Move to ROOT_FIND_PYTHON_MODULE.
Browse files Browse the repository at this point in the history
The old function find_python_module was defined both in ROOT and in
LLVM, and also using the similar output variables. This lead to
inconsistent behaviour depending on whether or not LLVM was also
searching for a Python package.
  • Loading branch information
hageboeck committed Jan 24, 2025
1 parent 68b0a11 commit eb552b0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 41 deletions.
6 changes: 3 additions & 3 deletions bindings/pyroot/pythonizations/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ endif()
# SOFIE-GNN pythonizations
if (tmva)
if(NOT MSVC OR CMAKE_SIZEOF_VOID_P EQUAL 4 OR win_broken_tests)
find_python_module(sonnet QUIET)
find_python_module(graph_nets QUIET)
if (PY_SONNET_FOUND AND PY_GRAPH_NETS_FOUND)
ROOT_FIND_PYTHON_MODULE(sonnet)
ROOT_FIND_PYTHON_MODULE(graph_nets)
if (ROOT_SONNET_FOUND AND ROOT_GRAPH_NETS_FOUND)
ROOT_ADD_PYUNITTEST(pyroot_pyz_sofie_gnn sofie_gnn.py PYTHON_DEPS numpy sonnet graph_nets)
endif()
endif()
Expand Down
5 changes: 2 additions & 3 deletions cmake/modules/RootMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1746,9 +1746,8 @@ function(ROOT_ADD_TEST test)
endif()

foreach(python_dep ${ARG_PYTHON_DEPS})
string(TOUPPER ${python_dep} python_dep_upper)
find_python_module(${python_dep_upper} QUIET)
if(NOT PY_${python_dep_upper}_FOUND)
ROOT_FIND_PYTHON_MODULE(${python_dep})
if(NOT ROOT_${python_dep}_FOUND)
set_property(TEST ${test} PROPERTY DISABLED True)
continue()
endif()
Expand Down
26 changes: 13 additions & 13 deletions tmva/pymva/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ project(pymva-tests)
set(Libraries Core MathCore TMVA PyMVA ROOTTMVASofie)

# Look for needed python modules
find_python_module(torch QUIET)
find_python_module(keras QUIET)
find_python_module(theano QUIET)
find_python_module(tensorflow QUIET)
find_python_module(sklearn QUIET)
ROOT_FIND_PYTHON_MODULE(torch)
ROOT_FIND_PYTHON_MODULE(keras)
ROOT_FIND_PYTHON_MODULE(theano)
ROOT_FIND_PYTHON_MODULE(tensorflow)
ROOT_FIND_PYTHON_MODULE(sklearn)

if(PY_SKLEARN_FOUND)
if(ROOT_SKLEARN_FOUND)
# Test PyRandomForest: Classification
ROOT_EXECUTABLE(testPyRandomForestClassification testPyRandomForestClassification.C
LIBRARIES ${Libraries})
Expand Down Expand Up @@ -51,18 +51,18 @@ if(PY_SKLEARN_FOUND)
LIBRARIES ${Libraries})
ROOT_ADD_TEST(PyMVA-AdaBoost-Multiclass COMMAND testPyAdaBoostMulticlass DEPENDS PyMVA-GTB-Multiclass)

endif(PY_SKLEARN_FOUND)
endif(ROOT_SKLEARN_FOUND)


# Enable tests based on available python modules
if(PY_TORCH_FOUND)
if(ROOT_TORCH_FOUND)
configure_file(generatePyTorchModelClassification.py generatePyTorchModelClassification.py COPYONLY)
configure_file(generatePyTorchModelMulticlass.py generatePyTorchModelMulticlass.py COPYONLY)
configure_file(generatePyTorchModelRegression.py generatePyTorchModelRegression.py COPYONLY)
configure_file(generatePyTorchModels.py generatePyTorchModels.py COPYONLY)
# Test PyTorch: Binary classification

if (PY_SKLEARN_FOUND)
if (ROOT_SKLEARN_FOUND)
set(PyMVA-Torch-Classification-depends PyMVA-AdaBoost-Classification)
set(PyMVA-Torch-Multiclass-depends PyMVA-AdaBoost-Multiclass)
endif()
Expand Down Expand Up @@ -95,13 +95,13 @@ if(PY_TORCH_FOUND)
)
target_link_libraries(TestRModelParserPyTorch ${BLAS_LINKER_FLAGS} ${BLAS_LIBRARIES})

endif(PY_TORCH_FOUND)
endif(ROOT_TORCH_FOUND)

if((PY_KERAS_FOUND AND PY_THEANO_FOUND) OR (PY_KERAS_FOUND AND PY_TENSORFLOW_FOUND))
if((ROOT_KERAS_FOUND AND ROOT_THEANO_FOUND) OR (ROOT_KERAS_FOUND AND ROOT_TENSORFLOW_FOUND))
configure_file(generateKerasModels.py generateKerasModels.py COPYONLY)
configure_file(scale_by_2_op.hxx scale_by_2_op.hxx COPYONLY)

if (PY_TORCH_FOUND)
if (ROOT_TORCH_FOUND)
set(PyMVA-Keras-Classification-depends PyMVA-Torch-Classification)
set(PyMVA-Keras-Regression-depends PyMVA-Torch-Regression)
set(PyMVA-Keras-Multiclass-depends PyMVA-Torch-Multiclass)
Expand Down Expand Up @@ -139,4 +139,4 @@ if((PY_KERAS_FOUND AND PY_THEANO_FOUND) OR (PY_KERAS_FOUND AND PY_TENSORFLOW_FOU
)
target_link_libraries(TestRModelParserKeras ${BLAS_LINKER_FLAGS} ${BLAS_LIBRARIES})

endif((PY_KERAS_FOUND AND PY_THEANO_FOUND) OR (PY_KERAS_FOUND AND PY_TENSORFLOW_FOUND))
endif()
4 changes: 2 additions & 2 deletions tmva/sofie/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ endif()

# gtest
# Look for needed python modules
find_python_module(torch QUIET)
if(PY_TORCH_FOUND)
ROOT_FIND_PYTHON_MODULE(torch)
if(ROOT_TORCH_FOUND)
configure_file(Conv1dModelGenerator.py Conv1dModelGenerator.py COPYONLY)
configure_file(Conv2dModelGenerator.py Conv2dModelGenerator.py COPYONLY)
configure_file(Conv3dModelGenerator.py Conv3dModelGenerator.py COPYONLY)
Expand Down
4 changes: 2 additions & 2 deletions tmva/tmva/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ if(dataframe)
endif()

if(dataframe)
find_python_module(xgboost QUIET)
if (PY_XGBOOST_FOUND)
ROOT_FIND_PYTHON_MODULE(xgboost QUIET)
if (ROOT_XGBOOST_FOUND)
ROOT_ADD_PYUNITTEST(rbdt_xgboost rbdt_xgboost.py)
endif()
endif()
Expand Down
36 changes: 18 additions & 18 deletions tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ else()
endif()
#these depends on external packages
if (machine_learning-pymva)
find_python_module(torch QUIET)
find_python_module(keras QUIET)
find_python_module(sonnet QUIET)
find_python_module(graph_nets QUIET)
find_python_module(sklearn QUIET)
ROOT_FIND_PYTHON_MODULE(torch QUIET)
ROOT_FIND_PYTHON_MODULE(keras QUIET)
ROOT_FIND_PYTHON_MODULE(sonnet QUIET)
ROOT_FIND_PYTHON_MODULE(graph_nets QUIET)
ROOT_FIND_PYTHON_MODULE(sklearn QUIET)
endif()
if (NOT PY_KERAS_FOUND)
if (NOT ROOT_KERAS_FOUND)
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_Keras.C)
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_Keras_HiggsModel.C)
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_RDataFrame.C)
Expand All @@ -318,16 +318,16 @@ else()
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_RSofieReader.C)
list(APPEND tmva_veto machine_learning/RBatchGenerator_TensorFlow.py)
endif()
if (NOT PY_SKLEARN_FOUND)
if (NOT ROOT_SKLEARN_FOUND)
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_Models.py roofit/rf617_simulation_based_inference_multidimensional.py)
endif()
if (NOT PY_TORCH_FOUND)
if (NOT ROOT_TORCH_FOUND)
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_PyTorch.C)
list(APPEND tmva_veto machine_learning/RBatchGenerator_PyTorch.py)
endif()
#veto this tutorial since it is added directly
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_GNN_Parser.py)
if (NOT PY_SONNET_FOUND OR NOT PY_GRAPH_NETS_FOUND)
if (NOT ROOT_SONNET_FOUND OR NOT ROOT_GRAPH_NETS_FOUND)
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_GNN.py)
list(APPEND tmva_veto machine_learning/TMVA_SOFIE_GNN_Application.C)
endif()
Expand Down Expand Up @@ -587,18 +587,18 @@ set (machine_learning-tmva101_Training-depends tutorial-machine_learning-tmva100
set (machine_learning-tmva102_Testing-depends tutorial-machine_learning-tmva101_Training-py)
set (machine_learning-tmva003_RReader-depends tutorial-machine_learning-TMVAClassification)
set (machine_learning-tmva004_RStandardScaler-depends tutorial-machine_learning-tmva003_RReader)
if (PY_TORCH_FOUND)
if (ROOT_TORCH_FOUND)
set (machine_learning-pytorch-ApplicationClassificationPyTorch-depends tutorial-machine_learning-pytorch-ClassificationPyTorch-py)
set (machine_learning-pytorch-RegressionPyTorch-depends tutorial-machine_learning-pytorch-ApplicationClassificationPyTorch-py)
set (machine_learning-pytorch-ApplicationRegressionPyTorch-depends tutorial-machine_learning-pytorch-RegressionPyTorch-py)
endif()
if (PY_KERAS_FOUND)
if (ROOT_KERAS_FOUND)
set (machine_learning-TMVA_SOFIE_RSofieReader-depends tutorial-machine_learning-TMVA_Higgs_Classification)
set (machine_learning-TMVA_SOFIE_RDataFrame_JIT-depends tutorial-machine_learning-TMVA_SOFIE_RSofieReader)
set (machine_learning-TMVA_SOFIE_Keras_HiggsModel-depends tutorial-machine_learning-TMVA_SOFIE_RDataFrame_JIT)
set (machine_learning-TMVA_SOFIE_RDataFrame-depends tutorial-machine_learning-TMVA_SOFIE_Keras_HiggsModel)
set (machine_learning-TMVA_SOFIE_Inference-depends tutorial-machine_learning-TMVA_SOFIE_RDataFrame)
if (PY_TORCH_FOUND)
if (ROOT_TORCH_FOUND)
set (machine_learning-keras-RegressionKeras-depends tutorial-machine_learning-pytorch-RegressionPyTorch-py)
set (machine_learning-keras-ClassificationKeras-depends tutorial-machine_learning-pytorch-ClassificationPyTorch-py)
endif()
Expand Down Expand Up @@ -641,7 +641,7 @@ if(ROOT_geom_FOUND)
FAILREGEX "Error in" "error:" "warning: Failed to call" LABELS tutorial ENVIRONMENT ${TUTORIAL_ENV})
endif()
# define Python GNN parsing tutorial needed to run before
if (PY_SONNET_FOUND AND PY_GRAPH_NETS_FOUND)
if (ROOT_SONNET_FOUND AND ROOT_GRAPH_NETS_FOUND)
ROOT_ADD_TEST(tutorial-machine_learning-TMVA_SOFIE_GNN_Parser COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/machine_learning/TMVA_SOFIE_GNN_Parser.py
PASSRC 0 FAILREGEX "Error in" ": error:" LABELS tutorial ENVIRONMENT ${TUTORIAL_ENV})
Expand Down Expand Up @@ -799,13 +799,13 @@ if(ROOT_pyroot_FOUND)
# Disable tutorial showing connection to the HTCondor service at CERN
list(APPEND pyveto analysis/dataframe/distrdf004_dask_lxbatch.py)

find_python_module(xgboost QUIET)
if(NOT PY_XGBOOST_FOUND OR NOT dataframe)
ROOT_FIND_PYTHON_MODULE(xgboost QUIET)
if(NOT ROOT_XGBOOST_FOUND OR NOT dataframe)
file(GLOB tmva_veto_py RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} machine_learning/tmva10*.py roofit/rf618_mixture_models.py)
list(APPEND pyveto ${tmva_veto_py})
endif()

if(NOT PY_KERAS_FOUND)
if(NOT ROOT_KERAS_FOUND)
file(GLOB tmva_veto_py RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} machine_learning/keras/*.py)
list(APPEND pyveto ${tmva_veto_py})
elseif(ROOT_ARCHITECTURE MATCHES macosx)
Expand All @@ -815,11 +815,11 @@ if(ROOT_pyroot_FOUND)
list(APPEND pyveto machine_learning/keras/MultiClassKeras.py)
endif()

if (PY_KERAS_FOUND)
if (ROOT_KERAS_FOUND)
set (machine_learning-TMVA_SOFIE_RDataFrame-py-depends tutorial-machine_learning-TMVA_SOFIE_Keras_HiggsModel)
endif()

if(NOT PY_TORCH_FOUND)
if(NOT ROOT_TORCH_FOUND)
file(GLOB tmva_veto_py RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} machine_learning/pytorch/*.py)
list(APPEND pyveto ${tmva_veto_py})
endif()
Expand Down

0 comments on commit eb552b0

Please sign in to comment.