示例#1
0
def dense_options(default_solver='solve',
                  default_least_squares_solver='least_squares_lstsq',
                  least_squares_lstsq_rcond=-1.):
    """Returns |solver_options| (with default values) for dense |NumPy| matricies.

    Parameters
    ----------
    default_solver
        Default dense solver to use (solve, least_squares_lstsq, generic_lgmres,
        least_squares_generic_lsmr, least_squares_generic_lsqr).
    default_least_squares_solver
        Default solver to use for least squares problems (least_squares_lstsq,
        least_squares_generic_lsmr, least_squares_generic_lsqr).
    least_squares_lstsq_rcond
        See :func:`numpy.linalg.lstsq`.

    Returns
    -------
    A tuple of possible values for |solver_options|.
    """

    assert default_least_squares_solver.startswith('least_squares')

    opts = (('solve', {
        'type': 'solve'
    }), ('least_squares_lstsq', {
        'type': 'least_squares_lstsq',
        'rcond': least_squares_lstsq_rcond
    }))
    opts = OrderedDict(opts)
    opts.update(genericsolvers.options())
    def_opt = opts.pop(default_solver)
    if default_least_squares_solver != default_solver:
        def_ls_opt = opts.pop(default_least_squares_solver)
        ordered_opts = OrderedDict(
            ((default_solver, def_opt), (default_least_squares_solver,
                                         def_ls_opt)))
    else:
        ordered_opts = OrderedDict(((default_solver, def_opt), ))
    ordered_opts.update(opts)
    return ordered_opts
示例#2
0
def dense_options(default_solver='solve',
                  default_least_squares_solver='least_squares_lstsq',
                  least_squares_lstsq_rcond=-1.):
    """Returns |solver_options| (with default values) for dense |NumPy| matricies.

    Parameters
    ----------
    default_solver
        Default dense solver to use (solve, least_squares_lstsq, generic_lgmres,
        least_squares_generic_lsmr, least_squares_generic_lsqr).
    default_least_squares_solver
        Default solver to use for least squares problems (least_squares_lstsq,
        least_squares_generic_lsmr, least_squares_generic_lsqr).
    least_squares_lstsq_rcond
        See :func:`numpy.linalg.lstsq`.

    Returns
    -------
    A tuple of possible values for |solver_options|.
    """

    assert default_least_squares_solver.startswith('least_squares')

    opts = (('solve',               {'type': 'solve'}),
            ('least_squares_lstsq', {'type': 'least_squares_lstsq',
                                     'rcond': least_squares_lstsq_rcond}))
    opts = OrderedDict(opts)
    opts.update(genericsolvers.options())
    def_opt = opts.pop(default_solver)
    if default_least_squares_solver != default_solver:
        def_ls_opt = opts.pop(default_least_squares_solver)
        ordered_opts = OrderedDict(((default_solver, def_opt),
                                    (default_least_squares_solver, def_ls_opt)))
    else:
        ordered_opts = OrderedDict(((default_solver, def_opt),))
    ordered_opts.update(opts)
    return ordered_opts
示例#3
0
def sparse_options(default_solver='spsolve',
                   default_least_squares_solver='least_squares_lsmr' if HAVE_SCIPY_LSMR else 'least_squares_generic_lsmr',
                   bicgstab_tol=1e-15,
                   bicgstab_maxiter=None,
                   spilu_drop_tol=1e-4,
                   spilu_fill_factor=10,
                   spilu_drop_rule='basic,area',
                   spilu_permc_spec='COLAMD',
                   spsolve_permc_spec='COLAMD',
                   spsolve_keep_factorization=True,
                   lgmres_tol=1e-5,
                   lgmres_maxiter=1000,
                   lgmres_inner_m=39,
                   lgmres_outer_k=3,
                   least_squares_lsmr_damp=0.0,
                   least_squares_lsmr_atol=1e-6,
                   least_squares_lsmr_btol=1e-6,
                   least_squares_lsmr_conlim=1e8,
                   least_squares_lsmr_maxiter=None,
                   least_squares_lsmr_show=False,
                   least_squares_lsqr_damp=0.0,
                   least_squares_lsqr_atol=1e-6,
                   least_squares_lsqr_btol=1e-6,
                   least_squares_lsqr_conlim=1e8,
                   least_squares_lsqr_iter_lim=None,
                   least_squares_lsqr_show=False,
                   pyamg_tol=1e-5,
                   pyamg_maxiter=400,
                   pyamg_verb=False,
                   pyamg_rs_strength=('classical', {'theta': 0.25}),
                   pyamg_rs_CF='RS',
                   pyamg_rs_presmoother=('gauss_seidel', {'sweep': 'symmetric'}),
                   pyamg_rs_postsmoother=('gauss_seidel', {'sweep': 'symmetric'}),
                   pyamg_rs_max_levels=10,
                   pyamg_rs_max_coarse=500,
                   pyamg_rs_coarse_solver='pinv2',
                   pyamg_rs_cycle='V',
                   pyamg_rs_accel=None,
                   pyamg_rs_tol=1e-5,
                   pyamg_rs_maxiter=100,
                   pyamg_sa_symmetry='hermitian',
                   pyamg_sa_strength='symmetric',
                   pyamg_sa_aggregate='standard',
                   pyamg_sa_smooth=('jacobi', {'omega': 4.0/3.0}),
                   pyamg_sa_presmoother=('block_gauss_seidel', {'sweep': 'symmetric'}),
                   pyamg_sa_postsmoother=('block_gauss_seidel', {'sweep': 'symmetric'}),
                   pyamg_sa_improve_candidates=[('block_gauss_seidel', {'sweep': 'symmetric', 'iterations': 4}), None],
                   pyamg_sa_max_levels=10,
                   pyamg_sa_max_coarse=500,
                   pyamg_sa_diagonal_dominance=False,
                   pyamg_sa_coarse_solver='pinv2',
                   pyamg_sa_cycle='V',
                   pyamg_sa_accel=None,
                   pyamg_sa_tol=1e-5,
                   pyamg_sa_maxiter=100):
    """Returns |solver_options| (with default values) for sparse |NumPy| matricies.

    Parameters
    ----------
    default_solver
        Default sparse solver to use (spsolve, bicgstab, bicgstab_spilu, pyamg,
        pyamg_rs, pyamg_sa, generic_lgmres, least_squares_lsmr, least_squares_lsqr).
    default_least_squares_solver
        Default solver to use for least squares problems (least_squares_lsmr,
        least_squares_lsqr).
    bicgstab_tol
        See :func:`scipy.sparse.linalg.bicgstab`.
    bicgstab_maxiter
        See :func:`scipy.sparse.linalg.bicgstab`.
    spilu_drop_tol
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_fill_factor
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_drop_rule
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_permc_spec
        See :func:`scipy.sparse.linalg.spilu`.
    spsolve_permc_spec
        See :func:`scipy.sparse.linalg.spsolve`.
    lgmres_tol
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_maxiter
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_inner_m
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_outer_k
        See :func:`scipy.sparse.linalg.lgmres`.
    least_squares_lsmr_damp
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_atol
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_btol
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_conlim
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_maxiter
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_show
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsqr_damp
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_atol
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_btol
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_conlim
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_iter_lim
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_show
        See :func:`scipy.sparse.linalg.lsqr`.
    pyamg_tol
        Tolerance for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_maxiter
        Maximum iterations for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_verb
        Verbosity flag for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_rs_strength
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_CF
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_presmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_postsmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_max_levels
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_max_coarse
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_coarse_solver
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_cycle
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_accel
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_tol
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_maxiter
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_sa_symmetry
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_strength
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_aggregate
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_smooth
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_presmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_postsmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_improve_candidates
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_max_levels
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_max_coarse
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_diagonal_dominance
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_coarse_solver
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_cycle
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_accel
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_tol
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_maxiter
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.

    Returns
    -------
    A tuple of all possible |solver_options|.
    """

    assert default_least_squares_solver.startswith('least_squares')

    opts = (('bicgstab_spilu',     {'type': 'bicgstab_spilu',
                                    'tol': bicgstab_tol,
                                    'maxiter': bicgstab_maxiter,
                                    'spilu_drop_tol': spilu_drop_tol,
                                    'spilu_fill_factor': spilu_fill_factor,
                                    'spilu_drop_rule': spilu_drop_rule,
                                    'spilu_permc_spec': spilu_permc_spec}),
            ('bicgstab',           {'type': 'bicgstab',
                                    'tol': bicgstab_tol,
                                    'maxiter': bicgstab_maxiter}),
            ('spsolve',            {'type': 'spsolve',
                                    'permc_spec': spsolve_permc_spec,
                                    'keep_factorization': spsolve_keep_factorization}),
            ('lgmres',             {'type': 'lgmres',
                                    'tol': lgmres_tol,
                                    'maxiter': lgmres_maxiter,
                                    'inner_m': lgmres_inner_m,
                                    'outer_k': lgmres_outer_k}),
            ('least_squares_lsqr', {'type': 'least_squares_lsqr',
                                    'damp': least_squares_lsqr_damp,
                                    'atol': least_squares_lsqr_atol,
                                    'btol': least_squares_lsqr_btol,
                                    'conlim': least_squares_lsqr_conlim,
                                    'iter_lim': least_squares_lsqr_iter_lim,
                                    'show': least_squares_lsqr_show}))

    if HAVE_SCIPY_LSMR:
        opts += (('least_squares_lsmr', {'type': 'least_squares_lsmr',
                                         'damp': least_squares_lsmr_damp,
                                         'atol': least_squares_lsmr_atol,
                                         'btol': least_squares_lsmr_btol,
                                         'conlim': least_squares_lsmr_conlim,
                                         'maxiter': least_squares_lsmr_maxiter,
                                         'show': least_squares_lsmr_show}),)

    if HAVE_PYAMG:
        opts += (('pyamg',    {'type': 'pyamg',
                               'tol': pyamg_tol,
                               'maxiter': pyamg_maxiter}),
                 ('pyamg-rs', {'type': 'pyamg-rs',
                               'strength': pyamg_rs_strength,
                               'CF': pyamg_rs_CF,
                               'presmoother': pyamg_rs_presmoother,
                               'postsmoother': pyamg_rs_postsmoother,
                               'max_levels': pyamg_rs_max_levels,
                               'max_coarse': pyamg_rs_max_coarse,
                               'coarse_solver': pyamg_rs_coarse_solver,
                               'cycle': pyamg_rs_cycle,
                               'accel': pyamg_rs_accel,
                               'tol': pyamg_rs_tol,
                               'maxiter': pyamg_rs_maxiter}),
                 ('pyamg-sa', {'type': 'pyamg-sa',
                               'symmetry': pyamg_sa_symmetry,
                               'strength': pyamg_sa_strength,
                               'aggregate': pyamg_sa_aggregate,
                               'smooth': pyamg_sa_smooth,
                               'presmoother': pyamg_sa_presmoother,
                               'postsmoother': pyamg_sa_postsmoother,
                               'improve_candidates': pyamg_sa_improve_candidates,
                               'max_levels': pyamg_sa_max_levels,
                               'max_coarse': pyamg_sa_max_coarse,
                               'diagonal_dominance': pyamg_sa_diagonal_dominance,
                               'coarse_solver': pyamg_sa_coarse_solver,
                               'cycle': pyamg_sa_cycle,
                               'accel': pyamg_sa_accel,
                               'tol': pyamg_sa_tol,
                               'maxiter': pyamg_sa_maxiter}))
    opts = OrderedDict(opts)
    opts.update(genericsolvers.options())
    def_opt = opts.pop(default_solver)
    if default_least_squares_solver != default_solver:
        def_ls_opt = opts.pop(default_least_squares_solver)
        ordered_opts = OrderedDict(((default_solver, def_opt),
                                    (default_least_squares_solver, def_ls_opt)))
    else:
        ordered_opts = OrderedDict(((default_solver, def_opt),))
    ordered_opts.update(opts)
    return ordered_opts
示例#4
0
文件: numpy.py 项目: lucas-ca/pymor
def sparse_options(
    default_solver="spsolve",
    default_least_squares_solver="least_squares_lsmr",
    bicgstab_tol=1e-15,
    bicgstab_maxiter=None,
    spilu_drop_tol=1e-4,
    spilu_fill_factor=10,
    spilu_drop_rule="basic,area",
    spilu_permc_spec="COLAMD",
    spsolve_permc_spec="COLAMD",
    spsolve_keep_factorization=True,
    lgmres_tol=1e-5,
    lgmres_maxiter=1000,
    lgmres_inner_m=39,
    lgmres_outer_k=3,
    least_squares_lsmr_damp=0.0,
    least_squares_lsmr_atol=1e-6,
    least_squares_lsmr_btol=1e-6,
    least_squares_lsmr_conlim=1e8,
    least_squares_lsmr_maxiter=None,
    least_squares_lsmr_show=False,
    least_squares_lsqr_damp=0.0,
    least_squares_lsqr_atol=1e-6,
    least_squares_lsqr_btol=1e-6,
    least_squares_lsqr_conlim=1e8,
    least_squares_lsqr_iter_lim=None,
    least_squares_lsqr_show=False,
    pyamg_tol=1e-5,
    pyamg_maxiter=400,
    pyamg_verb=False,
    pyamg_rs_strength=("classical", {"theta": 0.25}),
    pyamg_rs_CF="RS",
    pyamg_rs_presmoother=("gauss_seidel", {"sweep": "symmetric"}),
    pyamg_rs_postsmoother=("gauss_seidel", {"sweep": "symmetric"}),
    pyamg_rs_max_levels=10,
    pyamg_rs_max_coarse=500,
    pyamg_rs_coarse_solver="pinv2",
    pyamg_rs_cycle="V",
    pyamg_rs_accel=None,
    pyamg_rs_tol=1e-5,
    pyamg_rs_maxiter=100,
    pyamg_sa_symmetry="hermitian",
    pyamg_sa_strength="symmetric",
    pyamg_sa_aggregate="standard",
    pyamg_sa_smooth=("jacobi", {"omega": 4.0 / 3.0}),
    pyamg_sa_presmoother=("block_gauss_seidel", {"sweep": "symmetric"}),
    pyamg_sa_postsmoother=("block_gauss_seidel", {"sweep": "symmetric"}),
    pyamg_sa_improve_candidates=[("block_gauss_seidel", {"sweep": "symmetric", "iterations": 4}), None],
    pyamg_sa_max_levels=10,
    pyamg_sa_max_coarse=500,
    pyamg_sa_diagonal_dominance=False,
    pyamg_sa_coarse_solver="pinv2",
    pyamg_sa_cycle="V",
    pyamg_sa_accel=None,
    pyamg_sa_tol=1e-5,
    pyamg_sa_maxiter=100,
):
    """Returns |solver_options| (with default values) for sparse |NumPy| matricies.

    Parameters
    ----------
    default_solver
        Default sparse solver to use (spsolve, bicgstab, bicgstab_spilu, pyamg,
        pyamg_rs, pyamg_sa, generic_lgmres, least_squares_lsmr, least_squares_lsqr).
    default_least_squares_solver
        Default solver to use for least squares problems (least_squares_lsmr,
        least_squares_lsqr).
    bicgstab_tol
        See :func:`scipy.sparse.linalg.bicgstab`.
    bicgstab_maxiter
        See :func:`scipy.sparse.linalg.bicgstab`.
    spilu_drop_tol
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_fill_factor
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_drop_rule
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_permc_spec
        See :func:`scipy.sparse.linalg.spilu`.
    spsolve_permc_spec
        See :func:`scipy.sparse.linalg.spsolve`.
    lgmres_tol
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_maxiter
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_inner_m
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_outer_k
        See :func:`scipy.sparse.linalg.lgmres`.
    least_squares_lsmr_damp
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_atol
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_btol
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_conlim
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_maxiter
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_show
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsqr_damp
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_atol
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_btol
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_conlim
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_iter_lim
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_show
        See :func:`scipy.sparse.linalg.lsqr`.
    pyamg_tol
        Tolerance for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_maxiter
        Maximum iterations for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_verb
        Verbosity flag for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_rs_strength
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_CF
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_presmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_postsmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_max_levels
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_max_coarse
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_coarse_solver
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_cycle
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_accel
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_tol
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_maxiter
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_sa_symmetry
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_strength
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_aggregate
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_smooth
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_presmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_postsmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_improve_candidates
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_max_levels
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_max_coarse
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_diagonal_dominance
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_coarse_solver
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_cycle
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_accel
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_tol
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_maxiter
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.

    Returns
    -------
    A tuple of all possible |solver_options|.
    """

    assert default_least_squares_solver.startswith("least_squares")

    opts = (
        (
            "bicgstab_spilu",
            {
                "type": "bicgstab_spilu",
                "tol": bicgstab_tol,
                "maxiter": bicgstab_maxiter,
                "spilu_drop_tol": spilu_drop_tol,
                "spilu_fill_factor": spilu_fill_factor,
                "spilu_drop_rule": spilu_drop_rule,
                "spilu_permc_spec": spilu_permc_spec,
            },
        ),
        ("bicgstab", {"type": "bicgstab", "tol": bicgstab_tol, "maxiter": bicgstab_maxiter}),
        (
            "spsolve",
            {"type": "spsolve", "permc_spec": spsolve_permc_spec, "keep_factorization": spsolve_keep_factorization},
        ),
        (
            "lgmres",
            {
                "type": "lgmres",
                "tol": lgmres_tol,
                "maxiter": lgmres_maxiter,
                "inner_m": lgmres_inner_m,
                "outer_k": lgmres_outer_k,
            },
        ),
        (
            "least_squares_lsqr",
            {
                "type": "least_squares_lsqr",
                "damp": least_squares_lsqr_damp,
                "atol": least_squares_lsqr_atol,
                "btol": least_squares_lsqr_btol,
                "conlim": least_squares_lsqr_conlim,
                "iter_lim": least_squares_lsqr_iter_lim,
                "show": least_squares_lsqr_show,
            },
        ),
    )

    if HAVE_SCIPY_LSMR:
        opts += (
            (
                "least_squares_lsmr",
                {
                    "type": "least_squares_lsmr",
                    "damp": least_squares_lsmr_damp,
                    "atol": least_squares_lsmr_atol,
                    "btol": least_squares_lsmr_btol,
                    "conlim": least_squares_lsmr_conlim,
                    "maxiter": least_squares_lsmr_maxiter,
                    "show": least_squares_lsmr_show,
                },
            ),
        )

    if HAVE_PYAMG:
        opts += (
            ("pyamg", {"type": "pyamg", "tol": pyamg_tol, "maxiter": pyamg_maxiter}),
            (
                "pyamg-rs",
                {
                    "type": "pyamg-rs",
                    "strength": pyamg_rs_strength,
                    "CF": pyamg_rs_CF,
                    "presmoother": pyamg_rs_presmoother,
                    "postsmoother": pyamg_rs_postsmoother,
                    "max_levels": pyamg_rs_max_levels,
                    "max_coarse": pyamg_rs_max_coarse,
                    "coarse_solver": pyamg_rs_coarse_solver,
                    "cycle": pyamg_rs_cycle,
                    "accel": pyamg_rs_accel,
                    "tol": pyamg_rs_tol,
                    "maxiter": pyamg_rs_maxiter,
                },
            ),
            (
                "pyamg-sa",
                {
                    "type": "pyamg-sa",
                    "symmetry": pyamg_sa_symmetry,
                    "strength": pyamg_sa_strength,
                    "aggregate": pyamg_sa_aggregate,
                    "smooth": pyamg_sa_smooth,
                    "presmoother": pyamg_sa_presmoother,
                    "postsmoother": pyamg_sa_postsmoother,
                    "improve_candidates": pyamg_sa_improve_candidates,
                    "max_levels": pyamg_sa_max_levels,
                    "max_coarse": pyamg_sa_max_coarse,
                    "diagonal_dominance": pyamg_sa_diagonal_dominance,
                    "coarse_solver": pyamg_sa_coarse_solver,
                    "cycle": pyamg_sa_cycle,
                    "accel": pyamg_sa_accel,
                    "tol": pyamg_sa_tol,
                    "maxiter": pyamg_sa_maxiter,
                },
            ),
        )
    opts = OrderedDict(opts)
    opts.update(genericsolvers.options())
    def_opt = opts.pop(default_solver)
    if default_least_squares_solver != default_solver:
        def_ls_opt = opts.pop(default_least_squares_solver)
        ordered_opts = OrderedDict(((default_solver, def_opt), (default_least_squares_solver, def_ls_opt)))
    else:
        ordered_opts = OrderedDict(((default_solver, def_opt),))
    ordered_opts.update(opts)
    return ordered_opts
示例#5
0
def sparse_options(default_solver='spsolve',
                   default_least_squares_solver='least_squares_lsmr'
                   if HAVE_SCIPY_LSMR else 'least_squares_generic_lsmr',
                   bicgstab_tol=1e-15,
                   bicgstab_maxiter=None,
                   spilu_drop_tol=1e-4,
                   spilu_fill_factor=10,
                   spilu_drop_rule='basic,area',
                   spilu_permc_spec='COLAMD',
                   spsolve_permc_spec='COLAMD',
                   spsolve_keep_factorization=True,
                   lgmres_tol=1e-5,
                   lgmres_maxiter=1000,
                   lgmres_inner_m=39,
                   lgmres_outer_k=3,
                   least_squares_lsmr_damp=0.0,
                   least_squares_lsmr_atol=1e-6,
                   least_squares_lsmr_btol=1e-6,
                   least_squares_lsmr_conlim=1e8,
                   least_squares_lsmr_maxiter=None,
                   least_squares_lsmr_show=False,
                   least_squares_lsqr_damp=0.0,
                   least_squares_lsqr_atol=1e-6,
                   least_squares_lsqr_btol=1e-6,
                   least_squares_lsqr_conlim=1e8,
                   least_squares_lsqr_iter_lim=None,
                   least_squares_lsqr_show=False,
                   pyamg_tol=1e-5,
                   pyamg_maxiter=400,
                   pyamg_verb=False,
                   pyamg_rs_strength=('classical', {
                       'theta': 0.25
                   }),
                   pyamg_rs_CF='RS',
                   pyamg_rs_presmoother=('gauss_seidel', {
                       'sweep': 'symmetric'
                   }),
                   pyamg_rs_postsmoother=('gauss_seidel', {
                       'sweep': 'symmetric'
                   }),
                   pyamg_rs_max_levels=10,
                   pyamg_rs_max_coarse=500,
                   pyamg_rs_coarse_solver='pinv2',
                   pyamg_rs_cycle='V',
                   pyamg_rs_accel=None,
                   pyamg_rs_tol=1e-5,
                   pyamg_rs_maxiter=100,
                   pyamg_sa_symmetry='hermitian',
                   pyamg_sa_strength='symmetric',
                   pyamg_sa_aggregate='standard',
                   pyamg_sa_smooth=('jacobi', {
                       'omega': 4.0 / 3.0
                   }),
                   pyamg_sa_presmoother=('block_gauss_seidel', {
                       'sweep': 'symmetric'
                   }),
                   pyamg_sa_postsmoother=('block_gauss_seidel', {
                       'sweep': 'symmetric'
                   }),
                   pyamg_sa_improve_candidates=[('block_gauss_seidel', {
                       'sweep': 'symmetric',
                       'iterations': 4
                   }), None],
                   pyamg_sa_max_levels=10,
                   pyamg_sa_max_coarse=500,
                   pyamg_sa_diagonal_dominance=False,
                   pyamg_sa_coarse_solver='pinv2',
                   pyamg_sa_cycle='V',
                   pyamg_sa_accel=None,
                   pyamg_sa_tol=1e-5,
                   pyamg_sa_maxiter=100):
    """Returns |solver_options| (with default values) for sparse |NumPy| matricies.

    Parameters
    ----------
    default_solver
        Default sparse solver to use (spsolve, bicgstab, bicgstab_spilu, pyamg,
        pyamg_rs, pyamg_sa, generic_lgmres, least_squares_lsmr, least_squares_lsqr).
    default_least_squares_solver
        Default solver to use for least squares problems (least_squares_lsmr,
        least_squares_lsqr).
    bicgstab_tol
        See :func:`scipy.sparse.linalg.bicgstab`.
    bicgstab_maxiter
        See :func:`scipy.sparse.linalg.bicgstab`.
    spilu_drop_tol
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_fill_factor
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_drop_rule
        See :func:`scipy.sparse.linalg.spilu`.
    spilu_permc_spec
        See :func:`scipy.sparse.linalg.spilu`.
    spsolve_permc_spec
        See :func:`scipy.sparse.linalg.spsolve`.
    lgmres_tol
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_maxiter
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_inner_m
        See :func:`scipy.sparse.linalg.lgmres`.
    lgmres_outer_k
        See :func:`scipy.sparse.linalg.lgmres`.
    least_squares_lsmr_damp
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_atol
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_btol
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_conlim
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_maxiter
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsmr_show
        See :func:`scipy.sparse.linalg.lsmr`.
    least_squares_lsqr_damp
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_atol
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_btol
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_conlim
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_iter_lim
        See :func:`scipy.sparse.linalg.lsqr`.
    least_squares_lsqr_show
        See :func:`scipy.sparse.linalg.lsqr`.
    pyamg_tol
        Tolerance for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_maxiter
        Maximum iterations for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_verb
        Verbosity flag for `PyAMG <http://pyamg.github.io/>`_ blackbox solver.
    pyamg_rs_strength
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_CF
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_presmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_postsmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_max_levels
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_max_coarse
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_coarse_solver
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_cycle
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_accel
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_tol
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_rs_maxiter
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Ruge-Stuben solver.
    pyamg_sa_symmetry
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_strength
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_aggregate
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_smooth
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_presmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_postsmoother
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_improve_candidates
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_max_levels
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_max_coarse
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_diagonal_dominance
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_coarse_solver
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_cycle
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_accel
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_tol
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.
    pyamg_sa_maxiter
        Parameter for `PyAMG <http://pyamg.github.io/>`_ Smoothed-Aggregation solver.

    Returns
    -------
    A tuple of all possible |solver_options|.
    """

    assert default_least_squares_solver.startswith('least_squares')

    opts = (('bicgstab_spilu', {
        'type': 'bicgstab_spilu',
        'tol': bicgstab_tol,
        'maxiter': bicgstab_maxiter,
        'spilu_drop_tol': spilu_drop_tol,
        'spilu_fill_factor': spilu_fill_factor,
        'spilu_drop_rule': spilu_drop_rule,
        'spilu_permc_spec': spilu_permc_spec
    }), ('bicgstab', {
        'type': 'bicgstab',
        'tol': bicgstab_tol,
        'maxiter': bicgstab_maxiter
    }), ('spsolve', {
        'type': 'spsolve',
        'permc_spec': spsolve_permc_spec,
        'keep_factorization': spsolve_keep_factorization
    }), ('lgmres', {
        'type': 'lgmres',
        'tol': lgmres_tol,
        'maxiter': lgmres_maxiter,
        'inner_m': lgmres_inner_m,
        'outer_k': lgmres_outer_k
    }), ('least_squares_lsqr', {
        'type': 'least_squares_lsqr',
        'damp': least_squares_lsqr_damp,
        'atol': least_squares_lsqr_atol,
        'btol': least_squares_lsqr_btol,
        'conlim': least_squares_lsqr_conlim,
        'iter_lim': least_squares_lsqr_iter_lim,
        'show': least_squares_lsqr_show
    }))

    if HAVE_SCIPY_LSMR:
        opts += (('least_squares_lsmr', {
            'type': 'least_squares_lsmr',
            'damp': least_squares_lsmr_damp,
            'atol': least_squares_lsmr_atol,
            'btol': least_squares_lsmr_btol,
            'conlim': least_squares_lsmr_conlim,
            'maxiter': least_squares_lsmr_maxiter,
            'show': least_squares_lsmr_show
        }), )

    if HAVE_PYAMG:
        opts += (('pyamg', {
            'type': 'pyamg',
            'tol': pyamg_tol,
            'maxiter': pyamg_maxiter
        }), ('pyamg-rs', {
            'type': 'pyamg-rs',
            'strength': pyamg_rs_strength,
            'CF': pyamg_rs_CF,
            'presmoother': pyamg_rs_presmoother,
            'postsmoother': pyamg_rs_postsmoother,
            'max_levels': pyamg_rs_max_levels,
            'max_coarse': pyamg_rs_max_coarse,
            'coarse_solver': pyamg_rs_coarse_solver,
            'cycle': pyamg_rs_cycle,
            'accel': pyamg_rs_accel,
            'tol': pyamg_rs_tol,
            'maxiter': pyamg_rs_maxiter
        }), ('pyamg-sa', {
            'type': 'pyamg-sa',
            'symmetry': pyamg_sa_symmetry,
            'strength': pyamg_sa_strength,
            'aggregate': pyamg_sa_aggregate,
            'smooth': pyamg_sa_smooth,
            'presmoother': pyamg_sa_presmoother,
            'postsmoother': pyamg_sa_postsmoother,
            'improve_candidates': pyamg_sa_improve_candidates,
            'max_levels': pyamg_sa_max_levels,
            'max_coarse': pyamg_sa_max_coarse,
            'diagonal_dominance': pyamg_sa_diagonal_dominance,
            'coarse_solver': pyamg_sa_coarse_solver,
            'cycle': pyamg_sa_cycle,
            'accel': pyamg_sa_accel,
            'tol': pyamg_sa_tol,
            'maxiter': pyamg_sa_maxiter
        }))
    opts = OrderedDict(opts)
    opts.update(genericsolvers.options())
    def_opt = opts.pop(default_solver)
    if default_least_squares_solver != default_solver:
        def_ls_opt = opts.pop(default_least_squares_solver)
        ordered_opts = OrderedDict(
            ((default_solver, def_opt), (default_least_squares_solver,
                                         def_ls_opt)))
    else:
        ordered_opts = OrderedDict(((default_solver, def_opt), ))
    ordered_opts.update(opts)
    return ordered_opts