Commit c4a8ae8b authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

restructuring ...

parent de113af3
...@@ -6,15 +6,15 @@ from ..targets import TargetAnalysisResult ...@@ -6,15 +6,15 @@ from ..targets import TargetAnalysisResult
from ..meta import Forbidden from ..meta import Forbidden
guts_prefix = 'grond'
class Analyser(object): class Analyser(object):
def __init__(self, niter): def __init__(self, niter):
self.niter = niter self.niter = niter
def set_notifier(self, notifier): def analyse(self, problem, notifier):
self.notifier = notifier
def analyse(self, problem):
if self.niter == 0: if self.niter == 0:
return return
...@@ -37,7 +37,7 @@ class Analyser(object): ...@@ -37,7 +37,7 @@ class Analyser(object):
mss = num.zeros((self.niter, wproblem.ntargets)) mss = num.zeros((self.niter, wproblem.ntargets))
rstate = num.random.RandomState(123) rstate = num.random.RandomState(123)
self.notifier.emit('progress_start', 'analysing problem', self.niter) notifier.emit('progress_start', 'analysing problem', self.niter)
isbad_mask = None isbad_mask = None
for iiter in xrange(self.niter): for iiter in xrange(self.niter):
...@@ -62,9 +62,9 @@ class Analyser(object): ...@@ -62,9 +62,9 @@ class Analyser(object):
mss[iiter, :] = ms mss[iiter, :] = ms
isbad_mask = num.isnan(ms) isbad_mask = num.isnan(ms)
self.notifier.emit('progress_update', 'analysing problem', iiter) notifier.emit('progress_update', 'analysing problem', iiter)
self.notifier.emit('progress_finish', 'analysing problem') notifier.emit('progress_finish', 'analysing problem')
mean_ms = num.mean(mss, axis=0) mean_ms = num.mean(mss, axis=0)
weights = 1. / mean_ms weights = 1. / mean_ms
......
...@@ -16,7 +16,7 @@ from .problems.base import ProblemConfig, Problem ...@@ -16,7 +16,7 @@ from .problems.base import ProblemConfig, Problem
from .solvers.base import SolverConfig from .solvers.base import SolverConfig
from .analysers.base import AnalyserConfig from .analysers.base import AnalyserConfig
from .targets import TargetConfig from .targets import TargetConfig
from .meta import Path, HasPaths, expand_template, xjoin, GrondError from .meta import Path, HasPaths, expand_template, xjoin, GrondError, Notifier
logger = logging.getLogger('grond.core') logger = logging.getLogger('grond.core')
guts_prefix = 'grond' guts_prefix = 'grond'
...@@ -703,8 +703,10 @@ def process_event(ievent, g_data_id): ...@@ -703,8 +703,10 @@ def process_event(ievent, g_data_id):
logger.info( logger.info(
'start %i / %i' % (ievent+1, nevents)) 'start %i / %i' % (ievent+1, nevents))
solver = config.solver_config.get_solver() notifier = Notifier()
solver.analyse(problem)
analyser = config.analyser_config.get_analyser()
analyser.analyse(problem, notifier=notifier)
basepath = config.get_basepath() basepath = config.get_basepath()
config.change_basepath(rundir) config.change_basepath(rundir)
...@@ -726,11 +728,14 @@ def process_event(ievent, g_data_id): ...@@ -726,11 +728,14 @@ def process_event(ievent, g_data_id):
# update_every=10, # update_every=10,
# movie_filename='grond_opt_time_magnitude.mp4') # movie_filename='grond_opt_time_magnitude.mp4')
solver.solve(problem, solver = config.solver_config.get_solver()
rundir=rundir, solver.solve(
status=status, problem,
xs_inject=xs_inject) rundir=rundir,
# plot=splot, status=status,
# plot=splot,
xs_inject=xs_inject,
notifier=notifier)
harvest(rundir, problem, force=True) harvest(rundir, problem, force=True)
......
...@@ -68,7 +68,8 @@ def solve(problem, ...@@ -68,7 +68,8 @@ def solve(problem,
compensate_excentricity=True, compensate_excentricity=True,
xs_inject=None, xs_inject=None,
status=(), status=(),
plot=None): plot=None,
notifier=None):
xbounds = num.array(problem.get_parameter_bounds(), dtype=num.float) xbounds = num.array(problem.get_parameter_bounds(), dtype=num.float)
npar = problem.nparameters npar = problem.nparameters
...@@ -417,12 +418,13 @@ def solve(problem, ...@@ -417,12 +418,13 @@ def solve(problem,
class HighScoreSolver(Solver): class HighScoreSolver(Solver):
def __init__(self, analyser, kwargs): def __init__(self, kwargs):
Solver.__init__(self, analyser) Solver.__init__(self)
self._kwargs = kwargs self._kwargs = kwargs
def solve( def solve(
self, problem, rundir=None, status=(), plot=None, xs_inject=None): self, problem, rundir=None, status=(), plot=None, xs_inject=None,
notifier=None):
solve( solve(
problem, problem,
...@@ -430,7 +432,8 @@ class HighScoreSolver(Solver): ...@@ -430,7 +432,8 @@ class HighScoreSolver(Solver):
status=status, status=status,
plot=plot, plot=plot,
xs_inject=xs_inject, xs_inject=xs_inject,
**self.kwargs) notifier=notifier,
**self._kwargs)
class SamplerDistributionChoice(StringChoice): class SamplerDistributionChoice(StringChoice):
...@@ -472,7 +475,7 @@ class HighScoreSolverConfig(SolverConfig): ...@@ -472,7 +475,7 @@ class HighScoreSolverConfig(SolverConfig):
compensate_excentricity=self.compensate_excentricity) compensate_excentricity=self.compensate_excentricity)
def get_solver(self): def get_solver(self):
return HighScoreSolver(self.get_analyser(), self.get_solver_kwargs()) return HighScoreSolver(self.get_solver_kwargs())
__all__ = ''' __all__ = '''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment