from types import MethodType
from logging import debug
from ...utils.check.errclass import PluginError
from .baseclass import Plugin
[docs]class Model(Plugin):
def __init__(self, **kwargs):
"""Create a Model Class"""
super(Model, self).__init__(**kwargs)
self.requirements.update({"domain": {"any": True, "empty": True}})
# Default attributes
self.required_inputs = []
self.autoflush = False # Cleans big files at the end of simulation
# Empty backup comps
self.backup_comps = {}
[docs] def initiate_template(self):
default_functions = [
"run", "make_auxiliary", "make_input", "flushrun", "ini_periods",
"native2inputs", "outputs2native",
"native2inputs_adj", "outputs2native_adj",
"compile", "ini_mapper", "perturb_model"
]
super(Model, self).initiate_template(
plg_type="model",
default_functions={k: True for k in default_functions}
)
# Force initializing periods in ini_data
if hasattr(self, "ini_data"):
self.ini_data_orig = self.ini_data
def ini_data(self, **kwargs):
self.ini_data_orig(**kwargs)
self.ini_periods(**kwargs)
self.ini_data = MethodType(ini_data, self)
[docs] def run(self, *args, **kwargs):
"""Default empty run method"""
raise PluginError("This is the default empty run method")
[docs] def make_auxiliary(self, *args, **kwargs):
"""Default empty make_auxiliary method"""
debug("This is the default empty make_auxiliary method")
return
[docs] def outputs2native(self, *args, **kwargs):
"""Default empty outputs2native method"""
raise PluginError("This is the default empty outputs2native method")
[docs] def outputs2native_adj(self, *args, **kwargs):
"""Default empty outputs2native_adj method"""
raise PluginError("This is the default empty outputs2native_adj method")
[docs] def flushrun(self, *args, **kwargs):
"""Default empty flushrun method"""
raise PluginError("This is the default empty flushrun method")
[docs] def ini_periods(self, *args, **kwargs):
"""Default empty ini_periods method"""
raise PluginError("This is the default empty ini_periods method")
[docs] def perturb_model(self, *args, **kwargs):
"""Default empty perturb_model method"""
raise PluginError("This is the default empty perturb_model method")
[docs] @classmethod
def register_plugin(cls, name, version, module, subtype="", **kwargs):
"""Register a module for a plugin and version with possibly options
Args:
name (str): name of the plugin
version (str): version of the plugin
module (types.ModuleType): module defining the interface
between pyCIF and the plugin
plugin_type (str): type of plugin
**kwargs (dictionary): default options for module
"""
super(Model, cls).register_plugin(
name, version, module, plugin_type="model", subtype=subtype
)
[docs] def ini_mapper(self, *args, **kwargs):
"""Default empty ini_mapper method"""
raise PluginError("This is the default empty ini_mapper method")