Python: added tests and made Octave InputPropTest.m general

* removed non-general hard-coded grid sizes and added timing to Octave test
* added two Pythonbenchmarks (sync and async) for the same test
This commit is contained in:
Gaute Lindkvist 2019-06-04 10:34:31 +02:00
parent b6427d84c3
commit 930abbf02f
9 changed files with 34 additions and 71 deletions

View File

@ -31,9 +31,13 @@ if (MSVC)
# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")
find_package(Protobuf CONFIG 3.0 REQUIRED)
message(STATUS "Using protobuf ${protobuf_VERSION}")
set(protobuf_MODULE_COMPATIBLE ON CACHE DBOOL "")
find_package(Protobuf CONFIG 3.0 QUIET)
if (Protobuf_FOUND)
message(STATUS "Using protobuf ${protobuf_VERSION}")
else()
message(FATAL_ERROR "Protocol Buffers not found. This is required to build with gRPC")
endif()
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
@ -54,7 +58,7 @@ if (MSVC)
else()
if (NOT DEFINED GRPC_INSTALL_PREFIX OR NOT EXISTS ${GRPC_INSTALL_PREFIX})
message(FATAL_ERROR "You need a valid GRPC_INSTALL_PREFIX set to build with GRPC")
message(FATAL_ERROR "You need a valid GRPC_INSTALL_PREFIX set to build with gRPC")
endif()
set(ENV{PKG_CONFIG_PATH} "${GRPC_INSTALL_PREFIX}/lib/pkgconfig")
find_package(PkgConfig REQUIRED)
@ -154,14 +158,16 @@ if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
"rips/Instance.py"
"examples/CommandExample.py"
"examples/CaseInfoStreamingExample.py"
"examples/PoroPermXSync.py"
"examples/PoroPermXAsync.py"
"examples/SoilPorvAsync.py"
"examples/SoilPorvSync.py"
"examples/SelectedCases.py"
"examples/AllCases.py"
"examples/SetGridProperties.py"
"examples/GridInformation.py"
"examples/InputPropTestSync.py"
"examples/InputPropTestAsync.py"
"examples/SoilAverage.py"
"examples/SoilAverageNoComm.py"
"tests/test_sample.py"
"requirements.txt"
"setup.py.cmake"

View File

@ -1,32 +0,0 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import rips
import itertools
resInsight = rips.Instance.find()
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
resultChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORO', 0)
results = []
for resultChunk in resultChunks:
for value in resultChunk.values:
results.append(value)
print("Transferred " + str(len(results)) + " poro results")
resultChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PERMX', 0)
permres = []
for resultChunk in resultChunks:
for value in resultChunk.values:
permres.append(value)
print("Transferred " + str(len(permres)) + " permx results")
poropermx = []
for (poro, permx) in zip(results, permres):
poropermx.append(poro * permx)
resInsight.properties.setActiveCellResults(poropermx, 0, 'GENERATED', 'PORO*PERMX2', 0)

View File

@ -2,6 +2,7 @@ import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import rips
import time
def createResult(poroChunks, permxChunks):
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
@ -12,6 +13,7 @@ def createResult(poroChunks, permxChunks):
resInsight = rips.Instance.find()
start = time.time()
case = resInsight.project.case(id=0)
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
@ -19,4 +21,7 @@ permxChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PERMX', 0)
case.properties.setActiveCellPropertyAsync(createResult(poroChunks, permxChunks), 'GENERATED', 'POROPERMXAS', 0)
end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")

View File

@ -1,22 +0,0 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import rips
import itertools
resInsight = rips.Instance.find()
#gridCount = resInsight.gridInfo.getGridCount(caseId=0)
#gridDimensions = resInsight.gridInfo.getAllGridDimensions(caseId=0)
poroChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PORO', 0)
permxChunks = resInsight.properties.activeCellResults(0, 'STATIC_NATIVE', 'PERMX', 0)
results = []
for (poroChunk, permxChunk) in zip(poroChunks, permxChunks):
print("Received chunks")
for (poro, permx) in zip(poroChunk.values, permxChunk.values):
results.append(poro * permx)
print("Transferred " + str(len(results)) + " poro and permx results")
resInsight.properties.setActiveCellResults(results, 0, 'GENERATED', 'PORO*PERMX2', 0)

View File

@ -2,9 +2,10 @@ import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import rips
import time
resInsight = rips.Instance.find()
start = time.time()
case = resInsight.project.case(id=0)
poroChunks = case.properties.activeCellProperty('STATIC_NATIVE', 'PORO', 0)
@ -25,4 +26,7 @@ for (poro, permx) in zip(poroResults, permxResults):
case.properties.setActiveCellProperty(results, 'GENERATED', 'POROPERMXSY', 0)
end = time.time()
print("Time elapsed: ", end - start)
print("Transferred all results back")

View File

@ -5,16 +5,16 @@ import rips
import itertools
import time
start = time.time()
resInsight = rips.Instance.find()
start = time.time()
case = resInsight.project.case(id=0)
grid = case.grid(index = 0)
timeSteps = case.timeSteps()
averages = []
for i in range(0, len(timeSteps)):
for i in range(0, len(timeSteps.dates)):
resultChunks = case.properties.activeCellProperty('DYNAMIC_NATIVE', 'SOIL', i)
mysum = 0.0
count = 0

View File

@ -52,5 +52,5 @@ class Case:
return self.stub.GetCellInfoForActiveCells(request)
def timeSteps(self):
return self.stub.GetTimeSteps(self.request).dates
return self.stub.GetTimeSteps(self.request)

View File

@ -74,7 +74,8 @@ class Properties:
time_step = timeStep,
grid_index = gridIndex,
porosity_model = porosityModelEnum)
return self.propertiesStub.GetGridProperty(request)
for chunk in self.propertiesStub.GetGridProperty(request):
yield chunk
def setActiveCellPropertyAsync(self, values_iterator, propertyType, propertyName, timeStep, gridIndex = 0, porosityModel = 'MATRIX_MODEL'):
propertyTypeEnum = Properties_pb2.PropertyType.Value(propertyType)

View File

@ -1,12 +1,13 @@
addpath("/home/builder/Projects/ResInsightBuildDir/OctavePlugin");
tic();
PORO = riGetActiveCellProperty("PORO");
PERMX = riGetActiveCellProperty("PERMX");
IJK = riGetMainGridDimensions();
GENERATED = PORO .* PERMX;
GENERATED(10:IJK(1):IJK(1)*IJK(2)*IJK(3)) = 100;
GENERATED(10*IJK(1):1:11*IJK(1)) = 100;
GENERATED(11*IJK(1):1:12*IJK(1)) = 100;
GENERATED(12*IJK(1):1:13*IJK(1)) = 100;
riSetActiveCellProperty(GENERATED, "PORO*PERMX");
riSetActiveCellProperty(GENERATED, "PORO*PERMX");
elapsed_time = toc();
disp("Elapsed time: "), disp(elapsed_time)