def __init__(self, conf, problem, **kwargs): NonlinearSolver.__init__(self, conf, **kwargs) conf = self.conf log = get_logging_conf(conf) conf.log = log = Struct(name='log_conf', **log) conf.is_any_log = (log.text is not None) or (log.plot is not None) conf.problem = problem conf = self.conf if conf.is_any_log: self.log = Log([[r'$||r||$'], ['iteration'], [r'$\gamma$', r'$\max(\delta)$', r'$\max(\tau)$']], xlabels=['', '', 'all iterations'], ylabels=[r'$||r||$', 'iteration', 'stabilization'], yscales=['log', 'linear', 'log'], is_plot=conf.log.plot is not None, log_filename=conf.log.text, formats=[['%.8e'], ['%d'], ['%.8e', '%.8e', '%.8e']]) else: self.log = None
def __init__(self, conf, context=None, **kwargs): NonlinearSolver.__init__(self, conf, context=context, **kwargs) conf = self.conf log = get_logging_conf(conf) conf.log = log = Struct(name='log_conf', **log) conf.is_any_log = (log.text is not None) or (log.plot is not None) conf.problem = context conf = self.conf if conf.is_any_log: self.log = Log([[r'$||r||$'], ['iteration'], [r'$\gamma$', r'$\max(\delta)$', r'$\max(\tau)$']], xlabels=['', '', 'all iterations'], ylabels=[r'$||r||$', 'iteration', 'stabilization'], yscales=['log', 'linear', 'log'], is_plot=conf.log.plot is not None, log_filename=conf.log.text, formats=[['%.8e'], ['%d'], ['%.8e', '%.8e', '%.8e']]) else: self.log = None
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_1 = { 'name' : 'oseen', 'kind' : 'nls.oseen', 'needs_problem_instance' : True, 'stabil_mat' : 'stabil', 'adimensionalize' : False, 'check_navier_stokes_rezidual' : False, 'i_max' : 10, 'eps_a' : 1e-8, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'log' : {'text' : 'oseen_log.txt', 'plot' : 'oseen_log.png'}, } """ get = make_get_conf(conf, kwargs) common = NonlinearSolver.process_conf(conf) # Compulsory. needs_problem_instance = get('needs_problem_instance', True) if not needs_problem_instance: msg = 'set solver option "needs_problem_instance" to True!' raise ValueError(msg) stabil_mat = get('stabil_mat', None, 'missing "stabil_mat" in options!') # With defaults. adimensionalize = get('adimensionalize', False) if adimensionalize: raise NotImplementedError check = get('check_navier_stokes_rezidual', False) log = get_logging_conf(conf) log = Struct(name='log_conf', **log) is_any_log = (log.text is not None) or (log.plot is not None) return Struct(needs_problem_instance=needs_problem_instance, stabil_mat=stabil_mat, adimensionalize=adimensionalize, check_navier_stokes_rezidual=check, i_max=get('i_max', 1), eps_a=get('eps_a', 1e-10), eps_r=get('eps_r', 1.0), macheps=get('macheps', nm.finfo(nm.float64).eps), lin_red=get('lin_red', 1.0), lin_precision=get('lin_precision', None), log=log, is_any_log=is_any_log) + common
def process_conf(conf, kwargs): """ Missing items are set to default values for a linear problem. Example configuration, all items:: solver_1 = { 'name' : 'newton', 'kind' : 'nls.newton', 'i_max' : 2, 'eps_a' : 1e-8, 'eps_r' : 1e-2, 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'lin_precision' : None, 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'give_up_warp' : False, 'check' : 0, 'delta' : 1e-6, 'is_plot' : False, 'log' : None, # 'nonlinear' or 'linear' (ignore i_max) 'problem' : 'nonlinear', } """ get = make_get_conf(conf, kwargs) common = NonlinearSolver.process_conf(conf) log = get_logging_conf(conf) log = Struct(name="log_conf", **log) is_any_log = (log.text is not None) or (log.plot is not None) return ( Struct( i_max=get("i_max", 1), eps_a=get("eps_a", 1e-10), eps_r=get("eps_r", 1.0), macheps=get("macheps", nm.finfo(nm.float64).eps), lin_red=get("lin_red", 1.0), lin_precision=get("lin_precision", None), ls_red=get("ls_red", 0.1), ls_red_warp=get("ls_red_warp", 0.001), ls_on=get("ls_on", 0.99999), ls_min=get("ls_min", 1e-5), give_up_warp=get("give_up_warp", False), check=get("check", 0), delta=get("delta", 1e-6), is_plot=get("is_plot", False), problem=get("problem", "nonlinear"), log=log, is_any_log=is_any_log, ) + common )
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_0 = { 'name' : 'fmin_sd', 'kind' : 'opt.fmin_sd', 'i_max' : 10, 'eps_rd' : 1e-5, # Relative delta of objective function 'eps_of' : 1e-4, 'eps_ofg' : 1e-8, 'norm' : nm.Inf, 'ls' : True, # Linesearch. 'ls_method' : 'backtracking', # 'backtracking' or 'full' 'ls0' : 0.25, 'ls_red' : 0.5, 'ls_red_warp' : 0.1, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6, 'output' : None, # 'itc' 'log' : {'text' : 'output/log.txt', 'plot' : 'output/log.png'}, 'yscales' : ['linear', 'log', 'log', 'linear'], } """ get = make_get_conf(conf, kwargs) common = OptimizationSolver.process_conf(conf) log = get_logging_conf(conf) log = Struct(name='log_conf', **log) is_any_log = (log.text is not None) or (log.plot is not None) return Struct(i_max=get('i_max', 10), eps_rd=get('eps_rd', 1e-5), eps_of=get('eps_of', 1e-4), eps_ofg=get('eps_ofg', 1e-8), norm=get('norm', nm.Inf), ls=get('ls', True), ls_method=get('ls_method', 'backtracking'), ls0=get('ls0', 0.25), ls_red=get('ls_red', 0.5), ls_red_warp=get('ls_red_warp', 0.1), ls_on=get('ls_on', 0.99999), ls_min=get('ls_min', 1e-5), check=get('check', 0), delta=get('delta', 1e-6), output=get('output', None), yscales=get('yscales', ['linear', 'log', 'log', 'linear']), log=log, is_any_log=is_any_log) + common
def process_conf( conf ): """ Missing items are set to default values. Example configuration, all items:: solver_1 = { 'name' : 'oseen', 'kind' : 'nls.oseen', 'needs_problem_instance' : True, 'stabilization_hook' : 'create_stabil_mat', 'adimensionalize' : False, 'check_navier_stokes_rezidual' : False, 'i_max' : 10, 'eps_a' : 1e-8, 'eps_r' : 1.0, 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'is_plot' : False, 'log' : {'text' : 'oseen_log.txt', 'plot' : 'oseen_log.png'}, } """ get = conf.get_default_attr # Compulsory. needs_problem_instance = get('needs_problem_instance', True) if not needs_problem_instance: msg = 'set solver option "needs_problem_instance" to True!' raise ValueError(msg) stabilization_hook = get('stabilization_hook', None, 'missing "stabilization_hook" in options!') # With defaults. adimensionalize = get( 'adimensionalize', False ) check_navier_stokes_rezidual = get( 'check_navier_stokes_rezidual', False ) i_max = get( 'i_max', 1 ) eps_a = get( 'eps_a', 1e-10 ) eps_r = get( 'eps_r', 1.0 ) macheps = get( 'macheps', nm.finfo( nm.float64 ).eps ) lin_red = get( 'lin_red', 1.0 ) is_plot = get( 'is_plot', False ) log = get_logging_conf(conf) log = Struct(name='log_conf', **log) is_any_log = (log.text is not None) or (log.plot is not None) common = NonlinearSolver.process_conf( conf ) return Struct( **locals() ) + common
def process_conf(conf, kwargs): """ Missing items are set to default values for a linear problem. Example configuration, all items:: solver_1 = { 'name' : 'newton', 'kind' : 'nls.newton', 'i_max' : 2, 'eps_a' : 1e-8, 'eps_r' : 1e-2, 'eps_mode' : 'or', 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'lin_precision' : None, 'ls_on' : 0.99999, 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_min' : 1e-5, 'give_up_warp' : False, 'check' : 0, 'delta' : 1e-6, 'log' : None, # 'nonlinear' or 'linear' (ignore i_max) 'problem' : 'nonlinear', } """ get = make_get_conf(conf, kwargs) common = NonlinearSolver.process_conf(conf) log = get_logging_conf(conf) log = Struct(name='log_conf', **log) is_any_log = (log.text is not None) or (log.plot is not None) return Struct(i_max=get('i_max', 1), eps_a=get('eps_a', 1e-10), eps_r=get('eps_r', 1.0), eps_mode=get('eps_mode', 'and'), macheps=get('macheps', nm.finfo(nm.float64).eps), lin_red=get('lin_red', 1.0), lin_precision=get('lin_precision', None), ls_red=get('ls_red', 0.1), ls_red_warp=get('ls_red_warp', 0.001), ls_on=get('ls_on', 0.99999), ls_min=get('ls_min', 1e-5), give_up_warp=get('give_up_warp', False), check=get('check', 0), delta=get('delta', 1e-6), problem=get('problem', 'nonlinear'), log=log, is_any_log=is_any_log) + common
def process_conf( conf ): """ Missing items are set to default values for a linear problem. Example configuration, all items:: solver_1 = { 'name' : 'newton', 'kind' : 'nls.newton', 'i_max' : 2, 'eps_a' : 1e-8, 'eps_r' : 1e-2, 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'ls_red' : 0.1, 'ls_red_warp' : 0.001, 'ls_on' : 0.99999, 'ls_min' : 1e-5, 'check' : 0, 'delta' : 1e-6, 'is_plot' : False, 'log' : None, # 'nonlinear' or 'linear' (ignore i_max) 'problem' : 'nonlinear', } """ get = conf.get_default_attr i_max = get( 'i_max', 1 ) eps_a = get( 'eps_a', 1e-10 ) eps_r = get( 'eps_r', 1.0 ) macheps = get( 'macheps', nm.finfo( nm.float64 ).eps ) lin_red = get( 'lin_red', 1.0 ) ls_red = get( 'ls_red', 0.1 ) ls_red_warp = get( 'ls_red_warp', 0.001 ) ls_on = get( 'ls_on', 0.99999 ) ls_min = get( 'ls_min', 1e-5 ) check = get( 'check', 0 ) delta = get( 'delta', 1e-6) is_plot = get( 'is_plot', False ) problem = get( 'problem', 'nonlinear' ) log = get_logging_conf(conf) log = Struct(name='log_conf', **log) is_any_log = (log.text is not None) or (log.plot is not None) common = NonlinearSolver.process_conf( conf ) return Struct( **locals() ) + common
def process_conf(conf): """ Missing items are set to default values. Example configuration, all items:: solver_1 = { 'name' : 'semismooth_newton', 'kind' : 'nls.semismooth_newton', 'semismooth' : True, 'i_max' : 10, 'eps_a' : 1e-8, 'eps_r' : 1e-2, 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'ls_red_reg' : 0.1, 'ls_red_alt' : 0.01, 'ls_red_warp' : 0.001, 'ls_on' : 0.9, 'ls_min' : 1e-10, 'log' : {'plot' : 'convergence.png'}, } """ get = conf.get_default_attr semismooth = get('semismooth', True) i_max = get('i_max', 1) eps_a = get('eps_a', 1e-10) eps_r = get('eps_r', 1.0) macheps = get('macheps', nm.finfo(nm.float64).eps) lin_red = get('lin_red', 1.0) ls_red = {'regular' : get('ls_red_reg', 0.1), 'steepest_descent' : get('ls_red_alt', 0.01)} ls_red_warp = get('ls_red_warp', 0.001) ls_on = get('ls_on', 0.99999) ls_min = get('ls_min', 1e-5) log = get_logging_conf(conf) log = Struct(name='log_conf', **log) is_any_log = (log.text is not None) or (log.plot is not None) common = NonlinearSolver.process_conf(conf) return Struct(**locals()) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_1 = { 'name' : 'semismooth_newton', 'kind' : 'nls.semismooth_newton', 'semismooth' : True, 'i_max' : 10, 'eps_a' : 1e-8, 'eps_r' : 1e-2, 'macheps' : 1e-16, 'lin_red' : 1e-2, # Linear system error < (eps_a * lin_red). 'ls_red_reg' : 0.1, 'ls_red_alt' : 0.01, 'ls_red_warp' : 0.001, 'ls_on' : 0.9, 'ls_min' : 1e-10, 'log' : {'plot' : 'convergence.png'}, } """ get = make_get_conf(conf, kwargs) common = NonlinearSolver.process_conf(conf) log = get_logging_conf(conf) log = Struct(name='log_conf', **log) is_any_log = (log.text is not None) or (log.plot is not None) return Struct(semismooth=get('semismooth', True), i_max=get('i_max', 1), eps_a=get('eps_a', 1e-10), eps_r=get('eps_r', 1.0), macheps=get('macheps', nm.finfo(nm.float64).eps), lin_red=get('lin_red', 1.0), ls_red=get('ls_red', 0.1), ls_red_warp=get('ls_red_warp', 0.001), ls_on=get('ls_on', 0.99999), ls_min=get('ls_min', 1e-5), log=log, is_any_log=is_any_log) + common
def __init__(self, conf, **kwargs): OptimizationSolver.__init__(self, conf, **kwargs) conf = self.conf log = get_logging_conf(conf) conf.log = log = Struct(name='log_conf', **log) conf.is_any_log = (log.text is not None) or (log.plot is not None) if conf.is_any_log: self.log = Log([[r'$||\Psi||$'], [r'$||\nabla \Psi||$'], [r'$\alpha$'], ['iteration']], xlabels=['', '', 'all iterations', 'all iterations'], yscales=conf.yscales, is_plot=conf.log.plot is not None, log_filename=conf.log.text, formats=[['%.8e'], ['%.3e'], ['%.3e'], ['%d']]) else: self.log = None
def __init__(self, conf, **kwargs): NonlinearSolver.__init__(self, conf, **kwargs) conf = self.conf log = get_logging_conf(conf) conf.log = log = Struct(name='log_conf', **log) conf.is_any_log = (log.text is not None) or (log.plot is not None) if conf.is_any_log: self.log = Log([[r'$||r||$'], ['iteration']], xlabels=['', 'all iterations'], ylabels=[r'$||r||$', 'iteration'], yscales=['log', 'linear'], is_plot=conf.log.plot is not None, log_filename=conf.log.text, formats=[['%.8e'], ['%d']]) else: self.log = None
def __init__(self, conf, **kwargs): OptimizationSolver.__init__(self, conf, **kwargs) conf = self.conf log = get_logging_conf(conf) conf.log = log = Struct(name='log_conf', **log) conf.is_any_log = (log.text is not None) or (log.plot is not None) if conf.is_any_log: self.log = Log( [[r'$||\Psi||$'], [r'$||\nabla \Psi||$'], [r'$\alpha$'], ['iteration']], xlabels=['', '', 'all iterations', 'all iterations'], yscales=conf.yscales, is_plot=conf.log.plot is not None, log_filename=conf.log.text, formats=[['%.8e'], ['%.3e'], ['%.3e'], ['%d']]) else: self.log = None