def __init__( self, conf, **kwargs ): try: import petsc4py petsc4py.init([]) from petsc4py import PETSc except ImportError: msg = 'cannot import petsc4py!' raise ImportError( msg ) LinearSolver.__init__(self, conf, eps_a=conf.eps_a, eps_r=conf.eps_r, petsc=PETSc, pmtx=None, **kwargs) ksp = PETSc.KSP().create() ksp.setType( self.conf.method ) ksp.getPC().setType( self.conf.precond ) side = self._precond_sides[self.conf.precond_side] if side is not None: ksp.setPCSide(side) self.ksp = ksp self.converged_reasons = {} for key, val in ksp.ConvergedReason.__dict__.iteritems(): if isinstance(val, int): self.converged_reasons[val] = key
def __init__(self, conf, **kwargs): LinearSolver.__init__(self, conf, solve=None, **kwargs) um = self.sls = None aux = try_imports(['import scipy.linsolve as sls', 'import scipy.splinalg.dsolve as sls', 'import scipy.sparse.linalg.dsolve as sls'], 'cannot import scipy sparse direct solvers!') self.sls = aux['sls'] aux = try_imports(['import scipy.linsolve.umfpack as um', 'import scipy.splinalg.dsolve.umfpack as um', 'import scipy.sparse.linalg.dsolve.umfpack as um', 'import scikits.umfpack as um']) if 'um' in aux: um = aux['um'] if um is not None: is_umfpack = hasattr(um, 'UMFPACK_OK') else: is_umfpack = False method = self.conf.method if method == 'superlu': self.sls.use_solver(useUmfpack=False) elif method == 'umfpack': if not is_umfpack and self.conf.warn: output('umfpack not available, using superlu!') elif method != 'auto': raise ValueError('uknown solution method! (%s)' % method) if method != 'superlu' and is_umfpack: self.sls.use_solver(useUmfpack=True, assumeSortedIndices=True)
def __init__(self, conf, **kwargs): import sfepy.solvers.ls_mumps as mumps self.mumps_ls = None mumps.load_mumps_libraries() # try to load MUMPS libraries LinearSolver.__init__(self, conf, mumps=mumps, mumps_ls=None, mumps_presolved=False, **kwargs)
def __init__(self, conf, **kwargs): LinearSolver.__init__(self, conf, **kwargs) self.umfpack = None if self._presolve() and hasattr(self, "mtx"): if self.mtx is not None: family = Umfpack._family[self.mtx.dtype] self.umfpack = um.UmfpackContext(family=family) self.umfpack.numeric(self.mtx)
def __init__(self, conf, **kwargs): import multiprocessing import sfepy.solvers.ls_mumps as mumps mumps.load_mumps_libraries() # try to load MUMPS libraries LinearSolver.__init__(self, conf, mumps=mumps, mumps_ls=None, number_of_cpu=multiprocessing.cpu_count(), mumps_presolved=False, **kwargs)
def __init__(self, conf, **kwargs): try: import petsc4py petsc4py.init([]) from petsc4py import PETSc except ImportError: msg = 'cannot import petsc4py!' raise ImportError(msg) LinearSolver.__init__(self, conf, petsc=PETSc, pmtx=None, converged_reasons=None, **kwargs)
def __init__(self, conf, **kwargs): try: from mumps import DMumpsContext except ImportError: self.mumps = None msg = 'cannot import MUMPS!' raise ImportError(msg) LinearSolver.__init__(self, conf, **kwargs) self.mumps = DMumpsContext() self.mumps_presolved = False
def __init__(self, conf, **kwargs): import scipy.sparse.linalg.isolve as la LinearSolver.__init__(self, conf, **kwargs) try: solver = getattr(la, self.conf.method) except AttributeError: output("scipy solver %s does not exist!" % self.conf.method) output("using cg instead") solver = la.cg self.solver = solver self.converged_reasons = {0: "successful exit", 1: "number of iterations", -1: "illegal input or breakdown"}
def __init__(self, conf, comm=None, context=None, **kwargs): if comm is None: from sfepy.parallel.parallel import init_petsc_args; init_petsc_args from petsc4py import PETSc as petsc converged_reasons = {} for key, val in six.iteritems(petsc.KSP.ConvergedReason.__dict__): if isinstance(val, int): converged_reasons[val] = key LinearSolver.__init__(self, conf, petsc=petsc, comm=comm, converged_reasons=converged_reasons, fields=None, ksp=None, pmtx=None, context=context, **kwargs)
def __init__(self, conf, **kwargs): try: import pyamg except ImportError: msg = 'cannot import pyamg!' raise ImportError(msg) LinearSolver.__init__(self, conf, mg=None, **kwargs) try: solver = getattr(pyamg, self.conf.method) except AttributeError: output('pyamg.%s does not exist!' % self.conf.method) output('using pyamg.smoothed_aggregation_solver instead') solver = pyamg.smoothed_aggregation_solver self.solver = solver
def process_conf( conf ): """ 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 'eps_a' : 1e-12, # abstol 'eps_r' : 1e-12, # rtol 'i_max' : 1000, # maxits } """ get = conf.get_default_attr method = get( 'method', 'cg' ) precond = get( 'precond', 'icc' ) eps_a = get( 'eps_a', 1e-8 ) eps_r = get( 'eps_r', 1e-8 ) i_max = get( 'i_max', 100 ) common = LinearSolver.process_conf( conf ) return Struct( **locals() ) + 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_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_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_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 __init__(self, conf, context=None, **kwargs): import scipy.sparse.linalg.isolve as la LinearSolver.__init__(self, conf, context=context, **kwargs) try: solver = getattr(la, self.conf.method) except AttributeError: output('scipy solver %s does not exist!' % self.conf.method) output('using cg instead') solver = la.cg self.solver = solver self.converged_reasons = { 0 : 'successful exit', 1 : 'number of iterations', -1 : 'illegal input or breakdown', }
def __init__(self, conf, **kwargs): import scipy.sparse.linalg.isolve as la LinearSolver.__init__(self, conf, **kwargs) try: solver = getattr(la, self.conf.method) except AttributeError: output('scipy solver %s does not exist!' % self.conf.method) output('using cg instead') solver = la.cg self.solver = solver self.converged_reasons = { 0: 'successful exit', 1: 'number of iterations', -1: 'illegal input or breakdown', }
def __init__(self, conf, **kwargs): LinearSolver.__init__(self, conf, **kwargs) um = self.sls = None aux = try_imports( [ "import scipy.linsolve as sls", "import scipy.splinalg.dsolve as sls", "import scipy.sparse.linalg.dsolve as sls", ], "cannot import scipy sparse direct solvers!", ) self.sls = aux["sls"] aux = try_imports( [ "import scipy.linsolve.umfpack as um", "import scipy.splinalg.dsolve.umfpack as um", "import scipy.sparse.linalg.dsolve.umfpack as um", "import scikits.umfpack as um", ] ) if "um" in aux: um = aux["um"] if um is not None: is_umfpack = hasattr(um, "UMFPACK_OK") else: is_umfpack = False method = self.conf.method if method == "superlu": self.sls.use_solver(useUmfpack=False) elif method == "umfpack": if not is_umfpack and self.conf.warn: output("umfpack not available, using superlu!") elif method != "auto": raise ValueError("uknown solution method! (%s)" % method) if method != "superlu" and is_umfpack: self.sls.use_solver(useUmfpack=True, assumeSortedIndices=True) self.solve = None if self._presolve() and hasattr(self, "mtx"): if self.mtx is not None: self.solve = self.sls.factorized(self.mtx)
def __init__( self, conf, **kwargs ): if scipy.version.version < '0.7.0.dev3861': import scipy.linalg as la else: if scipy.version.version < '0.7.0.dev3998': import scipy.splinalg.isolve as la else: import scipy.sparse.linalg.isolve as la LinearSolver.__init__( self, conf, **kwargs ) try: solver = getattr( la, self.conf.method ) except AttributeError: output( 'scipy solver %s does not exist!' % self.conf.method ) output( 'using cg instead' ) solver = la.cg self.solver = solver
def __init__(self, conf, comm=None, **kwargs): if comm is None: try: import petsc4py petsc4py.init([]) except ImportError: msg = 'cannot import petsc4py!' raise ImportError(msg) from petsc4py import PETSc as petsc converged_reasons = {} for key, val in petsc.KSP.ConvergedReason.__dict__.iteritems(): if isinstance(val, int): converged_reasons[val] = key LinearSolver.__init__(self, conf, petsc=petsc, comm=comm, converged_reasons=converged_reasons, **kwargs)
def __init__(self, conf, comm=None, **kwargs): if comm is None: from sfepy.parallel.parallel import init_petsc_args init_petsc_args from petsc4py import PETSc as petsc converged_reasons = {} for key, val in six.iteritems(petsc.KSP.ConvergedReason.__dict__): if isinstance(val, int): converged_reasons[val] = key LinearSolver.__init__(self, conf, petsc=petsc, comm=comm, converged_reasons=converged_reasons, fields=None, **kwargs)
def __init__(self, conf, comm=None, **kwargs): if comm is None: try: import petsc4py petsc4py.init([]) except ImportError: msg = 'cannot import petsc4py!' raise ImportError(msg) from petsc4py import PETSc as petsc converged_reasons = {} for key, val in six.iteritems(petsc.KSP.ConvergedReason.__dict__): if isinstance(val, int): converged_reasons[val] = key LinearSolver.__init__(self, conf, petsc=petsc, comm=comm, converged_reasons=converged_reasons, fields=None, **kwargs)
def __init__(self, conf, **kwargs): try: import pyamg except ImportError: msg = "cannot import pyamg!" raise ImportError(msg) LinearSolver.__init__(self, conf, mg=None, **kwargs) try: solver = getattr(pyamg, self.conf.method) except AttributeError: output("pyamg.%s does not exist!" % self.conf.method) output("using pyamg.smoothed_aggregation_solver instead") solver = pyamg.smoothed_aggregation_solver self.solver = solver if hasattr(self, "mtx"): if self.mtx is not None: self.mg = self.solver(self.mtx)
def __init__(self, conf, **kwargs): try: import pyamg except ImportError: msg = 'cannot import pyamg!' raise ImportError(msg) LinearSolver.__init__(self, conf, mg=None, **kwargs) try: solver = getattr(pyamg, self.conf.method) except AttributeError: output('pyamg.%s does not exist!' % self.conf.method) output('using pyamg.smoothed_aggregation_solver instead') solver = pyamg.smoothed_aggregation_solver self.solver = solver if hasattr(self, 'mtx'): if self.mtx is not None: self.mg = self.solver(self.mtx)
def __init__(self, conf, context=None, **kwargs): try: import pyamg.krylov as krylov except ImportError: msg = 'cannot import pyamg.krylov!' raise ImportError(msg) LinearSolver.__init__(self, conf, mg=None, context=context, **kwargs) try: solver = getattr(krylov, self.conf.method) except AttributeError: output('pyamg.krylov.%s does not exist!' % self.conf.method) raise self.solver = solver self.converged_reasons = { 0: 'successful exit', 1: 'number of iterations', -1: 'illegal input or breakdown', }
def __init__(self, conf, **kwargs): LinearSolver.__init__(self, conf, **kwargs) um = self.sls = None aux = try_imports([ 'import scipy.linsolve as sls', 'import scipy.splinalg.dsolve as sls', 'import scipy.sparse.linalg.dsolve as sls' ], 'cannot import scipy sparse direct solvers!') self.sls = aux['sls'] aux = try_imports([ 'import scipy.linsolve.umfpack as um', 'import scipy.splinalg.dsolve.umfpack as um', 'import scipy.sparse.linalg.dsolve.umfpack as um', 'import scikits.umfpack as um' ]) if 'um' in aux: um = aux['um'] if um is not None: is_umfpack = hasattr(um, 'UMFPACK_OK') else: is_umfpack = False method = self.conf.method if method == 'superlu': self.sls.use_solver(useUmfpack=False) elif method == 'umfpack': if not is_umfpack and self.conf.warn: output('umfpack not available, using superlu!') elif method != 'auto': raise ValueError('uknown solution method! (%s)' % method) if method != 'superlu' and is_umfpack: self.sls.use_solver(useUmfpack=True, assumeSortedIndices=True) self.solve = None if self._presolve() and hasattr(self, 'mtx'): if self.mtx is not None: self.solve = self.sls.factorized(self.mtx)
def __init__(self, conf, context=None, **kwargs): try: import pyamg.krylov as krylov except ImportError: msg = 'cannot import pyamg.krylov!' raise ImportError(msg) LinearSolver.__init__(self, conf, mg=None, context=context, **kwargs) try: solver = getattr(krylov, self.conf.method) except AttributeError: output('pyamg.krylov.%s does not exist!' % self.conf.method) raise self.solver = solver self.converged_reasons = { 0 : 'successful exit', 1 : 'number of iterations', -1 : 'illegal input or breakdown', }
def __init__( self, conf, **kwargs ): try: import petsc4py petsc4py.init([]) from petsc4py import PETSc except ImportError: msg = 'cannot import petsc4py!' raise ImportError( msg ) LinearSolver.__init__( self, conf, petsc = PETSc, pmtx = None, **kwargs ) ksp = PETSc.KSP().create() ksp.setType( self.conf.method ) ksp.getPC().setType( self.conf.precond ) if hasattr( self, 'mtx' ): if self.mtx is not None: self.pmtx, self.sol, self.rhs = self.set_matrix( self.mtx ) ksp.setOperators( self.pmtx ) # set the matrix ksp.setFromOptions() self.ksp = ksp
def __init__(self, conf, method=None, **kwargs): LinearSolver.__init__(self, conf, solve=None, **kwargs) um = self.sls = None if method is None: method = self.conf.method aux = try_imports([ 'import scipy.linsolve as sls', 'import scipy.splinalg.dsolve as sls', 'import scipy.sparse.linalg.dsolve as sls' ], 'cannot import scipy sparse direct solvers!') if 'sls' in aux: self.sls = aux['sls'] else: raise ValueError('SuperLU not available!') if method in ['auto', 'umfpack']: aux = try_imports([ 'import scipy.linsolve.umfpack as um', 'import scipy.splinalg.dsolve.umfpack as um', 'import scipy.sparse.linalg.dsolve.umfpack as um', 'import scikits.umfpack as um' ]) is_umfpack = True if 'um' in aux\ and hasattr(aux['um'], 'UMFPACK_OK') else False if method == 'umfpack' and not is_umfpack: raise ValueError('UMFPACK not available!') elif method == 'superlu': is_umfpack = False else: raise ValueError('uknown solution method! (%s)' % method) if is_umfpack: self.sls.use_solver(useUmfpack=True, assumeSortedIndices=True) else: self.sls.use_solver(useUmfpack=False)
def __init__(self, conf, **kwargs): try: import petsc4py petsc4py.init([]) from petsc4py import PETSc except ImportError: msg = 'cannot import petsc4py!' raise ImportError(msg) LinearSolver.__init__(self, conf, petsc=PETSc, pmtx=None, **kwargs) ksp = PETSc.KSP().create() ksp.setType(self.conf.method) ksp.getPC().setType(self.conf.precond) side = self._precond_sides[self.conf.precond_side] if side is not None: ksp.setPCSide(side) self.ksp = ksp self.converged_reasons = {} for key, val in ksp.ConvergedReason.__dict__.iteritems(): if isinstance(val, int): self.converged_reasons[val] = key
def __init__(self, conf, method=None, **kwargs): LinearSolver.__init__(self, conf, solve=None, **kwargs) um = self.sls = None if method is None: method = self.conf.method aux = try_imports(['import scipy.linsolve as sls', 'import scipy.splinalg.dsolve as sls', 'import scipy.sparse.linalg.dsolve as sls'], 'cannot import scipy sparse direct solvers!') if 'sls' in aux: self.sls = aux['sls'] else: raise ValueError('SuperLU not available!') if method in ['auto', 'umfpack']: aux = try_imports([ 'import scipy.linsolve.umfpack as um', 'import scipy.splinalg.dsolve.umfpack as um', 'import scipy.sparse.linalg.dsolve.umfpack as um', 'import scikits.umfpack as um']) is_umfpack = True if 'um' in aux\ and hasattr(aux['um'], 'UMFPACK_OK') else False if method == 'umfpack' and not is_umfpack: raise ValueError('UMFPACK not available!') elif method == 'superlu': is_umfpack = False else: raise ValueError('uknown solution method! (%s)' % method) if is_umfpack: self.sls.use_solver(useUmfpack=True, assumeSortedIndices=True) else: self.sls.use_solver(useUmfpack=False)
def process_conf(conf): """ Missing items are set to default values. Example configuration, all items: solver_102 = { 'name' : 'ls102', 'kind' : 'ls.pyamg', 'method' : 'smoothed_aggregation_solver', 'eps_a' : 1e-12, } """ get = conf.get_default_attr method = get("method", "smoothed_aggregation_solver") eps_a = get("eps_a", 1e-8) common = LinearSolver.process_conf(conf) return Struct(**locals()) + 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): """ 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 = conf.get_default_attr method = get('method', 'auto') presolve = get('presolve', False) warn = get('warn', True) common = LinearSolver.process_conf(conf) return Struct(**locals()) + common
def process_conf( conf ): """ Missing items are set to default values. Example configuration, all items:: solver_110 = { 'name' : 'ls110', 'kind' : 'ls.scipy_iterative', 'method' : 'cg', 'i_max' : 1000, 'eps_a' : 1e-12, } """ get = conf.get_default_attr method = get( 'method', 'cg' ) i_max = get( 'i_max', 100 ) eps_a = get( 'eps_a', 1e-8 ) common = LinearSolver.process_conf( conf ) return Struct( **locals() ) + common