Added Python example for replace case

(and replaced tabs with spaces in CMake file for GRPCinterface)
This commit is contained in:
Gaute Lindkvist 2020-09-23 10:02:18 +02:00
parent 75f507e2ef
commit df51c9becb
2 changed files with 131 additions and 121 deletions

View File

@ -8,13 +8,13 @@ set ( SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.h
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.h ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.h
) )
set ( SOURCE_GROUP_SOURCE_FILES set ( SOURCE_GROUP_SOURCE_FILES
@ -23,13 +23,13 @@ set ( SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcServiceInterface.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCaseService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcSimulationWellService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcGridService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcProjectService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcCommandService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcAppService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPropertiesService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcNNCPropertiesService.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaGrpcPdmObjectService.cpp
) )
add_definitions(-DENABLE_GRPC) add_definitions(-DENABLE_GRPC)
@ -41,10 +41,10 @@ if (MSVC)
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation. # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
set(protobuf_MODULE_COMPATIBLE ON) set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf CONFIG 3.0 QUIET) find_package(Protobuf CONFIG 3.0 QUIET)
if (Protobuf_FOUND) if (Protobuf_FOUND)
message(STATUS "Using protobuf ${protobuf_VERSION}") message(STATUS "Using protobuf ${protobuf_VERSION}")
else() else()
message(FATAL_ERROR "Protocol Buffers not found. This is required to build with gRPC") message(FATAL_ERROR "Protocol Buffers not found. This is required to build with gRPC")
endif() endif()
# Find gRPC installation # Find gRPC installation
@ -65,29 +65,29 @@ if (MSVC)
) )
else() else()
find_package(gRPC CONFIG) find_package(gRPC CONFIG)
if(gRPC_FOUND) if(gRPC_FOUND)
message(STATUS "Found GRPC using find_package(gRPC CONFIG) ") message(STATUS "Found GRPC using find_package(gRPC CONFIG) ")
message(STATUS "Using gRPC ${gRPC_VERSION}") message(STATUS "Using gRPC ${gRPC_VERSION}")
set(GRPC_PACKAGE_LIBRARIES gRPC::gpr gRPC::grpc_unsecure gRPC::grpc++_unsecure) set(GRPC_PACKAGE_LIBRARIES gRPC::gpr gRPC::grpc_unsecure gRPC::grpc++_unsecure)
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>) set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
message(STATUS "_PROTOBUF_PROTOC : ${_PROTOBUF_PROTOC}") message(STATUS "_PROTOBUF_PROTOC : ${_PROTOBUF_PROTOC}")
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>) set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
message(STATUS "_GRPC_CPP_PLUGIN_EXECUTABLE : ${_GRPC_CPP_PLUGIN_EXECUTABLE}") message(STATUS "_GRPC_CPP_PLUGIN_EXECUTABLE : ${_GRPC_CPP_PLUGIN_EXECUTABLE}")
else() else()
set(RESINSIGHT_GRPC_INSTALL_PREFIX "" CACHE PATH "gRPC : Install prefix for gRPC") set(RESINSIGHT_GRPC_INSTALL_PREFIX "" CACHE PATH "gRPC : Install prefix for gRPC")
if (NOT DEFINED RESINSIGHT_GRPC_INSTALL_PREFIX OR NOT EXISTS ${RESINSIGHT_GRPC_INSTALL_PREFIX}) if (NOT DEFINED RESINSIGHT_GRPC_INSTALL_PREFIX OR NOT EXISTS ${RESINSIGHT_GRPC_INSTALL_PREFIX})
message(FATAL_ERROR "You need a valid RESINSIGHT_GRPC_INSTALL_PREFIX set to build with gRPC") message(FATAL_ERROR "You need a valid RESINSIGHT_GRPC_INSTALL_PREFIX set to build with gRPC")
endif() endif()
set(ENV{PKG_CONFIG_PATH} "${RESINSIGHT_GRPC_INSTALL_PREFIX}/lib/pkgconfig") set(ENV{PKG_CONFIG_PATH} "${RESINSIGHT_GRPC_INSTALL_PREFIX}/lib/pkgconfig")
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(GRPC REQUIRED grpc++_unsecure>=1.20 grpc_unsecure gpr protobuf) pkg_check_modules(GRPC REQUIRED grpc++_unsecure>=1.20 grpc_unsecure gpr protobuf)
set(_PROTOBUF_PROTOC "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/protoc") set(_PROTOBUF_PROTOC "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/protoc")
set(_GRPC_CPP_PLUGIN_EXECUTABLE "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/grpc_cpp_plugin") set(_GRPC_CPP_PLUGIN_EXECUTABLE "${RESINSIGHT_GRPC_INSTALL_PREFIX}/bin/grpc_cpp_plugin")
include_directories(AFTER ${GRPC_INCLUDE_DIRS}) include_directories(AFTER ${GRPC_INCLUDE_DIRS})
endif() endif()
endif() endif()
# Cannot use the nice new FindPackage modules for python since that is CMake 3.12+ # Cannot use the nice new FindPackage modules for python since that is CMake 3.12+
@ -98,15 +98,15 @@ endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
# Proto files # Proto files
set(PROTO_FILES set(PROTO_FILES
"Definitions" "Definitions"
"PdmObject" "PdmObject"
"Case" "Case"
"SimulationWell" "SimulationWell"
"Project" "Project"
"Commands" "Commands"
"NNCProperties" "NNCProperties"
"App" "App"
"Properties" "Properties"
"Grid" "Grid"
) )
set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}/Python") set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}/Python")
@ -115,7 +115,7 @@ foreach(proto_file ${PROTO_FILES})
get_filename_component(rips_proto "${CMAKE_CURRENT_LIST_DIR}/GrpcProtos/${proto_file}.proto" ABSOLUTE) get_filename_component(rips_proto "${CMAKE_CURRENT_LIST_DIR}/GrpcProtos/${proto_file}.proto" ABSOLUTE)
get_filename_component(rips_proto_path "${rips_proto}" PATH) get_filename_component(rips_proto_path "${rips_proto}" PATH)
list(APPEND GRPC_PROTO_FILES_FULL_PATH ${rips_proto}) list(APPEND GRPC_PROTO_FILES_FULL_PATH ${rips_proto})
set(rips_proto_srcs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.cc") set(rips_proto_srcs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.cc")
set(rips_proto_hdrs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.h") set(rips_proto_hdrs "${CMAKE_BINARY_DIR}/Generated/${proto_file}.pb.h")
@ -134,28 +134,28 @@ foreach(proto_file ${PROTO_FILES})
) )
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE) if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
set(rips_proto_python "rips/generated/${proto_file}_pb2.py") set(rips_proto_python "rips/generated/${proto_file}_pb2.py")
set(rips_grpc_python "rips/generated/${proto_file}_pb2_grpc.py") set(rips_grpc_python "rips/generated/${proto_file}_pb2_grpc.py")
add_custom_command( add_custom_command(
OUTPUT "${GRPC_PYTHON_SOURCE_PATH}/${rips_proto_python}" "${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}" OUTPUT "${GRPC_PYTHON_SOURCE_PATH}/${rips_proto_python}" "${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}"
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE}
ARGS -m grpc_tools.protoc ARGS -m grpc_tools.protoc
-I "${rips_proto_path}" -I "${rips_proto_path}"
--python_out "${GRPC_PYTHON_SOURCE_PATH}/rips/generated" --python_out "${GRPC_PYTHON_SOURCE_PATH}/rips/generated"
--grpc_python_out "${GRPC_PYTHON_SOURCE_PATH}/rips/generated" --grpc_python_out "${GRPC_PYTHON_SOURCE_PATH}/rips/generated"
"${rips_proto}" "${rips_proto}"
DEPENDS "${rips_proto}" DEPENDS "${rips_proto}"
COMMENT "Generating ${rips_proto_python} and ${rips_grpc_python}" COMMENT "Generating ${rips_proto_python} and ${rips_grpc_python}"
VERBATIM VERBATIM
) )
list (APPEND GRPC_PYTHON_GENERATED_SOURCES list (APPEND GRPC_PYTHON_GENERATED_SOURCES
${rips_proto_python} ${rips_proto_python}
${rips_grpc_python} ${rips_grpc_python}
) )
else() else()
message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not generate GRPC Python code.") message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not generate GRPC Python code.")
endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE) endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
list( APPEND GRPC_HEADER_FILES list( APPEND GRPC_HEADER_FILES
${rips_proto_hdrs} ${rips_proto_hdrs}
@ -170,74 +170,75 @@ foreach(proto_file ${PROTO_FILES})
endforeach(proto_file) endforeach(proto_file)
if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE) if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake
${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py) ${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py)
CONFIGURE_FILE( ${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake CONFIGURE_FILE( ${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake
${GRPC_PYTHON_SOURCE_PATH}/setup.py) ${GRPC_PYTHON_SOURCE_PATH}/setup.py)
list(APPEND GRPC_PYTHON_SOURCES list(APPEND GRPC_PYTHON_SOURCES
"rips/generated/RiaVersionInfo.py" "rips/generated/RiaVersionInfo.py"
"rips/__init__.py" "rips/__init__.py"
"rips/case.py" "rips/case.py"
"rips/contour_map.py" "rips/contour_map.py"
"rips/grid.py" "rips/grid.py"
"rips/gridcasegroup.py" "rips/gridcasegroup.py"
"rips/instance.py" "rips/instance.py"
"rips/pdmobject.py" "rips/pdmobject.py"
"rips/plot.py" "rips/plot.py"
"rips/project.py" "rips/project.py"
"rips/simulation_well.py" "rips/simulation_well.py"
"rips/view.py" "rips/view.py"
"rips/well_log_plot.py" "rips/well_log_plot.py"
"rips/PythonExamples/instance_example.py" "rips/PythonExamples/instance_example.py"
"rips/PythonExamples/command_example.py" "rips/PythonExamples/command_example.py"
"rips/PythonExamples/case_grid_group.py" "rips/PythonExamples/case_grid_group.py"
"rips/PythonExamples/case_info_streaming_example.py" "rips/PythonExamples/case_info_streaming_example.py"
"rips/PythonExamples/create_wbs_plot.py" "rips/PythonExamples/create_wbs_plot.py"
"rips/PythonExamples/export_plots.py" "rips/PythonExamples/export_plots.py"
"rips/PythonExamples/export_snapshots.py" "rips/PythonExamples/export_snapshots.py"
"rips/PythonExamples/error_handling.py" "rips/PythonExamples/error_handling.py"
"rips/PythonExamples/import_well_paths_and_logs.py" "rips/PythonExamples/import_well_paths_and_logs.py"
"rips/PythonExamples/soil_porv_async.py" "rips/PythonExamples/soil_porv_async.py"
"rips/PythonExamples/soil_porv_sync.py" "rips/PythonExamples/soil_porv_sync.py"
"rips/PythonExamples/selected_cases.py" "rips/PythonExamples/selected_cases.py"
"rips/PythonExamples/all_cases.py" "rips/PythonExamples/all_cases.py"
"rips/PythonExamples/set_grid_properties.py" "rips/PythonExamples/replace_case.py"
"rips/PythonExamples/set_cell_result.py" "rips/PythonExamples/set_grid_properties.py"
"rips/PythonExamples/set_flow_diagnostics_result.py" "rips/PythonExamples/set_cell_result.py"
"rips/PythonExamples/grid_information.py" "rips/PythonExamples/set_flow_diagnostics_result.py"
"rips/PythonExamples/input_prop_test_sync.py" "rips/PythonExamples/grid_information.py"
"rips/PythonExamples/input_prop_test_async.py" "rips/PythonExamples/input_prop_test_sync.py"
"rips/PythonExamples/soil_average_async.py" "rips/PythonExamples/input_prop_test_async.py"
"rips/PythonExamples/soil_average_sync.py" "rips/PythonExamples/soil_average_async.py"
"rips/PythonExamples/view_example.py" "rips/PythonExamples/soil_average_sync.py"
"rips/tests/test_cases.py" "rips/PythonExamples/view_example.py"
"rips/tests/test_grids.py" "rips/tests/test_cases.py"
"rips/tests/test_properties.py" "rips/tests/test_grids.py"
"rips/tests/test_project.py" "rips/tests/test_properties.py"
"rips/tests/conftest.py" "rips/tests/test_project.py"
"rips/tests/dataroot.py" "rips/tests/conftest.py"
"rips/tests/test_nnc_properties.py" "rips/tests/dataroot.py"
"rips/tests/test_simulation_wells.py" "rips/tests/test_nnc_properties.py"
"rips/tests/test_summary_cases.py" "rips/tests/test_simulation_wells.py"
"rips/tests/test_wells.py" "rips/tests/test_summary_cases.py"
"requirements.txt" "rips/tests/test_wells.py"
"setup.py" "requirements.txt"
"README.md" "setup.py"
"LICENSE" "README.md"
) "LICENSE"
)
list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES})
list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES})
foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES}) foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES})
list(APPEND GRPC_PYTHON_SOURCES_FULL_PATH "${GRPC_PYTHON_SOURCE_PATH}/${PYTHON_SCRIPT}") list(APPEND GRPC_PYTHON_SOURCES_FULL_PATH "${GRPC_PYTHON_SOURCE_PATH}/${PYTHON_SCRIPT}")
endforeach() endforeach()
if (MSVC) if (MSVC)
source_group(TREE ${GRPC_PYTHON_SOURCE_PATH} FILES ${GRPC_PYTHON_SOURCES_FULL_PATH} PREFIX "GrpcInterface\\Python") source_group(TREE ${GRPC_PYTHON_SOURCE_PATH} FILES ${GRPC_PYTHON_SOURCES_FULL_PATH} PREFIX "GrpcInterface\\Python")
endif(MSVC) endif(MSVC)
else() else()
message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not copy grpc Python code to build folder") message(STATUS "RESINSIGHT_GRPC_PYTHON_EXECUTABLE not specified. Will not copy grpc Python code to build folder")
endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE) endif(RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
list ( APPEND GRPC_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) list ( APPEND GRPC_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,9 @@
# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resinsight = rips.Instance.find()
# Example code
print("ResInsight version: " + resinsight.version_string())
case = resinsight.project.case(case_id=0)
case.replace(new_grid_file='C:/Users/lindkvis/Projects/ResInsight/TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID')