class SummaryConfig(BaseCClass): TYPE_NAME = "summary_config" _alloc = ResPrototype( "void* summary_config_alloc(char*, load_fail_type)", bind=False ) _free = ResPrototype("void summary_config_free(summary_config)") _get_var = ResPrototype("char* summary_config_get_var(summary_config)") def __init__(self, key, load_fail=LoadFailTypeEnum.LOAD_FAIL_WARN): c_ptr = self._alloc(key, load_fail) super(SummaryConfig, self).__init__(c_ptr) def __repr__(self): return "SummaryConfig() %s" % self._ad_str() def free(self): self._free() @property def key(self): return self._get_var() def __ne__(self, other): return not self == other def __eq__(self, other): """ @rtype: bool""" if self.key != other.key: return False return True
class EnKFState(BaseCClass): TYPE_NAME = "enkf_state" _free = ResPrototype("void* enkf_state_free( enkf_state )") _get_ens_config = ResPrototype( "ens_config_ref enkf_state_get_ensemble_config( enkf_state )") _initialize = ResPrototype( "void enkf_state_initialize( enkf_state , enkf_fs , stringlist , enkf_init_mode_enum)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def free(self): self._free() def ensembleConfig(self): """ @rtype: EnsembleConfig """ return self._get_ens_config() def initialize(self, fs, param_list=None, init_mode=EnkfInitModeEnum.INIT_CONDITIONAL): if param_list is None: ens_config = self.ensembleConfig() param_list = ens_config.getKeylistFromVarType( EnkfVarType.PARAMETER) self._initialize(fs, param_list, init_mode)
class ErtTemplate(BaseCClass): TYPE_NAME = "ert_template" _free = ResPrototype("void ert_template_free( ert_template )") _get_template_file = ResPrototype("char* ert_template_get_template_file(ert_template)") _get_target_file = ResPrototype("char* ert_template_get_target_file(ert_template)") _get_args_as_string = ResPrototype("char* ert_template_get_args_as_string(ert_template)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def get_template_file(self): """ @rtype: str """ return self._get_template_file() def get_target_file(self): """ @rtype: str """ return self._get_target_file() def get_args_as_string(self): """ @rtype: str """ return self._get_args_as_string() def free(self): self._free()
class PathFormat(BaseCClass): TYPE_NAME = "path_fmt" _alloc = ResPrototype("void* path_fmt_alloc_directory_fmt(char*)", bind=False) _str = ResPrototype("char* path_fmt_get_fmt(path_fmt)") _free = ResPrototype("void path_fmt_free(path_fmt)") def __init__(self, path_fmt): c_ptr = self._alloc(path_fmt) if c_ptr: super().__init__(c_ptr) else: raise ValueError('Unable to construct path format "%s"' % path_fmt) def __repr__(self): return self._create_repr("fmt=%s" % self._str()) def free(self): self._free() def __ne__(self, other): return not self == other def __eq__(self, other): return os.path.realpath(self._str()) == os.path.realpath(other._str())
class Field(BaseCClass): TYPE_NAME = "field" _free = ResPrototype("void field_free( field )") _ijk_get_double = ResPrototype( "double field_ijk_get_double(field, int, int, int)") _export = ResPrototype( "void field_export(field, char* , fortio , enkf_field_file_format_enum , bool , char*)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def ijk_get_double(self, i, j, k): return self._ijk_get_double(i, j, k) def export(self, filename, file_type=None, init_file=None): output_transform = False if file_type is None: try: file_type = FieldConfig.exportFormat(filename) except ValueError: sys.stderr.write( "Sorry - could not infer output format from filename:%s\n" % filename) return False self._export(filename, None, file_type, output_transform, init_file) return True def free(self): self._free()
class RNGConfig(BaseCClass): TYPE_NAME = "rng_config" _rng_alg_type = ResPrototype("rng_alg_type_enum rng_config_get_type(rng_config)") _load_file = ResPrototype("char* rng_config_get_seed_load_file(rng_config)") _store_file = ResPrototype("char* rng_config_get_seed_store_file(rng_config)") _random_seed = ResPrototype("char* rng_config_get_random_seed(rng_config)") def __init__(self, user_config_file): raise NotImplementedError( "RNGConfig does not support " "initialization from Python." ) @property def alg_type(self): return self._rng_alg_type() @property def load_filename(self): return self._load_file() @property def store_filename(self): return self._store_file() @property def random_seed(self): return self._random_seed()
class SubstConfig(BaseCClass): TYPE_NAME = "subst_config" _alloc = ResPrototype("void* subst_config_alloc(config_content)", bind=False) _free = ResPrototype("void subst_config_free(subst_config)") _get_subst_list = ResPrototype( "subst_list_ref subst_config_get_subst_list( subst_config )") def __init__(self, config_content): c_ptr = self._alloc(config_content) if c_ptr is None: raise ValueError('Failed to construct RNGConfig instance') super(SubstConfig, self).__init__(c_ptr) def __getitem__(self, key): subst_list = self._get_subst_list() return subst_list[key] def __iter__(self): subst_list = self._get_subst_list() return iter(subst_list) @property def subst_list(self): return self._get_subst_list().setParent(self) def free(self): self._free()
class EnsemblePlotGenKWVector(BaseCClass): TYPE_NAME = "ensemble_plot_gen_kw_vector" _size = ResPrototype( "int enkf_plot_gen_kw_vector_get_size(ensemble_plot_gen_kw_vector)") _get_value = ResPrototype( "double enkf_plot_gen_kw_vector_iget(ensemble_plot_gen_kw_vector, int)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def __len__(self): """@rtype: int""" return self._size() def getValue(self, index): """@rtype: float""" return self[index] def __iter__(self): cur = 0 while cur < len(self): yield self[cur] cur += 1 def __getitem__(self, index): """@rtype: float""" return self._get_value(index) def __repr__(self): return "EnsemblePlotGenKWVector(size = %d) %s" % (len(self), self._ad_str())
class EnsemblePlotDataVector(BaseCClass): TYPE_NAME = "ensemble_plot_data_vector" _size = ResPrototype("int enkf_plot_tvector_size(ensemble_plot_data_vector)") _get_value = ResPrototype( "double enkf_plot_tvector_iget_value(ensemble_plot_data_vector, int)" ) _get_time = ResPrototype( "time_t enkf_plot_tvector_iget_time(ensemble_plot_data_vector, int)" ) _is_active = ResPrototype( "bool enkf_plot_tvector_iget_active(ensemble_plot_data_vector, int)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def __len__(self): """@rtype: int""" return self._size() def getValue(self, index): """@rtype: float""" return self._get_value(index) def getTime(self, index): """@rtype: CTime""" return self._get_time(index) def isActive(self, index): """@rtype: bool""" return self._is_active(index) def __repr__(self): return "EnsemblePlotDataVector(size = %d) %s" % (len(self), self._ad_str())
class ForwardLoadContext(BaseCClass): TYPE_NAME = "forward_load_context" _alloc = ResPrototype( "void* forward_load_context_alloc( run_arg , bool , ecl_config , char* , stringlist )", bind=False) _select_step = ResPrototype( "void forward_load_context_select_step( forward_load_context , int )") _get_step = ResPrototype( "int forward_load_context_get_load_step( forward_load_context)") _free = ResPrototype( "void forward_load_context_free( forward_load_context)") def __init__(self, run_arg=None, load_summary=False, ecl_config=None, ecl_base=None, messages=None, report_step=None): c_ptr = self._alloc(run_arg, load_summary, ecl_config, ecl_base, messages) super(ForwardLoadContext, self).__init__(c_ptr) if not report_step is None: self.selectStep(report_step) def getLoadStep(self): return self._get_step() def selectStep(self, report_step): self._select_step(report_step) def free(self): self._free()
class ErtTemplates(BaseCClass): TYPE_NAME = "ert_templates" _free = ResPrototype("void ert_templates_free( ert_templates )") _alloc_list = ResPrototype( "stringlist_ref ert_templates_alloc_list(ert_templates)") _get_template = ResPrototype( "ert_template_ref ert_templates_get_template(ert_templates, char*)") _clear = ResPrototype("void ert_templates_clear(ert_templates)") _add_template = ResPrototype( "ert_template_ref ert_templates_add_template(ert_templates, char*, char*, char*, char*)" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def getTemplateNames(self): """ @rtype: StringList """ return self._alloc_list().setParent(self) def clear(self): self._clear() def get_template(self, key): """ @rtype: ErtTemplate """ return self._get_template(key).setParent(self) def add_template(self, key, template_file, target_file, arg_string): """ @rtype: ErtTemplate """ return self._add_template(key, template_file, target_file, arg_string).setParent(self) def free(self): self._free()
class ConfigError(BaseCClass): TYPE_NAME = "config_error" _free = ResPrototype("void config_error_free(config_error)") _count = ResPrototype("int config_error_count(config_error)") _iget = ResPrototype("char* config_error_iget(config_error, int)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def __getitem__(self, index): """@rtype: str""" if not isinstance(index, int): raise TypeError("Expected an integer") size = len(self) if index >= size: raise IndexError("Index out of range: %d < %d" % (index, size)) return self._iget(index) def __len__(self): """@rtype: int""" return self._count() def free(self): self._free()
def __init__(self, ert, function_name, argument_types, argument_count): super().__init__(ert) parsed_argument_types = [] if ert is not None: self.__function = ResPrototype("void* %s(void*, stringlist)" % function_name) else: for arg in argument_types: if arg is bool: parsed_argument_types.append("bool") elif arg is str: parsed_argument_types.append("char*") elif arg is int: parsed_argument_types.append("int") elif arg is float: parsed_argument_types.append("float") else: raise TypeError("Unknown type: %s" % arg) self.__function = ResPrototype( "void* %s(%s)" % (function_name, ", ".join( parsed_argument_types[:argument_count])))
class HookWorkflow(BaseCClass): TYPE_NAME = "hook_workflow" _get_workflow = ResPrototype( "workflow_ref hook_workflow_get_workflow(hook_workflow)") _get_runmode = ResPrototype( "hook_runtime_enum hook_workflow_get_run_mode(hook_workflow)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def getWorkflow(self) -> Workflow: """@rtype: Workflow""" return self._get_workflow() def getRunMode(self) -> HookRuntime: return self._get_runmode() def __eq__(self, other): return (self.getRunMode() == other.getRunMode() and self.getWorkflow().src_file == other.getWorkflow().src_file) def __ne__(self, other): return not self == other def __repr__(self): return "HookWorkflow({}, {})".format(self.getWorkflow().src_file, self.getRunMode())
class HookManager(BaseCClass): TYPE_NAME = "hook_manager" _get_runpath_list_file = ResPrototype( "char* hook_manager_get_runpath_list_file(hook_manager)") _get_runpath_list = ResPrototype( "runpath_list_ref hook_manager_get_runpath_list(hook_manager)") _iget_hook_workflow = ResPrototype( "hook_workflow_ref hook_manager_iget_hook_workflow(hook_manager, int)") _size = ResPrototype("int hook_manager_get_size(hook_manager)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def __len__(self): """ @rtype: int """ return self._size() def __repr__(self): return 'HookManager(size = %d) %s' % (len(self), self._ad_str()) def __getitem__(self, index): """ @rtype: Hook workflow """ assert isinstance(index, int) if index < 0: index += len(self) if 0 <= index < len(self): return self._iget_hook_workflow(index) else: raise IndexError("Invalid index. Valid range: [0, %d)." % len(self)) def checkRunpathListFile(self): """ @rtype: bool """ runpath_list_file = self._get_runpath_list_file() if not os.path.exists(runpath_list_file): sys.stderr.write( "** Warning: the file: %s with a list of runpath directories was not found - hook workflow will probably fail.\n" % runpath_list_file) def getRunpathList(self): """ @rtype: RunpathList """ return self._get_runpath_list() def runWorkflows(self, run_time, ert_self): workflow_list = ert_self.getWorkflowList() for hook_workflow in self: if (hook_workflow.getRunMode() is not run_time): continue workflow = hook_workflow.getWorkflow() workflow.run(ert_self, context=workflow_list.getContext())
class EnsemblePlotData(BaseCClass): TYPE_NAME = "ensemble_plot_data" _alloc = ResPrototype("void* enkf_plot_data_alloc(enkf_config_node)", bind=False) _load = ResPrototype( "void enkf_plot_data_load(ensemble_plot_data, enkf_fs, char*, bool_vector)" ) _size = ResPrototype("int enkf_plot_data_get_size(ensemble_plot_data)") _get = ResPrototype( "ensemble_plot_data_vector_ref enkf_plot_data_iget(ensemble_plot_data, int)" ) _free = ResPrototype("void enkf_plot_data_free(ensemble_plot_data)") def __init__(self, ensemble_config_node, file_system=None, user_index=None, input_mask=None): assert isinstance(ensemble_config_node, EnkfConfigNode) c_pointer = self._alloc(ensemble_config_node) super().__init__(c_pointer) if file_system is not None: self.load(file_system, user_index, input_mask) def load(self, file_system, user_index=None, input_mask=None): assert isinstance(file_system, EnkfFs) if input_mask is not None: assert isinstance(input_mask, BoolVector) self._load(file_system, user_index, input_mask) def __len__(self): """@rtype: int""" return self._size() def __getitem__(self, index) -> EnsemblePlotDataVector: """@rtype: EnsemblePlotDataVector""" return self._get(index) def __iter__(self): cur = 0 while cur < len(self): yield self[cur] cur += 1 def free(self): self._free() def __repr__(self): return "EnsemblePlotData(size = %d) %s" % (len(self), self._ad_str())
class History(BaseCClass): TYPE_NAME = "history" _alloc_from_refcase = ResPrototype( "void* history_alloc_from_refcase(ecl_sum, bool)", bind=False) _alloc_from_sched_file = ResPrototype( "void* history_alloc_from_sched_file(char*, sched_file)", bind=False) _get_source_string = ResPrototype( "char* history_get_source_string(history_source_enum)", bind=False) _free = ResPrototype("void history_free( history )") # _history_get_source_type = ResPrototype("history_source_type_enum history_get_source_type(char*)", bind = False) def __init__(self, refcase=None, use_history=False, sched_file=None): """ @type refcase: EclSum @type use_history: bool @rtype: HistoryType """ self._init_from = '' self._init_val = '' if sched_file is not None: self._init_from = 'sched_file' self._init_val = str(sched_file) c_ptr = self._alloc_from_sched_file(sched_file, use_history) else: self._init_from = 'refcase' self._init_val = str(refcase) c_ptr = self._alloc_from_refcase(refcase, use_history) if c_ptr: super(History, self).__init__(c_ptr) else: if sched_file is None and refcase is None: raise ArgumentError( 'Need to specify either sched_file or refcase.') raise ValueError('Invalid input. Failed to create History.') @staticmethod def get_source_string(history_source_type): """ @type history_source_type: HistorySourceEnum @rtype: str """ return self._get_source_string(history_source_type) def free(self): self._free(self) def __repr__(self): fr = self._init_from va = self._init_val ad = self._ad_str() return 'History(init_from = %s: %s) %s' % (fr, va, ad)
class RNGConfig(BaseCClass): TYPE_NAME = "rng_config" _alloc = ResPrototype("void* rng_config_alloc(config_content)", bind=False) _alloc_full = ResPrototype("void* rng_config_alloc_full(char*)", bind=False) _free = ResPrototype("void rng_config_free(rng_config)") _rng_alg_type = ResPrototype( "rng_alg_type_enum rng_config_get_type(rng_config)") _random_seed = ResPrototype("char* rng_config_get_random_seed(rng_config)") def __init__(self, config_content=None, config_dict=None): if config_content and config_dict: raise ValueError( "RNGConfig can not be instantiated with both config types") if not (config_content or config_dict): raise ValueError( "RNGConfig can not be instantiated without any config objects") if config_content: c_ptr = self._alloc(config_content) elif config_dict: random_seed = config_dict.get(ConfigKeys.RANDOM_SEED) c_ptr = self._alloc_full(random_seed) else: c_ptr = None if c_ptr is None: raise ValueError("Failed to construct RNGConfig instance") super(RNGConfig, self).__init__(c_ptr) @property def alg_type(self): return self._rng_alg_type() @property def random_seed(self): return self._random_seed() def free(self): self._free() def __eq__(self, other): if self.random_seed != other.random_seed: return False if self.alg_type != other.alg_type: return False return True
class EnKFState(BaseCClass): TYPE_NAME = "enkf_state" _free = ResPrototype("void enkf_state_free( enkf_state )") _get_ens_config = ResPrototype( "ens_config_ref enkf_state_get_ensemble_config( enkf_state )" ) _initialize = ResPrototype( "void enkf_state_initialize" "( enkf_state , enkf_fs , stringlist , enkf_init_mode_enum)" ) _forward_model_OK = ResPrototype( "bool enkf_state_complete_forward_modelOK(res_config, run_arg)", bind=False ) _forward_model_EXIT = ResPrototype( "bool enkf_state_complete_forward_model_EXIT_handler__(run_arg)", bind=False ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def free(self): self._free() def ensembleConfig(self): """@rtype: EnsembleConfig""" return self._get_ens_config() def initialize( self, fs: EnkfFs, param_list: Optional[StringList] = None, init_mode=EnkfInitModeEnum.INIT_CONDITIONAL, ): if param_list is None: ens_config = self.ensembleConfig() param_list = ens_config.getKeylistFromVarType(EnkfVarType.PARAMETER) self._initialize(fs, StringList(param_list), init_mode) @classmethod def forward_model_exit_callback(cls, args): if not isinstance(args[0], RunArg): raise ValueError("Expected RunArg as second argument") return cls._forward_model_EXIT(args[0]) @classmethod def forward_model_ok_callback(cls, args): if not isinstance(args[1], ResConfig): raise ValueError("Expected ResConfig as second argument") if not isinstance(args[0], RunArg): raise ValueError("Expected RunArg as second argument") return cls._forward_model_OK(args[1], args[0])
class CThreadPool(BaseCClass): TYPE_NAME = "thread_pool" _alloc = ResPrototype("void* thread_pool_alloc(int, bool)", bind=False) _free = ResPrototype("void thread_pool_free(thread_pool)") _add_job = ResPrototype( "void thread_pool_add_job(thread_pool, void*, void*)") _join = ResPrototype("void thread_pool_join(thread_pool)") def __init__(self, pool_size, start=True): c_ptr = self._alloc(pool_size, start) super(CThreadPool, self).__init__(c_ptr) self.arg_list = [] def addTaskFunction(self, name, lib, c_function_name): function = CThreadPool.lookupCFunction(lib, c_function_name) self_ref = weakref.ref(self) # avoid circular dependencies def wrappedFunction(arg): return self_ref().addTask(function, arg) setattr(self, name, wrappedFunction) def addTask(self, cfunc, arg): """ The function should come from CThreadPool.lookupCFunction(). """ if isinstance(arg, BaseCClass): arg_ptr = BaseCClass.from_param(arg) else: arg_ptr = arg self.arg_list.append(arg) self._add_job(cfunc, arg_ptr) def join(self): self._join() def free(self): self.join() self._free() @staticmethod def lookupCFunction(lib, name): if isinstance(lib, ctypes.CDLL): func = getattr(lib, name) return func else: raise TypeError("The lib argument must be of type ctypes.CDLL")
class Summary(BaseCClass): TYPE_NAME = "summary" _alloc = ResPrototype("void* summary_alloc(summary_config)", bind = False) _free = ResPrototype("void summary_free(summary)") _iget_value = ResPrototype("double summary_get(summary, int)") _length = ResPrototype("int summary_length(summary)") def __init__(self, config): c_ptr = self._alloc(config) self._config = config super(Summary, self).__init__(c_ptr) def __len__(self): return self._length() def __repr__(self): return "Summary(key=%s, length=%d) %s" % (self.key, len(self), self._ad_str()) def __getitem__(self, index): if index < 0: index += len(self) if index < 0: raise ValueError("Invalid index") if index >= len(self): raise IndexError("Invalid index:%d Valid range: [0,%d>" % (index, len(self))) return self._iget_value(index) def value(self, report_step): return self[report_step] @property def config(self): return self._config @property def key(self): return self.config.key def free(self): self._free()
class ErtTemplate(BaseCClass): TYPE_NAME = "ert_template" _free = ResPrototype("void ert_template_free( ert_template )") _get_template_file = ResPrototype( "char* ert_template_get_template_file(ert_template)" ) _get_target_file = ResPrototype("char* ert_template_get_target_file(ert_template)") _get_arg_list = ResPrototype( "subst_list_ref ert_template_get_arg_list( ert_template )" ) def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def get_template_file(self): """@rtype: str""" return self._get_template_file() def get_target_file(self): """@rtype: str""" return self._get_target_file() def get_args_as_string(self): """@rtype: str""" args_list = self._get_arg_list() return ", ".join( ["{}={}".format(key, args_list.get(key)) for key in args_list.keys()] ) def __eq__(self, other): return ( self.get_template_file() == other.get_template_file() and self.get_target_file() == other.get_target_file() and self.get_args_as_string() == other.get_args_as_string() ) def __ne__(self, other): return not self == other def __repr__(self): return "ErtTemplate({}, {}, {})".format( self.get_template_file(), self.get_target_file(), self.get_args_as_string() ) def free(self): self._free()
class ForwardModel(BaseCClass): TYPE_NAME = "forward_model" _alloc = ResPrototype("void* forward_model_alloc(ext_joblist)", bind=False) _free = ResPrototype("void forward_model_free( forward_model )") _clear = ResPrototype("void forward_model_clear(forward_model)") _add_job = ResPrototype( "ext_job_ref forward_model_add_job(forward_model, char*)") _alloc_joblist = ResPrototype( "stringlist_obj forward_model_alloc_joblist(forward_model)") _iget_job = ResPrototype( "ext_job_ref forward_model_iget_job( forward_model, int)") _get_length = ResPrototype("int forward_model_get_length(forward_model)") _formatted_fprintf = ResPrototype( "void forward_model_formatted_fprintf(forward_model, char*, char*, char*, subst_list, int, env_varlist)" ) def __init__(self, ext_joblist): c_ptr = self._alloc(ext_joblist) if c_ptr: super(ForwardModel, self).__init__(c_ptr) else: raise ValueError( 'Failed to construct forward model from provided ext_joblist %s' % ext_joblist) def __len__(self): return self._get_length() def joblist(self): """ @rtype: StringList """ return self._alloc_joblist() def iget_job(self, index): """ @rtype: ExtJob """ return self._iget_job(index).setParent(self) def add_job(self, name): """ @rtype: ExtJob """ return self._add_job(name).setParent(self) def clear(self): self._clear() def free(self): self._free() def formatted_fprintf(self, run_id, path, data_root, global_args, umask, env_varlist): self._formatted_fprintf(run_id, path, data_root, global_args, umask, env_varlist) def __repr__(self): return self._create_repr('joblist=%s' % self.joblist()) def get_size(self): return len(self)
class SummaryKeySet(BaseCClass): TYPE_NAME = "summary_key_set" _alloc = ResPrototype("void* summary_key_set_alloc()", bind=False) _alloc_from_file = ResPrototype( "void* summary_key_set_alloc_from_file(char*, bool)", bind=False ) _free = ResPrototype("void summary_key_set_free(summary_key_set)") _size = ResPrototype("int summary_key_set_get_size(summary_key_set)") _add_key = ResPrototype( "bool summary_key_set_add_summary_key(summary_key_set, char*)" ) _has_key = ResPrototype( "bool summary_key_set_has_summary_key(summary_key_set, char*)" ) _keys = ResPrototype("stringlist_obj summary_key_set_alloc_keys(summary_key_set)") _is_read_only = ResPrototype("bool summary_key_set_is_read_only(summary_key_set)") _fwrite = ResPrototype("void summary_key_set_fwrite(summary_key_set, char*)") def __init__(self, filename=None, read_only=False): if filename is None: c_ptr = self._alloc() else: c_ptr = self._alloc_from_file(filename, read_only) super().__init__(c_ptr) def addSummaryKey(self, key): assert isinstance(key, str) return self._add_key(key) def __len__(self): return self._size() def __contains__(self, key): return self._has_key(key) def keys(self) -> StringList: """@rtype: StringList""" return self._keys() def isReadOnly(self): """@rtype: bool""" return self._is_read_only() def writeToFile(self, filename): assert isinstance(filename, str) self._fwrite(filename) def free(self): self._free()
class RunArg(BaseCClass): TYPE_NAME = "run_arg" _alloc_ENSEMBLE_EXPERIMENT = ResPrototype("run_arg_obj run_arg_alloc_ENSEMBLE_EXPERIMENT(char*, enkf_fs, int, int, char*, char*, subst_list)", bind = False) _free = ResPrototype("void run_arg_free(run_arg)") _get_queue_index_safe = ResPrototype("int run_arg_get_queue_index_safe(run_arg)") _is_submitted = ResPrototype("bool run_arg_is_submitted(run_arg)") _get_run_id = ResPrototype("char* run_arg_get_run_id(run_arg)") _get_geo_id = ResPrototype("int run_arg_get_geo_id(run_arg)") _set_geo_id = ResPrototype("void run_arg_set_geo_id(run_arg, int)") _get_runpath = ResPrototype("char* run_arg_get_runpath(run_arg)") def __init__(self): raise NotImplementedError("Cannot instantiat RunArg directly!") @classmethod def createEnsembleExperimentRunArg(cls, run_id, fs, iens, runpath, jobname, subst_list, iter=0): return cls._alloc_ENSEMBLE_EXPERIMENT(run_id, fs, iens, iter, runpath, jobname, subst_list) def free(self): self._free() def getQueueIndex(self): qi = self._get_queue_index_safe() if qi < 0: raise ValueError('Cannot get queue index before job is submitted.') return qi def isSubmitted(self): return self._is_submitted() def __repr__(self): if self.isSubmitted(): su = 'submitted' qi = self.getQueueIndex() else: su = "not submitted" qi = "--" return 'RunArg(queue_index = %s, %s) %s' % (qi, su, self._ad_str()) def get_run_id(self): return self._get_run_id( ) @property def geo_id(self): return self._get_geo_id() @geo_id.setter def geo_id(self, value): self._set_geo_id(value) @property def runpath(self): return self._get_runpath()
class HookWorkflow(BaseCClass): TYPE_NAME = "hook_workflow" _get_workflow = ResPrototype( "workflow_ref hook_workflow_get_workflow(hook_workflow)") _get_runmode = ResPrototype( "hook_runtime_enum hook_workflow_get_run_mode(hook_workflow)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def getWorkflow(self): """ @rtype: Workflow """ return self._get_workflow() def getRunMode(self): return self._get_runmode()
class Log(BaseCClass): _get_filename = ResPrototype("char* log_get_filename(log)") _get_level = ResPrototype("message_level_enum log_get_level(log)") _set_level = ResPrototype("void log_set_level(log, message_level_enum)") def __init__(self): raise NotImplementedError("Class can not be instantiated directly!") def get_filename(self): return self._get_filename() # return "ert_config.log" def get_level(self): return self._get_level() def set_level(self, level): self._set_level(self, level)
class LocalUpdateStep(BaseCClass): TYPE_NAME = "local_updatestep" _size = ResPrototype( "int local_updatestep_get_num_ministep(local_updatestep)") _iget_ministep = ResPrototype( "local_ministep_ref local_updatestep_iget_ministep(local_updatestep, int)" ) _free = ResPrototype("void local_updatestep_free(local_updatestep)") _attach_ministep = ResPrototype( "void local_updatestep_add_ministep(local_updatestep, local_ministep)" ) _name = ResPrototype("char* local_updatestep_get_name(local_updatestep)") def __init__(self, updatestep_key): raise NotImplementedError("Class can not be instantiated directly!") def __len__(self): """@rtype: int""" return self._size() def __getitem__(self, index): """@rtype: LocalMinistep""" if not isinstance(index, int): raise TypeError("Keys must be ints, not %s" % str(type(index))) if index < 0: index += len(self) if 0 <= index < len(self): return self._iget_ministep(index) else: raise IndexError("Invalid index, valid range: [0, %d)" % len(self)) def attachMinistep(self, ministep): assert isinstance(ministep, LocalMinistep) self._attach_ministep(ministep) def name(self): return self._name() def getName(self): """@rtype: str""" return self.name() def free(self): self._free(self)
class History(BaseCClass): TYPE_NAME = "history" _alloc_from_refcase = ResPrototype( "void* history_alloc_from_refcase(ecl_sum, bool)", bind=False) _get_source_string = ResPrototype( "char* history_get_source_string(history_source_enum)", bind=False) _free = ResPrototype("void history_free( history )") def __init__(self, refcase=None, use_history=False, sched_file=None): """ @type refcase: EclSum @type use_history: bool @rtype: HistoryType """ if sched_file is not None: raise ValueError("Cannot create history from sched_file.") if refcase is None: ValueError("Refcase cannot be None when creating a History.") self._init_from = "refcase" self._init_val = str(refcase) c_ptr = self._alloc_from_refcase(refcase, use_history) if c_ptr: super(History, self).__init__(c_ptr) else: raise ValueError("Invalid input. Failed to create History.") @staticmethod def get_source_string(history_source_type): """ @type history_source_type: HistorySourceEnum @rtype: str """ return History._get_source_string(history_source_type) def free(self): self._free(self) def __repr__(self): fr = self._init_from va = self._init_val ad = self._ad_str() return "History(init_from = %s: %s) %s" % (fr, va, ad)
class Log(BaseCClass): _open_log = ResPrototype("void* log_open_file(char*, message_level_enum)", bind=False) _get_filename = ResPrototype("char* log_get_filename(log)") _set_level = ResPrototype("void log_set_level(log, message_level_enum)") def __init__(self, log_filename, log_level): c_ptr = self._open_log(log_filename, log_level) if c_ptr: super(Log, self).__init__(c_ptr) else: raise IOError("Failed to open log handle at:%s" % log_filename) def get_filename(self): return self._get_filename() def set_level(self, level): self._set_level(self, level)