Skip to content

Commit

Permalink
Create the opm_embedded from the same shared library that is used to …
Browse files Browse the repository at this point in the history
…create opm.common.*

Now, there are two modules created
    - opmcommon_python
    - opm_embedded, as embedded Python module, needed for PYACTION and PYINPUT
  • Loading branch information
lisajulia committed Apr 26, 2024
1 parent 2a547e1 commit c0f290b
Show file tree
Hide file tree
Showing 9 changed files with 702 additions and 41 deletions.
24 changes: 0 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,34 +404,15 @@ if (OPM_ENABLE_PYTHON)

target_link_libraries(opmcommon_python PRIVATE
opmcommon)
if(OPM_ENABLE_EMBEDDED_PYTHON)
pybind11_add_module(opm_embedded
${PYTHON_CXX_SOURCE_FILES}
${PROJECT_BINARY_DIR}/python/cxx/builtin_pybind11.cpp)
target_link_libraries(opm_embedded PRIVATE
opmcommon)
endif()
if(TARGET pybind11::pybind11)
target_link_libraries(opmcommon_python PRIVATE
pybind11::pybind11)
if(OPM_ENABLE_EMBEDDED_PYTHON)
target_link_libraries(opm_embedded PRIVATE
pybind11::pybind11)
endif()
else()
target_include_directories(opmcommon_python SYSTEM PRIVATE ${pybind11_INCLUDE_DIRS})
if(OPM_ENABLE_EMBEDDED_PYTHON)
target_include_directories(opm_embedded SYSTEM PRIVATE ${pybind11_INCLUDE_DIRS})
endif()
endif()
set_target_properties(opmcommon_python PROPERTIES
LIBRARY_OUTPUT_DIRECTORY python/opm)
add_dependencies(opmcommon_python copy_python)
if(OPM_ENABLE_EMBEDDED_PYTHON)
set_target_properties(opm_embedded PROPERTIES
LIBRARY_OUTPUT_DIRECTORY python)
add_dependencies(opm_embedded copy_python)
endif()

# Generate versioned setup.py
configure_file(${PROJECT_SOURCE_DIR}/python/setup.py.in
Expand All @@ -456,11 +437,6 @@ if (OPM_ENABLE_PYTHON)
## Need to install this Python script such that it can be used by opm-simulators when building against an installed
## opm-common
install( PROGRAMS "python/install.py" DESTINATION "${OPM_PYTHON_COMMON_DIR}" )

# Install the convenience library for PYACTION script development
if (OPM_ENABLE_EMBEDDED_PYTHON)
install(TARGETS opm_embedded DESTINATION ${DEST_PREFIX}${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_PREFIX})
endif()
endif()

# Observe that if the opmcommon library has been built as a shared library the
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,15 @@ if(ENABLE_ECL_OUTPUT)
tests/ACTIONX_M1.X0010
tests/wclose.py
tests/msim/MSIM_PYACTION.DATA
tests/msim/MSIM_PYACTION_RETRIEVE_INFO.DATA
tests/msim/MSIM_PYACTION_CHANGING_SCHEDULE.DATA
tests/msim/MSIM_PYACTION_CHANGING_SCHEDULE_ACTIONX_CALLBACK.DATA
tests/msim/MSIM_PYACTION_INSERT_KEYWORD.DATA
tests/msim/MSIM_PYACTION_INSERT_INVALID_KEYWORD.DATA
tests/msim/MSIM_PYACTION_NO_RUN_FUNCTION.DATA
tests/msim/MSIM_PYACTION_OPEN_WELL_AT_PAST_REPORT_STEP.DATA
tests/msim/MSIM_PYACTION_OPEN_WELL_AT_TOO_LATE_REPORT_STEP.DATA
tests/msim/retrieve_info.py
tests/msim/action1.py
tests/msim/action2.py
tests/msim/action2_no_run_function.py
Expand Down
9 changes: 0 additions & 9 deletions python/cxx/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,3 @@ void python::common::export_all_opm_embedded(py::module& module) {
module.attr("current_report_step") = 0;
module.doc() = R"pbdoc(This is the opm_embedded module for embedding python code in PYACTION.)pbdoc";
}

/*
PYBIND11_MODULE create a Python of all the Python/C++ classes which are
generated in the python::common::export_all_opm_embedded() function in the wrapping code.
The same module is created as an embedded python module in PythonInterp.cpp
*/
PYBIND11_MODULE(opm_embedded, module) {
python::common::export_all_opm_embedded(module);
}
7 changes: 7 additions & 0 deletions python/opm_embedded/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
This is the opm_embedded module for embedding python code in PYACTION.
"""

from opm.opmcommon_python import current_ecl_state, current_summary_state, current_schedule, current_report_step
from opm.opmcommon_python import OpmLog
from opm.opmcommon_python import DeckKeyword # Needed for PYINPUT
1 change: 1 addition & 0 deletions python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ setup(
long_description=long_description,
long_description_content_type="text/markdown",
packages=[
'opm_embedded',
'opm',
'opm.io',
'opm.io.deck',
Expand Down

0 comments on commit c0f290b

Please sign in to comment.