1import logging
3from pyrocko.guts import Object
4from grond.meta import GrondError, has_get_plot_classes
6guts_prefix = 'grond'
8logger = logging.getLogger('grond.optimisers.base')
11class BadProblem(GrondError):
12 pass
15@has_get_plot_classes
16class Optimiser(Object):
18 def __init__(self, **kwargs):
19 Object.__init__(self, **kwargs)
20 self._nthreads = 1
22 def set_nthreads(self, nthreads):
23 logger.debug('Setting nthreads to %d', nthreads)
24 self._nthreads = nthreads
26 def optimise(self, problem):
27 raise NotImplementedError
29 @property
30 def niterations(self):
31 raise NotImplementedError
33 def get_status(self, history):
34 pass
36 def init_bootstraps(self, problem):
37 raise NotImplementedError
39 @classmethod
40 def get_plot_classes(cls):
41 from . import plot
42 return plot.get_plot_classes()
45class OptimiserConfig(Object):
46 pass
49class OptimiserStatus(object):
50 __slots__ = ['row_names', 'column_data', 'extra_header', 'extra_footer']
52 def __init__(self, row_names, column_data,
53 extra_header=None, extra_footer=None):
54 self.row_names = row_names
55 self.column_data = column_data
56 self.extra_header = extra_header
57 self.extra_footer = extra_footer
59 @property
60 def column_names(self):
61 return self.column_data.keys()
63 @property
64 def ncolumns(self):
65 return len(self.column_data)
67 @property
68 def values(self):
69 return self.column_data.values()
72__all__ = '''
73 BadProblem
74 Optimiser
75 OptimiserConfig
76'''.split()