Skip to content

Commit

Permalink
fix only use torch if it is found
Browse files Browse the repository at this point in the history
  • Loading branch information
burlen committed Nov 29, 2020
1 parent 6efeda9 commit c810676
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 9 deletions.
25 changes: 25 additions & 0 deletions CMake/FindMatplotlib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#*****************************************************************************
# FindMatplotlib
#
# Check if matplotlib is installed and configure c-api includes
#
# This module defines
# Matplotlib_FOUND, set TRUE if matplotlib and c-api are available
# Matplotlib_VERSION, matplotlib release version

set(_TMP_PY_OUTPUT)
set(_TMP_PY_RETURN)
exec_program("${PYTHON_EXECUTABLE}"
ARGS "-c 'import matplotlib; print(matplotlib.__version__)'"
OUTPUT_VARIABLE _TMP_PY_OUTPUT
RETURN_VALUE _TMP_PY_RETURN)
set(Matplotlib_VERSION_FOUND FALSE)
if(NOT _TMP_PY_RETURN)
set(Matplotlib_VERSION_FOUND TRUE)
else()
set(_TMP_PY_OUTPUT)
endif()
set(Matplotlib_VERSION "${_TMP_PY_OUTPUT}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Matplotlib DEFAULT_MSG Matplotlib_VERSION_FOUND)
25 changes: 25 additions & 0 deletions CMake/FindPyTorch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#*****************************************************************************
# FindPyTorch
#
# Check if torch is installed and configure c-api includes
#
# This module defines
# PyTorch_FOUND, set TRUE if torch and c-api are available
# PyTorch_VERSION, torch release version

set(_TMP_PY_OUTPUT)
set(_TMP_PY_RETURN)
exec_program("${PYTHON_EXECUTABLE}"
ARGS "-c 'import torch; print(torch.__version__)'"
OUTPUT_VARIABLE _TMP_PY_OUTPUT
RETURN_VALUE _TMP_PY_RETURN)
set(PyTorch_VERSION_FOUND FALSE)
if(NOT _TMP_PY_RETURN)
set(PyTorch_VERSION_FOUND TRUE)
else()
set(_TMP_PY_OUTPUT)
endif()
set(PyTorch_VERSION "${_TMP_PY_OUTPUT}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PyTorch DEFAULT_MSG PyTorch_VERSION_FOUND)
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ if(PYTHONINTERP_FOUND)
endif()
find_package(PythonLibs ${TECA_PYTHON_VERSION})
find_package(NumPy)
find_package(PyTorch)
find_package(Matplotlib)
if (TECA_HAS_MPI)
find_package(MPI4Py)
endif()
Expand All @@ -288,7 +290,10 @@ elseif (REQUIRE_PYTHON)
else()
message(STATUS "Python ${TECA_PYTHON_VERSION} features -- not found. Requires Python, SWIG, numpy, and mpi4py if compiling with MPI")
endif()
set(TECA_HAS_PYTHON ${tmp} CACHE BOOL "Python binding")
set(TECA_HAS_PYTHON ${tmp} CACHE BOOL "TECA Python bindings")
set(TECA_HAS_NUMPY ${NumPy_FOUND} CACHE BOOL "Python NumPy module")
set(TECA_HAS_PYTORCH ${PyTorch_FOUND} CACHE BOOL "Python torch module")
set(TECA_HAS_MATPLOTLIB ${Matplotlib_FOUND} CACHE BOOL "Python matplotlib module")

# silence the annoying cmake warnings about REQUIRE_<X> when
# the required package X is actually found.
Expand Down
5 changes: 4 additions & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ teca_add_app(teca_cartesian_mesh_diff LIBS ${teca_app_link}

teca_add_python_app(teca_convert_table)
teca_add_python_app(teca_dataset_metadata FEATURES ${TECA_HAS_NETCDF})
teca_add_python_app(teca_deeplabv3p_ar_detect FEATURES ${TECA_HAS_NETCDF})

teca_add_python_app(teca_deeplabv3p_ar_detect
FEATURES ${TECA_HAS_NETCDF} ${TECA_HAS_PYTORCH})

teca_add_python_app(teca_temporal_reduction FEATURES ${TECA_HAS_NETCDF})
teca_add_python_app(teca_event_filter)
teca_add_python_app(teca_profile_explorer)
Expand Down
8 changes: 6 additions & 2 deletions python/teca_py_alg.i
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,16 @@
/***************************************************************************
model_segmentation
***************************************************************************/
%pythoncode "teca_model_segmentation.py"
#ifdef TECA_HAS_PYTORCH
%pythoncode "teca_model_segmentation.py"
#endif

/***************************************************************************
deeplabv3p_ar_detect
***************************************************************************/
%pythoncode "teca_deeplabv3p_ar_detect.py"
#ifdef TECA_HAS_PYTORCH
%pythoncode "teca_deeplabv3p_ar_detect.py"
#endif

/***************************************************************************
tc_activity
Expand Down
3 changes: 3 additions & 0 deletions teca_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#cmakedefine TECA_HAS_VTK
#cmakedefine TECA_HAS_PARAVIEW
#cmakedefine TECA_HAS_PYTHON
#cmakedefine TECA_HAS_NUMPY
#cmakedefine TECA_HAS_PYTORCH
#cmakedefine TECA_HAS_MATPLOTLIB
#cmakedefine TECA_HAS_LIBXLSXWRITER
#cmakedefine TECA_HAS_UDUNITS
#cmakedefine TECA_HAS_OPENSSL
Expand Down
5 changes: 3 additions & 2 deletions test/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
teca_add_test(test_deeplabv3p_ar_detect_app_thread
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_deeplabv3p_ar_detect_app.sh
${CMAKE_BINARY_DIR}/${BIN_PREFIX} ${TECA_DATA_ROOT} -1
FEATURES ${TECA_HAS_NETCDF}
FEATURES ${TECA_HAS_NETCDF} ${TECA_HAS_PYTORCH}
REQ_TECA_DATA)

teca_add_test(test_deeplabv3p_ar_detect_app_mpi
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_deeplabv3p_ar_detect_app.sh
${CMAKE_BINARY_DIR}/${BIN_PREFIX} ${TECA_DATA_ROOT} -1
${MPIEXEC} ${HALF_TEST_CORES}
FEATURES ${TECA_HAS_NETCDF_MPI} ${TECA_HAS_MPI} ${MPI4Py_FOUND}
FEATURES ${TECA_HAS_NETCDF_MPI} ${TECA_HAS_PYTORCH}
${TECA_HAS_MPI} ${MPI4Py_FOUND}
REQ_TECA_DATA)

teca_add_test(test_bayesian_ar_detect_app_thread
Expand Down
6 changes: 3 additions & 3 deletions test/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ teca_add_test(py_test_deeplabv3p_ar_detect_serial
"${TECA_DATA_ROOT}/cascade_deeplab_IVT.pt"
"${TECA_DATA_ROOT}/ARTMIP_MERRA_2D_2017-05.*\.nc$"
"${TECA_DATA_ROOT}/test_deeplabv3p_ar_detect" IVT 1
FEATURES ${TECA_HAS_NETCDF}
FEATURES ${TECA_HAS_NETCDF} ${TECA_HAS_PYTORCH}
REQ_TECA_DATA)

teca_add_test(py_test_deeplabv3p_ar_detect_threads
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_deeplabv3p_ar_detect.py
"${TECA_DATA_ROOT}/cascade_deeplab_IVT.pt"
"${TECA_DATA_ROOT}/ARTMIP_MERRA_2D_2017-05.*\.nc$"
"${TECA_DATA_ROOT}/test_deeplabv3p_ar_detect" IVT -1
FEATURES ${TECA_HAS_NETCDF}
FEATURES ${TECA_HAS_NETCDF} ${TECA_HAS_PYTORCH}
REQ_TECA_DATA)

teca_add_test(py_test_deeplabv3p_ar_detect_mpi_threads
Expand All @@ -410,7 +410,7 @@ teca_add_test(py_test_deeplabv3p_ar_detect_mpi_threads
"${TECA_DATA_ROOT}/cascade_deeplab_IVT.pt"
"${TECA_DATA_ROOT}/ARTMIP_MERRA_2D_2017-05.*\.nc$"
"${TECA_DATA_ROOT}/test_deeplabv3p_ar_detect" IVT -1
FEATURES ${TECA_HAS_NETCDF} ${TECA_HAS_MPI} ${MPI4Py_FOUND}
FEATURES ${TECA_HAS_NETCDF} ${TECA_HAS_PYTORCH} ${TECA_HAS_MPI} ${MPI4Py_FOUND}
REQ_TECA_DATA)

teca_add_test(py_test_binary_stream
Expand Down

0 comments on commit c810676

Please sign in to comment.