def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_2 = { 'name' : 'lobpcg', 'kind' : 'eig.scipy_lobpcg', 'i_max' : 20, 'n_eigs' : 5, 'eps_a' : None, 'largest' : True, 'precond' : None, 'verbosity' : 0, } """ get = make_get_conf(conf, kwargs) common = EigenvalueSolver.process_conf(conf) return Struct(i_max=get('i_max', 20), n_eigs=get('n_eigs', None), eps_a=get('eps_a', None), largest=get('largest', True), precond=get('precond', None), verbosity=get('verbosity', 0)) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_120 = { 'name' : 'ls120', 'kind' : 'ls.petsc', 'method' : 'cg', # ksp_type 'precond' : 'icc', # pc_type 'precond_side' : 'left', # ksp_pc_side 'eps_a' : 1e-12, # abstol 'eps_r' : 1e-12, # rtol 'eps_d' : 1e5, # divtol 'i_max' : 1000, # maxits } """ get = make_get_conf(conf, kwargs) common = LinearSolver.process_conf(conf) return Struct(method=get('method', 'cg'), precond=get('precond', 'icc'), precond_side=get('precond_side', None), i_max=get('i_max', 100), eps_a=get('eps_a', 1e-8), eps_r=get('eps_r', 1e-8), eps_d=get('eps_d', 1e5)) + common
def process_conf(conf, kwargs): """ Setup solver configuration options. Example configuration:: solvers = { 'ls': ('ls.schur_generalized', {'blocks': {'u': ['displacement1', 'displacement2'], 'v': ['velocity1', 'velocity2'], 'w': ['pressure1', 'pressure2'], }, 'function': my_schur, 'needs_problem_instance': True, }) } """ get = make_get_conf(conf, kwargs) common = ScipyDirect.process_conf(conf, kwargs) return Struct(blocks=get('blocks', None, 'missing "blocks" in options!'), function=get('function', None, 'missing "function" in options!'), needs_problem_instance=True) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_1 = { 'name' : 'ls', 'kind' : 'ls.petsc_parallel', 'log_dir' : '.', # Store logs here. 'n_proc' : 5, # Number of processes to run. 'method' : 'cg', # ksp_type 'precond' : 'bjacobi', # pc_type 'sub_precond' : 'icc', # sub_pc_type 'eps_a' : 1e-12, # abstol 'eps_r' : 1e-12, # rtol 'eps_d' : 1e5, # divtol 'i_max' : 1000, # maxits } """ get = make_get_conf(conf, kwargs) common = PETScKrylovSolver.process_conf(conf, kwargs) return Struct(log_dir=get('log_dir', '.'), n_proc=get('n_proc', 1), sub_precond=get('sub_precond', 'icc')) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_2 = { 'name' : 'eigen1', 'kind' : 'eig.pysparse', 'i_max' : 150, 'eps_a' : 1e-5, 'tau' : -10.0, 'method' : 'qmrs', 'verbosity' : 0, 'strategy' : 1, } """ get = make_get_conf(conf, kwargs) common = EigenvalueSolver.process_conf(conf) return Struct(i_max=get('i_max', 100), n_eigs=get('n_eigs', 5), eps_a=get('eps_a', 1e-5), tau=get('tau', 0.0), method=get('method', 'qmrs'), verbosity=get('verbosity', 0), strategy=get('strategy', 1)) + common
def process_conf(conf, kwargs): """ Missing items are left to scipy defaults. Unused options are ignored. Example configuration, all items:: solver_1 = { 'name' : 'broyden', 'kind' : 'nls.scipy_broyden_like', 'method' : 'broyden3', 'i_max' : 10, 'alpha' : 0.9, 'M' : 5, 'w0' : 0.1, 'verbose' : True, } """ get = make_get_conf(conf, kwargs) common = NonlinearSolver.process_conf(conf) return Struct(method=get('method', 'broyden3'), i_max=get('i_max', 10), alpha=get('alpha', 0.9), M=get('M', 5), w0=get('w0', 0.1), verbose=get('verbose', False)) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_1 = { 'name' : 'ls', 'kind' : 'ls.petsc_parallel', 'n_proc' : 5, # Number of processes to run. 'method' : 'cg', # ksp_type 'precond' : 'bjacobi', # pc_type 'sub_precond' : 'icc', # sub_pc_type 'eps_a' : 1e-12, # abstol 'eps_r' : 1e-12, # rtol 'eps_d' : 1e5, # divtol 'i_max' : 1000, # maxits } """ get = make_get_conf(conf, kwargs) common = PETScKrylovSolver.process_conf(conf, kwargs) return Struct(n_proc=get('n_proc', 1), sub_precond=get('sub_precond', 'icc')) + common
def process_conf(conf, kwargs): """ Setup solver configuration options. Example configuration:: solvers = { 'ls': ('ls.cm_pb', {'others': ['acoustic_subproblem.py'], 'coupling_variables': ['g'], 'needs_problem_instance': True, }) } """ get = make_get_conf(conf, kwargs) common = ScipyDirect.process_conf(conf, kwargs) return ( Struct( others=get("others", None, 'missing "others" in options!'), coupling_variables=get("coupling_variables", None, 'missing "coupling_variables"!'), needs_problem_instance=True, ) + common )
def process_conf(conf, kwargs): """ Setup solver configuration options. Example configuration:: solvers = { 'ls': ('ls.schur_generalized', {'blocks': {'u': ['displacement1', 'displacement2'], 'v': ['velocity1', 'velocity2'], 'w': ['pressure1', 'pressure2'], }, 'function': my_schur, 'needs_problem_instance': True, }) } """ get = make_get_conf(conf, kwargs) common = ScipyDirect.process_conf(conf, kwargs) return Struct( blocks=get('blocks', None, 'missing "blocks" in options!'), function=get('function', None, 'missing "function" in options!'), needs_problem_instance=True) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_110 = { 'name' : 'ls110', 'kind' : 'ls.scipy_iterative', 'method' : 'cg', 'precond' : None, 'callback' : None, 'i_max' : 1000, 'eps_r' : 1e-12, } """ get = make_get_conf(conf, kwargs) common = LinearSolver.process_conf(conf) return Struct(method=get('method', 'cg'), precond=get('precond', None), callback=get('callback', None), i_max=get('i_max', 100), eps_a=None, eps_r=get('eps_r', 1e-8)) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_102 = { 'name' : 'ls102', 'kind' : 'ls.pyamg', 'method' : 'smoothed_aggregation_solver', 'accel' : 'cg' 'eps_r' : 1e-12, } """ get = make_get_conf(conf, kwargs) common = LinearSolver.process_conf(conf) return ( Struct( method=get("method", "smoothed_aggregation_solver"), accel=get("accel", None), i_max=None, eps_a=None, eps_r=get("eps_r", 1e-8), ) + common )
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_1100 = { 'name' : 'dls1100', 'kind' : 'ls.scipy_direct', 'method' : 'superlu', 'presolve' : False, 'warn' : True, } """ get = make_get_conf(conf, kwargs) common = LinearSolver.process_conf(conf) return ( Struct( method=get("method", "auto"), presolve=get("presolve", False), warn=get("warn", True), i_max=None, eps_a=None, eps_r=None, ) + common )
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_2 = { 'name' : 'eigen1', 'kind' : 'eig.pysparse', 'i_max' : 150, 'eps_a' : 1e-5, 'tau' : -10.0, 'method' : 'qmrs', 'verbosity' : 0, 'strategy' : 1, } """ get = make_get_conf(conf, kwargs) common = EigenvalueSolver.process_conf(conf) return Struct(i_max=get('i_max', 100), eps_a=get('eps_a', 1e-5), tau=get('tau', 0.0), method=get('method', 'qmrs'), verbosity=get('verbosity', 0), strategy=get('strategy', 1)) + common
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): """ Process configuration options. """ get = make_get_conf(conf, kwargs) common = SimpleTimeSteppingSolver.process_conf(conf, kwargs) return Struct(mass=get('mass', None, 'missing "mass" in options!'), lumped=get('lumped', False)) + 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, 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, kwargs): """ Process configuration options. """ get = make_get_conf(conf, kwargs) common = TimeSteppingSolver.process_conf(conf) return Struct(t0=get('t0', 0.0), t1=get('t1', 1.0), dt=get('dt', None), n_step=get('n_step', 10), quasistatic=get('quasistatic', False)) + common
def process_conf(conf, kwargs): """ Process configuration options. """ get = make_get_conf(conf, kwargs) common = SimpleTimeSteppingSolver.process_conf(conf, kwargs) adt = Struct(red_factor=get('dt_red_factor', 0.2), red_max=get('dt_red_max', 1e-3), inc_factor=get('dt_inc_factor', 1.25), inc_on_iter=get('dt_inc_on_iter', 4), inc_wait=get('dt_inc_wait', 5), red=1.0, wait=0, dt0=0.0) return Struct(adapt_fun=get('adapt_fun', adapt_time_step), adt=adt) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_20 = { 'name' : 'eigen2', 'kind' : 'eig.sgscipy', 'force_n_eigs' : True, } """ get = make_get_conf(conf, kwargs) common = EigenvalueSolver.process_conf(conf) return Struct(force_n_eigs=get('force_n_eigs', False)) + 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 process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_102 = { 'name' : 'ls102', 'kind' : 'ls.pyamg', 'method' : 'smoothed_aggregation_solver', 'accel' : 'cg' 'eps_r' : 1e-12, } """ get = make_get_conf(conf, kwargs) common = LinearSolver.process_conf(conf) return Struct(method=get('method', 'smoothed_aggregation_solver'), accel = get('accel', None), i_max=None, eps_a=None, eps_r=get('eps_r', 1e-8)) + common
def process_conf(conf, kwargs): """ Missing items are set to default values. Example configuration, all items:: solver_1100 = { 'name' : 'dls1100', 'kind' : 'ls.scipy_direct', 'method' : 'superlu', 'presolve' : False, 'warn' : True, } """ get = make_get_conf(conf, kwargs) common = LinearSolver.process_conf(conf) return Struct(method=get('method', 'auto'), presolve=get('presolve', False), warn=get('warn', True), i_max=None, eps_a=None, eps_r=None) + common
def process_conf(conf, kwargs): """ Setup solver configuration options. Example configuration:: solvers = { 'ls': ('ls.cm_pb', {'others': ['acoustic_subproblem.py'], 'coupling_variables': ['g'], 'needs_problem_instance': True, }) } """ get = make_get_conf(conf, kwargs) common = ScipyDirect.process_conf(conf, kwargs) return Struct(others=get('others', None, 'missing "others" in options!'), coupling_variables=get('coupling_variables', None, 'missing "coupling_variables"!'), needs_problem_instance=True) + common
def process_conf(conf, kwargs): """ Setup solver configuration options. Example configuration:: solvers = { 'ls': ('ls.schur_complement', {'eliminate': ['displacement'], 'keep': ['pressure'], 'needs_problem_instance': True, }) } """ get = make_get_conf(conf, kwargs) conf.blocks = {'1': get('eliminate', None, 'missing "eliminate" in options!'), '2': get('keep', None, 'missing "keep" in options!'),} conf.function = SchurComplement.schur_fun common = SchurGeneralized.process_conf(conf, kwargs) return common
def process_conf(conf, kwargs): """ Setup solver configuration options. Example configuration:: solvers = { 'ls': ('ls.schur_complement', {'eliminate': ['displacement'], 'keep': ['pressure'], 'needs_problem_instance': True, }) } """ get = make_get_conf(conf, kwargs) conf.blocks = { '1': get('eliminate', None, 'missing "eliminate" in options!'), '2': get('keep', None, 'missing "keep" in options!'), } conf.function = SchurComplement.schur_fun common = SchurGeneralized.process_conf(conf, kwargs) return common
def process_conf(conf, kwargs): """ Missing items are left to SciPy defaults. Unused options are ignored. Besides 'i_max', use option names according to scipy.optimize function arguments. The 'i_max' translates either to 'maxiter' or 'maxfun' as available. Example configuration:: solver_1 = { 'name' : 'fmin', 'kind' : 'nls.scipy_fmin_like', 'method' : 'bfgs', 'i_max' : 10, 'verbose' : True, 'gtol' : 1e-7 } """ get = make_get_conf(conf, kwargs) common = OptimizationSolver.process_conf(conf) opts = Struct(method=get('method', 'fmin'), i_max=get('i_max', 10), verbose=get('verbose', False)) + common other = {} keys = opts.to_dict().keys() for key, val in conf.to_dict().iteritems(): if key not in keys: other[key] = val return opts + Struct(**other)