Skip to content

Commit

Permalink
Merge pull request #277 from LLNL/feature/flexible_python_targets
Browse files Browse the repository at this point in the history
Feature/flexible python targets
  • Loading branch information
ldowen authored Jun 11, 2024
2 parents 97ddcbe + 13a1b37 commit d40e795
Show file tree
Hide file tree
Showing 55 changed files with 268 additions and 177 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Notable changes include:
* added MFV hydro from Hopkins 2015 with extension for ALE options

* Build changes / improvements:
* PYBind11 libraries no longer depend on the structure of the PYB11 source directory.
* CMake interface for adding PYBind11 target libraries is modified to more closely match how C++ libraries are created.
* Multiple Spheral Python modules / CMake targets can be specified for a single directory.
* KernelIntegrator and FieldList directories are divided into 2 modules / targets.
* tpl-manager.py will no longer use generic x86_64 configs for non LC systems. Users will be required to supply their own configs for pointing spack at external packages.

* Bug Fixes / improvements:
Expand Down
54 changes: 30 additions & 24 deletions cmake/spheral/SpheralAddLibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,35 @@ function(spheral_add_cxx_library package_name _cxx_obj_list)
set_target_properties(Spheral_${package_name} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endfunction()

#----------------------------------------------------------------------------------------
# spheral_add_pybin11_library_package
#----------------------------------------------------------------------------------------
# -------------------------------------------
# VARIABLES THAT NEED TO BE PREVIOUSLY DEFINED
# -------------------------------------------
# SPHERAL_BLT_DEPENDS : REQUIRED : List of external dependencies
# EXTRA_PYB11_SPHERAL_ENV_VARS : OPTIONAL : Additional directories containing python filed, used by LLNLSpheral
# <package_name>_headers : OPTIONAL : List of necessary headers to include
# <package_name>_sources : OPTIONAL : List of necessary source files to include
# SPHERAL_SUBMOD_DEPENDS : REQUIRED : List of submodule dependencies
# ----------------------
# INPUT-OUTPUT VARIABLES
# ----------------------
# package_name : REQUIRED : Desired package name
# module_list_name : REQUIRED : The NAME of the global variable that is the list of
# Spheral python modules (not the list itself)
# INCLUDES : OPTIONAL : Target specific includes
# DEPENDS : OPTIONAL : Target specific dependencies
# SOURCE : OPTIONAL : Target specific sources
# -----------------------
# OUTPUT VARIABLES TO USE - Made available implicitly after function call
# -----------------------
# Spheral<package_name> : Target for a given Spheral python module
# Spheral<package_name>_src : Target for the PYB11Generated source code for a given Spheral module
# <module_list_name> : List of Spheral python modules, appended with current module name
#----------------------------------------------------------------------------------------

#-----------------------------------------------------------------------------------
# spheral_add_pybind11_library
# - Generate the python friendly Spheral package lib
#
# Args:
# package_name : *name* of spheral package to make into a library
# INCLUDES : optional, any additional include paths
# SOURCES : optional, any additional source files to compile into the library
# DEPENDS : optional, extra dependencies
#
# Variables that must be set before calling spheral_add_obj_library:
# spheral_depends
# - List of targets the library depends on
# SPHERAL_BLT_DEPENDS
# - List of blt/libs the library depends on
#
#-----------------------------------------------------------------------------------

function(spheral_add_pybind11_library package_name)
function(spheral_add_pybind11_library package_name module_list_name)

# Define our arguments
set(options )
Expand Down Expand Up @@ -205,8 +214,6 @@ function(spheral_add_pybind11_library package_name)

# Get the TPL dependencies
get_property(SPHERAL_BLT_DEPENDS GLOBAL PROPERTY SPHERAL_BLT_DEPENDS)
get_property(spheral_tpl_includes GLOBAL PROPERTY spheral_tpl_includes)
get_property(spheral_tpl_libraries GLOBAL PROPERTY spheral_tpl_libraries)
# If building shared libraries, use the SPHERAL_OBJ_LIBS global list
# Note, LLNLSpheral has appended any local targets to this list as well
if(ENABLE_DEV_BUILD)
Expand All @@ -222,8 +229,7 @@ function(spheral_add_pybind11_library package_name)
SOURCE ${package_name}_PYB11.py
DEPENDS ${SPHERAL_BLT_DEPENDS} ${SPHERAL_CXX_DEPENDS} ${EXTRA_CXX_DEPENDS} ${SPHERAL_DEPENDS}
PYTHONPATH ${PYTHON_ENV_STR}
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${SPHERAL_INCLUDES} ${${package_name}_INCLUDES} ${spheral_tpl_includes} ${PYBIND11_ROOT_DIR}/include
LINKS ${spheral_tpl_libraries}
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${${package_name}_INCLUDES} ${PYBIND11_ROOT_DIR}/include
COMPILE_OPTIONS ${SPHERAL_PYB11_TARGET_FLAGS}
USE_BLT ON
EXTRA_SOURCE ${${package_name}_SOURCES}
Expand All @@ -235,7 +241,7 @@ function(spheral_add_pybind11_library package_name)
install(TARGETS ${MODULE_NAME}
DESTINATION ${SPHERAL_SITE_PACKAGES_PATH}/Spheral
)

set_property(GLOBAL APPEND PROPERTY ${module_list_name} ${package_name})
# Set the r-path of the C++ lib such that it is independent of the build dir when installed
set_target_properties(${MODULE_NAME} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

Expand Down
2 changes: 1 addition & 1 deletion cmake/spheral/SpheralInstallPythonFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function(spheral_install_python_files)

if (NOT ENABLE_CXXONLY)
install(FILES ${ARGV}
DESTINATION DESTINATION ${SPHERAL_SITE_PACKAGES_PATH}/Spheral)
DESTINATION ${SPHERAL_SITE_PACKAGES_PATH}/Spheral)
install(CODE "execute_process( \
COMMAND ${PYTHON_EXE} -m compileall DESTINATION ${SPHERAL_SITE_PACKAGES_PATH}/Spheral \
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX})")
Expand Down
4 changes: 2 additions & 2 deletions src/PYB11/ANEOS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
spheral_add_pybind11_library(ANEOS
INCLUDES ${SPHERAL_ROOT_DIR}/src/Pybind11Wraps/ANEOS)
spheral_add_pybind11_library(ANEOS SPHERAL_MODULE_LIST
INCLUDES ${SPHERAL_ROOT_DIR}/src/Pybind11Wraps/ANEOS SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/ArtificialConduction/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(ArtificialConduction)
spheral_add_pybind11_library(ArtificialConduction SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/ArtificialViscosity/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(ArtificialViscosity)
spheral_add_pybind11_library(ArtificialViscosity SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Boundary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Boundary)
spheral_add_pybind11_library(Boundary SPHERAL_MODULE_LIST)
5 changes: 4 additions & 1 deletion src/PYB11/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# When Python targets are created, they add the module name to SPHERAL_MODULE_LIST
set (_python_packages
CXXTypes
CXXTests
Expand Down Expand Up @@ -65,7 +66,9 @@ foreach(_python_package ${_python_packages})
add_subdirectory(${_python_package})
endforeach()

string(REPLACE ";" " " PYTHONPKGS "${_python_packages}")
# This global list is filled in each spheral_add_pybind11_library call
get_property(SPHERAL_MODULE_LIST GLOBAL PROPERTY SPHERAL_MODULE_LIST)
string(REPLACE ";" " " PYTHONPKGS "${SPHERAL_MODULE_LIST}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/SpheralCompiledPackages.py.in
${CMAKE_CURRENT_BINARY_DIR}/SpheralCompiledPackages.py)
Expand Down
2 changes: 1 addition & 1 deletion src/PYB11/CRKSPH/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(CRKSPH)
spheral_add_pybind11_library(CRKSPH SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/CXXTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(CXXTests)
spheral_add_pybind11_library(CXXTests SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/CXXTypes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(CXXTypes)
spheral_add_pybind11_library(CXXTypes SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/DEM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(DEM)
spheral_add_pybind11_library(DEM SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Damage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Damage)
spheral_add_pybind11_library(Damage SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/DataBase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(DataBase)
spheral_add_pybind11_library(DataBase SPHERAL_MODULE_LIST)
4 changes: 2 additions & 2 deletions src/PYB11/DataOutput/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
spheral_add_pybind11_library(DataOutput
spheral_add_pybind11_library(DataOutput SPHERAL_MODULE_LIST
SOURCES RestartableObject.cc
INCLUDES ${SPHERAL_ROOT_DIR}/src/Pybind11Wraps/DataOutput)
INCLUDES ${SPHERAL_ROOT_DIR}/src/Pybind11Wraps/DataOutput SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/DeviceTestLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(DeviceTestLib)
spheral_add_pybind11_library(DeviceTestLib SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Distributed)
spheral_add_pybind11_library(Distributed SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/ExternalForce/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(ExternalForce)
spheral_add_pybind11_library(ExternalForce SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/FSISPH/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(FSISPH)
spheral_add_pybind11_library(FSISPH SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Field/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Field)
spheral_add_pybind11_library(Field SPHERAL_MODULE_LIST)
7 changes: 4 additions & 3 deletions src/PYB11/FieldList/ArithmeticFieldList.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from PYB11Generator import *
from FieldList import *
import FieldList
import FieldListBase

#-------------------------------------------------------------------------------
# FieldList with numeric operations
#-------------------------------------------------------------------------------
@PYB11template("Dimension", "Value")
@PYB11pycppname("FieldList")
class ArithmeticFieldList(FieldListBase):
class ArithmeticFieldList(FieldListBase.FieldListBase):

PYB11typedefs = """
typedef FieldList<%(Dimension)s, %(Value)s> FieldListType;
Expand Down Expand Up @@ -138,4 +139,4 @@ def localMax(self):
#-------------------------------------------------------------------------------
# Inject FieldList
#-------------------------------------------------------------------------------
PYB11inject(FieldList, ArithmeticFieldList)
PYB11inject(FieldList.FieldList, ArithmeticFieldList)
62 changes: 62 additions & 0 deletions src/PYB11/FieldList/ArithmeticFieldList_PYB11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Spheral ArithmeticFieldList module.
Provides the ArithmeticFieldList classes.
"""

from PYB11Generator import *
from SpheralCommon import *
from spheralDimensions import *
dims = spheralDimensions()

from ArithmeticFieldList import *
from MinMaxFieldList import *

#-------------------------------------------------------------------------------
# Includes
#-------------------------------------------------------------------------------
PYB11includes += ['"Geometry/Dimension.hh"',
'"Field/FieldBase.hh"',
'"Field/Field.hh"',
'"Field/FieldList.hh"',
'"Field/FieldListSet.hh"',
'"Utilities/FieldDataTypeTraits.hh"',
'"Utilities/DomainNode.hh"',
'"Geometry/CellFaceFlag.hh"',
'<vector>']

#-------------------------------------------------------------------------------
# Namespaces
#-------------------------------------------------------------------------------
PYB11namespaces = ["Spheral"]

#-------------------------------------------------------------------------------
# Do our dimension dependent instantiations.
#-------------------------------------------------------------------------------
for ndim in dims:

#...........................................................................
# arithmetic fields
for (value, label) in (("int", "Int"),
("unsigned", "Unsigned"),
("uint64_t", "ULL"),
("Dim<%i>::Vector" % ndim, "Vector"),
("Dim<%i>::Tensor" % ndim, "Tensor"),
("Dim<%i>::ThirdRankTensor" % ndim, "ThirdRankTensor"),
("Dim<%i>::FourthRankTensor" % ndim, "FourthRankTensor"),
("Dim<%i>::FifthRankTensor" % ndim, "FifthRankTensor")):
exec('''
%(label)sFieldList%(ndim)sd = PYB11TemplateClass(ArithmeticFieldList, template_parameters=("Dim<%(ndim)i>", "%(value)s"))
''' % {"ndim" : ndim,
"value" : value,
"label" : label})

#...........................................................................
# A few fields can apply the min/max with a scalar additionally
for (value, label) in (("double", "Scalar"),
("Dim<%i>::SymTensor" % ndim, "SymTensor")):
exec('''
%(label)sFieldList%(ndim)sd = PYB11TemplateClass(MinMaxFieldList, template_parameters=("Dim<%(ndim)i>", "%(value)s"))
''' % {"ndim" : ndim,
"value" : value,
"label" : label})
3 changes: 2 additions & 1 deletion src/PYB11/FieldList/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spheral_add_pybind11_library(FieldList)
spheral_add_pybind11_library(FieldList SPHERAL_MODULE_LIST)
spheral_add_pybind11_library(ArithmeticFieldList SPHERAL_MODULE_LIST)
28 changes: 0 additions & 28 deletions src/PYB11/FieldList/FieldList_PYB11.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from FieldListBase import *
from FieldList import *
from ArithmeticFieldList import *
from MinMaxFieldList import *
from FieldListSet import *

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -58,32 +56,6 @@
("RKCoefficients<Dim<%i>>" % ndim, "RKCoefficients")):
exec('''
%(label)sFieldList%(ndim)sd = PYB11TemplateClass(FieldList, template_parameters=("Dim<%(ndim)i>", "%(value)s"))
''' % {"ndim" : ndim,
"value" : value,
"label" : label})

#...........................................................................
# arithmetic fields
for (value, label) in (("int", "Int"),
("unsigned", "Unsigned"),
("uint64_t", "ULL"),
("Dim<%i>::Vector" % ndim, "Vector"),
("Dim<%i>::Tensor" % ndim, "Tensor"),
("Dim<%i>::ThirdRankTensor" % ndim, "ThirdRankTensor"),
("Dim<%i>::FourthRankTensor" % ndim, "FourthRankTensor"),
("Dim<%i>::FifthRankTensor" % ndim, "FifthRankTensor")):
exec('''
%(label)sFieldList%(ndim)sd = PYB11TemplateClass(ArithmeticFieldList, template_parameters=("Dim<%(ndim)i>", "%(value)s"))
''' % {"ndim" : ndim,
"value" : value,
"label" : label})

#...........................................................................
# A few fields can apply the min/max with a scalar addtionally
for (value, label) in (("double", "Scalar"),
("Dim<%i>::SymTensor" % ndim, "SymTensor")):
exec('''
%(label)sFieldList%(ndim)sd = PYB11TemplateClass(MinMaxFieldList, template_parameters=("Dim<%(ndim)i>", "%(value)s"))
''' % {"ndim" : ndim,
"value" : value,
"label" : label})
Expand Down
4 changes: 3 additions & 1 deletion src/PYB11/FieldList/MinMaxFieldList.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from PYB11Generator import *
import FieldList
import FieldListBase
from ArithmeticFieldList import *

#-------------------------------------------------------------------------------
# Add min/max operations to a Field
#-------------------------------------------------------------------------------
@PYB11template("Dimension", "Value")
@PYB11pycppname("FieldList")
class MinMaxFieldList(FieldListBase):
class MinMaxFieldList(FieldListBase.FieldListBase):

PYB11typedefs = """
typedef FieldList<%(Dimension)s, %(Value)s> FieldListType;
Expand Down
2 changes: 1 addition & 1 deletion src/PYB11/FieldOperations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(FieldOperations)
spheral_add_pybind11_library(FieldOperations SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/FileIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(FileIO)
spheral_add_pybind11_library(FileIO SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/GSPH/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(GSPH)
spheral_add_pybind11_library(GSPH SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Geometry)
spheral_add_pybind11_library(Geometry SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Gravity/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Gravity)
spheral_add_pybind11_library(Gravity SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Helmholtz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Helmholtz)
spheral_add_pybind11_library(Helmholtz SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Hydro/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Hydro)
spheral_add_pybind11_library(Hydro SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Integrator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Integrator)
spheral_add_pybind11_library(Integrator SPHERAL_MODULE_LIST)
2 changes: 1 addition & 1 deletion src/PYB11/Kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
spheral_add_pybind11_library(Kernel)
spheral_add_pybind11_library(Kernel SPHERAL_MODULE_LIST)
3 changes: 2 additions & 1 deletion src/PYB11/KernelIntegrator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spheral_add_pybind11_library(KernelIntegrator)
spheral_add_pybind11_library(KernelIntegrator SPHERAL_MODULE_LIST)
spheral_add_pybind11_library(IntegrationKernels SPHERAL_MODULE_LIST)
20 changes: 0 additions & 20 deletions src/PYB11/KernelIntegrator/IntegrationCoefficient.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,4 @@ def evaluateCoefficient(self,
kid = "const KernelIntegrationData<%(Dimension)s>&"):
"Return a value for the coefficient"
return "%(CoefficientType)s"

@PYB11template("Dimension", "CoefficientType")
@PYB11holder("std::shared_ptr")
class IntegralDependsOnCoefficient:
def pyinit(self):
"Choose coefficient for integral (coefficient defaults to one)"

coefficient = PYB11property(doc="The coefficient",
getter = "getCoefficient",
setter = "setCoefficient")

@PYB11template("Dimension", "CoefficientType")
@PYB11holder("std::shared_ptr")
class IntegralDependsOnFieldListCoefficient:
def pyinit(self):
"Choose coefficient for integral"

coefficient = PYB11property(doc="The coefficient",
getter = "getCoefficient",
setter = "setCoefficient")

Loading

0 comments on commit d40e795

Please sign in to comment.