Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, ert, size, verbose=False):
self._ert = ert
""" :type: ert.enkf.EnKFMain """
self._size = size
max_runtime = ert.analysisConfig().get_max_runtime()
job_queue = ert.siteConfig().getJobQueue()
job_queue.set_max_job_duration(max_runtime)
self._queue_manager = JobQueueManager(job_queue)
self._queue_manager.startQueue(size, verbose=verbose)
self._run_args = {}
""" :type: dict[int, RunArg] """
self._thread_pool = CThreadPool(8)
self._thread_pool.addTaskFunction("submitJob", ENKF_LIB, "enkf_main_isubmit_job__")
class EnkfVarType(BaseCEnum):
INVALID_VAR = None
PARAMETER = None
DYNAMIC_STATE = None
DYNAMIC_RESULT = None
STATIC_STATE = None
INDEX_STATE = None
EnkfVarType.addEnum("INVALID_VAR", 0)
EnkfVarType.addEnum("PARAMETER", 1)
EnkfVarType.addEnum("DYNAMIC_STATE", 2)
EnkfVarType.addEnum("DYNAMIC_RESULT", 4)
EnkfVarType.addEnum("STATIC_STATE", 8)
EnkfVarType.addEnum("INDEX_STATE", 16)
EnkfVarType.registerEnum(ENKF_LIB, "enkf_var_type_enum")
"""
RunpathList.cNamespace().add(self, realization_number, iteration_number, runpath, basename)
def clear(self):
RunpathList.cNamespace().clear(self)
def free(self):
RunpathList.cNamespace().free(self)
def export(self):
RunpathList.cNamespace().export(self)
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("runpath_list", RunpathList)
RunpathList.cNamespace().free = cwrapper.prototype("void runpath_list_free(runpath_list)")
RunpathList.cNamespace().add = cwrapper.prototype("void runpath_list_add(runpath_list, int, int, char*, char*)")
RunpathList.cNamespace().clear = cwrapper.prototype("void runpath_list_clear(runpath_list)")
RunpathList.cNamespace().size = cwrapper.prototype("int runpath_list_size(runpath_list)")
RunpathList.cNamespace().iens = cwrapper.prototype("int runpath_list_iget_iens(runpath_list, int)")
RunpathList.cNamespace().iteration = cwrapper.prototype("int runpath_list_iget_iter(runpath_list, int)")
RunpathList.cNamespace().runpath = cwrapper.prototype("char* runpath_list_iget_runpath(runpath_list, int)")
RunpathList.cNamespace().basename = cwrapper.prototype("char* runpath_list_iget_basename(runpath_list, int)")
RunpathList.cNamespace().export = cwrapper.prototype("void runpath_list_fprintf(runpath_list)")
RunpathList.cNamespace().alloc = cwrapper.prototype("c_void_p runpath_list_alloc(char*)")
return self[index]
def __iter__(self):
cur = 0
while cur < len(self):
yield self[cur]
cur += 1
def __getitem__(self, index):
""" @rtype: float """
return EnsemblePlotGenKWVector.cNamespace().get_value(self, index)
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("ensemble_plot_gen_kw_vector", EnsemblePlotGenKWVector)
cwrapper.registerType("ensemble_plot_gen_kw_vector_obj", EnsemblePlotGenKWVector.createPythonObject)
cwrapper.registerType("ensemble_plot_gen_kw_vector_ref", EnsemblePlotGenKWVector.createCReference)
EnsemblePlotGenKWVector.cNamespace().size = cwrapper.prototype("int enkf_plot_gen_kw_vector_get_size(ensemble_plot_gen_kw_vector)")
EnsemblePlotGenKWVector.cNamespace().get_value = cwrapper.prototype("double enkf_plot_gen_kw_vector_iget(ensemble_plot_gen_kw_vector, int)")
return self.getDataModelConfig()
elif implementation_type == ErtImplType.GEN_KW:
return self.getKeywordModelConfig()
elif implementation_type == ErtImplType.CUSTOM_KW:
return self.getCustomKeywordModelConfig()
elif implementation_type == ErtImplType.SUMMARY:
return SummaryConfig.createCReference(self.getPointerReference(), parent=self)
else:
print("[EnkfConfigNode::getModelConfig()] Unhandled implementation model type: %i" % implementation_type)
# raise NotImplementedError("Unknown model type: %i" % type)
def getKey(self):
return EnkfConfigNode.cNamespace().get_key( self )
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("enkf_config_node", EnkfConfigNode)
EnkfConfigNode.cNamespace().free = cwrapper.prototype("void enkf_config_node_free(enkf_config_node)")
EnkfConfigNode.cNamespace().get_ref = cwrapper.prototype("c_void_p enkf_config_node_get_ref(enkf_config_node)") #todo: fix return type
EnkfConfigNode.cNamespace().get_impl_type = cwrapper.prototype("ert_impl_type_enum enkf_config_node_get_impl_type(enkf_config_node)")
EnkfConfigNode.cNamespace().get_enkf_outfile = cwrapper.prototype("char* enkf_config_node_get_enkf_outfile(enkf_config_node)")
EnkfConfigNode.cNamespace().get_min_std_file = cwrapper.prototype("char* enkf_config_node_get_min_std_file(enkf_config_node)")
EnkfConfigNode.cNamespace().get_enkf_infile = cwrapper.prototype("char* enkf_config_node_get_enkf_infile(enkf_config_node)")
EnkfConfigNode.cNamespace().get_init_file_fmt = cwrapper.prototype("char* enkf_config_node_get_init_file_fmt(enkf_config_node)")
EnkfConfigNode.cNamespace().get_var_type = cwrapper.prototype("enkf_var_type_enum enkf_config_node_get_var_type(enkf_config_node)") #todo: fix return type as enum
EnkfConfigNode.cNamespace().get_key = cwrapper.prototype("char* enkf_config_node_get_key(enkf_config_node)")
EnkfConfigNode.cNamespace().get_obs_keys = cwrapper.prototype("stringlist_ref enkf_config_node_get_obs_keys(enkf_config_node)")
EnkfConfigNode.cNamespace().alloc_summary_node = cwrapper.prototype("enkf_config_node_obj enkf_config_node_alloc_summary(char*, load_fail_type)")
EnkfConfigNode.cNamespace().alloc_field_node = cwrapper.prototype("enkf_config_node_obj enkf_config_node_alloc_field(char*, ecl_grid, c_void_p, bool)")
EnkfConfigNode.cNamespace().update_state_field = cwrapper.prototype("void enkf_config_node_update_state_field(enkf_config_node, enkf_truncation_type_enum, double, double)")
from ert.cwrap import CWrapper, CNamespace
from ert.enkf import ENKF_LIB
class ErtLog(object):
cnamespace = None
@staticmethod
def log(log_level, message ):
ErtLog.cnamespace.write_log(log_level, message)
ErtLog.cnamespace = CNamespace("ErtLog")
cwrapper = CWrapper(ENKF_LIB)
ErtLog.cnamespace.init = cwrapper.prototype("void ert_log_init_log(int, char*, char*, bool)")
ErtLog.cnamespace.write_log = cwrapper.prototype("void ert_log_add_message_py(int, char*)")
@classmethod
def ENSEMBLE_EXPERIMENT(cls , fs , iens , runpath , iter = 0):
c_ptr = RunArg.cNamespace().alloc_ENSEMBLE_EXPERIMENT(fs , iens , iter , runpath)
return RunArg( c_ptr )
def free(self):
RunArg.cNamespace().free(self)
def getQueueIndex(self):
return RunArg.cNamespace().get_queue_index( self )
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("run_arg", RunArg)
RunArg.cNamespace().alloc_ENSEMBLE_EXPERIMENT = cwrapper.prototype("c_void_p run_arg_alloc_ENSEMBLE_EXPERIMENT(enkf_fs , int, int, char*)")
RunArg.cNamespace().free = cwrapper.prototype("void run_arg_free(run_arg)")
RunArg.cNamespace().get_queue_index = cwrapper.prototype("int run_arg_get_queue_index(run_arg)")
def igetMean(self , iobs):
if 0 <= iobs < self.getObsSize():
return MeasBlock.cNamespace().iget_mean(self , iobs)
else:
raise IndexError("Invalid observation index:%d valid range: [0,%d)" % (iobs , self.getObsSize()))
def igetStd(self , iobs):
if 0 <= iobs < self.getObsSize():
return MeasBlock.cNamespace().iget_std(self , iobs)
else:
raise IndexError("Invalid observation index:%d valid range: [0,%d)" % (iobs , self.getObsSize()))
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("meas_block", MeasBlock)
MeasBlock.cNamespace().alloc = cwrapper.prototype("c_void_p meas_block_alloc( char* , bool_vector , int)")
MeasBlock.cNamespace().free = cwrapper.prototype("void meas_block_free( meas_block )")
MeasBlock.cNamespace().get_active_ens_size = cwrapper.prototype("int meas_block_get_active_ens_size( meas_block )")
MeasBlock.cNamespace().get_total_ens_size = cwrapper.prototype("int meas_block_get_total_ens_size( meas_block )")
MeasBlock.cNamespace().get_total_obs_size = cwrapper.prototype("int meas_block_get_total_obs_size( meas_block )")
MeasBlock.cNamespace().iget_value = cwrapper.prototype("double meas_block_iget( meas_block , int , int)")
MeasBlock.cNamespace().iset_value = cwrapper.prototype("void meas_block_iset( meas_block , int , int , double)")
MeasBlock.cNamespace().iget_mean = cwrapper.prototype("double meas_block_iget_ens_mean( meas_block , int )")
MeasBlock.cNamespace().iget_std = cwrapper.prototype("double meas_block_iget_ens_std( meas_block , int )")
MeasBlock.cNamespace().iens_active = cwrapper.prototype("bool meas_block_iens_active( meas_block , int )")
post_simulation_hook = self.ert.getPostSimulationHook()
if post_simulation_hook.hasWorkflow():
post_simulation_hook.checkRunpathListFile()
workflow = post_simulation_hook.getWorkflow()
workflow_list = self.ert.getWorkflowList()
workflow.run(self.ert, context=workflow_list.getContext())
def smootherUpdate(self, target_fs):
""" @rtype: bool """
assert isinstance(target_fs, EnkfFs)
return EnkfSimulationRunner.cNamespace().smoother_update(self, target_fs)
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("enkf_simulation_runner", EnkfSimulationRunner)
EnkfSimulationRunner.cNamespace().run_assimilation = cwrapper.prototype("void enkf_main_run_assimilation(enkf_simulation_runner, bool_vector, int, int, int)")
EnkfSimulationRunner.cNamespace().run_smoother = cwrapper.prototype("void enkf_main_run_smoother(enkf_simulation_runner, char*, bool)")
EnkfSimulationRunner.cNamespace().run_simple_step = cwrapper.prototype("bool enkf_main_run_simple_step(enkf_simulation_runner, bool_vector, enkf_init_mode_enum, int)")
EnkfSimulationRunner.cNamespace().smoother_update = cwrapper.prototype("bool enkf_main_smoother_update(enkf_simulation_runner, enkf_fs)")
def getSize(self):
""" @rtype: float """
return len(self)
def getIndex(self, obs_index):
""" @rtype: int """
return self.getDataIndex( obs_index )
def getDataIndex(self, obs_index):
return GenObservation.cNamespace().get_data_index(self, obs_index)
cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("gen_obs", GenObservation)
cwrapper.registerType("gen_obs_obj", GenObservation.createPythonObject)
cwrapper.registerType("gen_obs_ref", GenObservation.createCReference)
GenObservation.cNamespace().get_value = cwrapper.prototype("double summary_obs_get_value(summary_obs)")
GenObservation.cNamespace().get_std = cwrapper.prototype("double gen_obs_iget_std(gen_obs, int)")
GenObservation.cNamespace().get_data = cwrapper.prototype("double gen_obs_iget_data(gen_obs, int)")
GenObservation.cNamespace().get_size = cwrapper.prototype("int gen_obs_get_size(gen_obs)")
GenObservation.cNamespace().get_data_index = cwrapper.prototype("int gen_obs_get_obs_index(gen_obs, int)")