Skip to content

Commit d5057ec

Browse files
authored
Merge Pull Request E3SM-Project#2851 from E3SM-Project/scream/bartgol/eamxx/pyscream
Automatically Merged using E3SM Pull Request AutoTester PR Title: Initial implementation of pyscream module(s) for running eamxx from python PR Author: bartgol PR LABELS: AT: AUTOMERGE, python
2 parents 3a0cee9 + 1bd69ad commit d5057ec

40 files changed

+941
-12
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
*.la
1010
*.a
1111

12+
# Shared libraries
13+
*.so
14+
*.so.*
15+
1216
# Executables
1317
*.exe
1418

@@ -41,3 +45,9 @@ site
4145
components/eamxx/site/*
4246
# Ignore auto-generated eamxx_params.md file
4347
components/eamxx/docs/common/eamxx_params.md
48+
49+
# Python packaging
50+
*.egg-info
51+
components/eamxx/src/python/build
52+
components/eamxx/src/python/build_src
53+
components/eamxx/src/python/dist

components/eamxx/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ set(SCREAM_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
272272
set(SCREAM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
273273
set(SCREAM_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
274274

275+
option (EAMXX_ENABLE_PYBIND "Whether to enable python interface to eamxx, via pybind11" OFF)
276+
if (EAMXX_ENABLE_PYBIND)
277+
# Pybind11 requires shared libraries
278+
set (BUILD_SHARED_LIBS ON)
279+
endif()
280+
275281
####################################################################
276282
# Packs-related settings #
277283
####################################################################

components/eamxx/cmake/CompareNCFiles.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ function(CompareNCFiles)
1313
set (argsMv LABELS FIXTURES_REQUIRED)
1414

1515
cmake_parse_arguments(PARSE "${options}" "${args1v}" "${argsMv}" ${ARGN})
16-
CheckMacroArgs(CompareNCFilesFamily PARSE "${options}" "${args1v}" "${argsMv}")
16+
CheckMacroArgs(CompareNCFiles PARSE "${options}" "${args1v}" "${argsMv}")
1717

1818
# Sanity checks
1919
if (NOT PARSE_TEST_NAME)
20-
message ("Error! CompareNCFilesPair requires the keyword argument TEST_NAME")
20+
message ("Error! CompareNCFiles requires the keyword argument TEST_NAME")
2121
message (FATAL_ERROR "Aborting...")
2222
endif()
2323
if (NOT PARSE_SRC_FILE)
24-
message ("Error! CompareNCFilesPair requires the keyword argument SRC_FILE")
24+
message ("Error! CompareNCFiles requires the keyword argument SRC_FILE")
2525
message (FATAL_ERROR "Aborting...")
2626
endif()
2727
if (NOT PARSE_TGT_FILE)
28-
message ("Error! CompareNCFilesPair requires the keyword argument TGT_FILE")
28+
message ("Error! CompareNCFiles requires the keyword argument TGT_FILE")
2929
message (FATAL_ERROR "Aborting...")
3030
endif()
3131

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# - FindMPI4PY
2+
# Find mpi4py includes
3+
# This module defines:
4+
# MPI4PY_INCLUDE_DIR, where to find mpi4py.h, etc.
5+
# MPI4PY_FOUND
6+
7+
function (SetMpi4pyIncludeDir)
8+
endfunction()
9+
10+
if (NOT TARGET mpi4py)
11+
# If user provided an include dir, we will use that, otherwise we'll ask python to find it
12+
if (NOT MPI4PY_INCLUDE_DIR)
13+
execute_process(COMMAND
14+
"${PYTHON_EXECUTABLE}" "-c" "import mpi4py; print (mpi4py.get_include())"
15+
OUTPUT_VARIABLE OUTPUT
16+
RESULT_VARIABLE RESULT
17+
OUTPUT_STRIP_TRAILING_WHITESPACE)
18+
if (RESULT)
19+
set(MPI4PY_FOUND FALSE)
20+
else ()
21+
set (MPI4PY_INCLUDE_DIR ${OUTPUT} CACHE PATH "Path to mpi4py include directory" FORCE)
22+
endif()
23+
endif()
24+
25+
# If we still don't have an include dir, it means we have no mpi4py installed
26+
if (NOT MPI4PY_INCLUDE_DIR)
27+
set(MPI4PY_FOUND FALSE)
28+
else ()
29+
add_library(mpi4py INTERFACE)
30+
target_include_directories(mpi4py INTERFACE SYSTEM ${MPI4PY_INCLUDE_DIR})
31+
set(MPI4PY_FOUND TRUE)
32+
endif()
33+
endif()
34+
35+
include(FindPackageHandleStandardArgs)
36+
find_package_handle_standard_args(mpi4py DEFAULT_MSG MPI4PY_INCLUDE_DIR)

components/eamxx/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ add_subdirectory(control)
77
if (PROJECT_NAME STREQUAL "E3SM")
88
add_subdirectory(mct_coupling)
99
endif()
10+
11+
if (EAMXX_ENABLE_PYBIND)
12+
add_subdirectory(python)
13+
endif()

components/eamxx/src/control/atmosphere_driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ void AtmosphereDriver::run (const int dt) {
16091609
// that quantity at the beginning of the timestep. Or they may need to store
16101610
// the timestamp at the beginning of the timestep, so that we can compute
16111611
// dt at the end.
1612-
for (auto it : m_output_managers) {
1612+
for (auto& it : m_output_managers) {
16131613
it.init_timestep(m_current_ts,dt);
16141614
}
16151615

components/eamxx/src/physics/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
add_library(eamxx_physics INTERFACE)
2+
13
# Build shared physics functions first, so other parametrizations can use them
24
add_subdirectory(share)
35

components/eamxx/src/physics/cld_fraction/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ target_compile_definitions(cld_fraction PUBLIC EAMXX_HAS_CLD_FRACTION)
1414
target_link_libraries(cld_fraction physics_share scream_share)
1515
target_compile_options(cld_fraction PUBLIC)
1616

17+
# Add this library to eamxx_physics
18+
target_link_libraries(eamxx_physics INTERFACE cld_fraction)
19+
1720
# Cloud fraction does not yet have a set of unit tests or a BFB test comparing with the F90
1821
# code.
1922
# The cloud fraction stand alone test, in the /tests/ directory covers a range of property

components/eamxx/src/physics/cosp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ add_library(eamxx_cosp ${COSP_SRCS})
5353
target_link_libraries(eamxx_cosp physics_share scream_share cosp)
5454
target_compile_options(eamxx_cosp PUBLIC)
5555
target_compile_definitions(eamxx_cosp PUBLIC EAMXX_HAS_COSP)
56+
57+
# Add this library to eamxx_physics
58+
target_link_libraries(eamxx_physics INTERFACE eamxx_cosp)

components/eamxx/src/physics/mam/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ target_link_libraries(mam PUBLIC physics_share scream_share mam4xx haero)
5555
#if (NOT SCREAM_LIB_ONLY)
5656
# add_subdirectory(tests)
5757
#endif()
58+
59+
# Add this library to eamxx_physics
60+
target_link_libraries(eamxx_physics INTERFACE mam)

0 commit comments

Comments
 (0)