Source code for pycif.utils.classes.minimizers
from types import MethodType
from ...utils.check.errclass import PluginError
from .baseclass import Plugin
[docs]
class Minimizer(Plugin):
"""Plugin type for minimisation algorithms used in variational inversion.
Drives the iterative optimisation loop (e.g. L-BFGS-B, CG) that minimises
the cost function with respect to the control vector.
Concrete implementations live in ``pycif/plugins/minimizers/``.
"""
[docs]
def initiate_template(self):
"""Initialise the Minimizer plugin template.
Loads the registered minimizer module and attaches ``minimize`` as a
bound method on this instance.
"""
super(Minimizer, self).initiate_template(
plg_type="minimizer",
default_functions={"minimize": True}
)
[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(Minimizer, cls).register_plugin(
name, version, module, plugin_type="minimizer", subtype=subtype
)
[docs]
def minimize(self, *args, **kwargs):
"""Run the minimisation algorithm. Must be overridden.
Raises:
PluginError: Always, in this default implementation.
"""
raise PluginError("The function minimize was not defined")