Esempio n. 1
0
def _parallelImport():
    try:
        import scipy
    except:
        pass

    from PyTrilinos import Epetra

    import platform
    if platform.dist()[0] == 'debian':
        import PyTrilinos
        if '10.0.4' in PyTrilinos.version():
            try:
                from mpi4py import MPI
            except ImportError:
                raise Exception("Could not import mpi4py. The package mpi4py is a required package if you are using Trilinos on a Debian platform with Trilinos version 10.0.4 due to a Trilinos bug (see <http://matforge.org/fipy/ticket/420>). Try installing using 'easy_install mpi4py'.")

    from fipy.tools.comms.commWrapper import ParallelCommWrapper
    parallelComm = ParallelCommWrapper(Epetra=Epetra)

    if parallelComm.Nproc > 1:

        try:
            from mpi4py import MPI
            from fipy.tools.comms.mpi4pyCommWrapper import Mpi4pyCommWrapper
            parallelComm = Mpi4pyCommWrapper(Epetra=Epetra, MPI=MPI)
        except ImportError:
            raise ImportError("Could not import mpi4py. The package mpi4py is a required package if you are using Trilinos in parallel. Try installing using 'easy_install mpi4py'.")

    from fipy.tools.comms.serialCommWrapper import SerialCommWrapper
    return SerialCommWrapper(Epetra=Epetra), parallelComm
Esempio n. 2
0
def _parallelImport():
    try:
        import scipy
    except:
        pass

    from PyTrilinos import Epetra

    import platform
    if platform.dist()[0] == 'debian':
        import PyTrilinos
        if '10.0.4' in PyTrilinos.version():
            try:
                from mpi4py import MPI
            except ImportError:
                raise Exception(
                    "Could not import mpi4py. The package mpi4py is a required package if you are using Trilinos on a Debian platform with Trilinos version 10.0.4 due to a Trilinos bug (see <https://github.com/usnistgov/fipy/issues/301>). Try installing using 'easy_install mpi4py'."
                )

    from fipy.tools.comms.commWrapper import ParallelCommWrapper
    parallelComm = ParallelCommWrapper(Epetra=Epetra)

    if parallelComm.Nproc > 1:

        try:
            from mpi4py import MPI
            from fipy.tools.comms.mpi4pyCommWrapper import Mpi4pyCommWrapper
            parallelComm = Mpi4pyCommWrapper(Epetra=Epetra, MPI=MPI)
        except ImportError:
            raise ImportError(
                "Could not import mpi4py. The package mpi4py is a required package if you are using Trilinos in parallel. Try installing using 'easy_install mpi4py'."
            )

    from fipy.tools.comms.serialCommWrapper import SerialCommWrapper
    return SerialCommWrapper(Epetra=Epetra), parallelComm
Esempio n. 3
0
    def printPackageInfo(self):

        for pkg in [
                'fipy', 'numpy', 'pysparse', 'scipy', 'matplotlib', 'mpi4py',
                'pyamgx'
        ]:

            try:
                mod = __import__(pkg)

                if hasattr(mod, '__version__'):
                    print(pkg, 'version', mod.__version__)
                else:
                    print(pkg, 'version not available')

            except ImportError as e:
                print(pkg, 'is not installed')

            except Exception as e:
                print(pkg, 'version check failed:', e)

        ## PyTrilinos
        try:
            import PyTrilinos
            print(PyTrilinos.version())
        except ImportError as e:
            print('PyTrilinos is not installed')
        except Exception as e:
            print('PyTrilinos version check failed:', e)

        ## Mayavi uses a non-standard approach for storing its version number.
        try:
            from mayavi.__version__ import __version__ as mayaviversion
            print('mayavi version', mayaviversion)
        except ImportError as e:
            try:
                from enthought.mayavi.__version__ import __version__ as mayaviversion
                print('enthought.mayavi version', mayaviversion)
            except ImportError as e:
                print('enthought.mayavi is not installed')
            except Exception as e:
                print('enthought.mayavi version check failed:', e)
        except Exception as e:
            print('mayavi version check failed:', e)

        ## Gmsh version
        try:
            from fipy.meshes.gmshMesh import gmshVersion
            gmshversion = gmshVersion()
            if gmshversion is None:
                print('gmsh is not installed')
            else:
                print('gmsh version', gmshversion)
        except Exception as e:
            print('gmsh version check failed:', e)
Esempio n. 4
0
    def printPackageInfo(self):

        for pkg in ['fipy', 'numpy', 'pysparse', 'scipy', 'matplotlib', 'mpi4py', 'pyamgx']:

            try:
                mod = __import__(pkg)

                if hasattr(mod, '__version__'):
                    print(pkg, 'version', mod.__version__)
                else:
                    print(pkg, 'version not available')

            except ImportError as e:
                print(pkg, 'is not installed')

            except Exception as e:
                print(pkg, 'version check failed:', e)

        ## PyTrilinos
        try:
            import PyTrilinos
            print(PyTrilinos.version())
        except ImportError as e:
            print('PyTrilinos is not installed')
        except Exception as e:
            print('PyTrilinos version check failed:', e)

        ## Mayavi uses a non-standard approach for storing its version number.
        try:
            from mayavi.__version__ import __version__ as mayaviversion
            print('mayavi version', mayaviversion)
        except ImportError as e:
            try:
                from enthought.mayavi.__version__ import __version__ as mayaviversion
                print('enthought.mayavi version', mayaviversion)
            except ImportError as e:
                print('enthought.mayavi is not installed')
            except Exception as e:
                print('enthought.mayavi version check failed:', e)
        except Exception as e:
            print('mayavi version check failed:', e)

        ## Gmsh version
        try:
            from fipy.meshes.gmshMesh import gmshVersion
            gmshversion = gmshVersion()
            if gmshversion is None:
                print('gmsh is not installed')
            else:
                print('gmsh version', gmshversion)
        except Exception as e:
            print('gmsh version check failed:', e)
Esempio n. 5
0
def _dealWithTrilinosImportPathologies():
    ## The import scipy statement is added to allow PyTrilinos to run
    ## without throwing a segmentation fault. This is caused by weird
    ## behavior in scipy and PyTrilinos depending on the order in which
    ## modules are imported

    try:
        import scipy
    except:
        pass

    # The fact that I have to do the following manipulation with the current
    # directory is really, really bad.
    import os
    current_working_directory_path = os.getcwd()
    from PyTrilinos import ML  # Gets around strange Trilinos import-order bugs.
    os.chdir(current_working_directory_path)
    # When run in MPI mode, the first Trilinos import makes the "current
    # directory" be the directory with the executable file that's being
    # run.  As best I can tell, this happens in MPI_Init, deep in Trilinos.
    # Possibly because "current directory" not well-defined in MPI between
    # processors?

    # This fix relies on this being the FIRST place to import any Trilinos
    # module.  The only way to import Trilinos things should be to do
    # `from fipy.solvers import *` and have it automatically import Trilinos
    # via this file.

    from PyTrilinos import Epetra

    import platform
    if platform.dist()[0] == 'debian':
        import PyTrilinos
        if '10.0.4' in PyTrilinos.version():
            # The package mpi4py is a required package if you are using
            # Trilinos on a Debian platform with Trilinos version 10.0.4 due to
            # a Trilinos bug (see <https://github.com/usnistgov/fipy/issues/301>).

            from mpi4py import MPI
Esempio n. 6
0
    def printPackageInfo(self):
        packages = ['python']
        versions = [sys.version.replace('\n', '| ')]

        for pkg in ['fipy', 'numpy', 'pysparse', 'scipy', 'matplotlib', 'mpi4py', 'petsc4py', 'pyamgx']:
            packages.append(pkg)

            try:
                mod = __import__(pkg)

                versions.append(mod.__version__)
            except ImportError as e:
                versions.append('not installed')

            except Exception as e:
                versions.append('version check failed: {}'.format(e))

        ## PyTrilinos
        packages.append('PyTrilinos')
        try:
            import PyTrilinos
            versions.append(PyTrilinos.version())
        except ImportError as e:
            versions.append('not installed')
        except Exception as e:
            versions.append('version check failed: {}'.format(e))

        ## Mayavi uses a non-standard approach for storing its version number.
        packages.append('mayavi')
        try:
            from mayavi.__version__ import __version__ as mayaviversion
            versions.append(mayaviversion)
        except ImportError as e:
            try:
                from enthought.mayavi.__version__ import __version__ as mayaviversion
                versions.append(mayaviversion)
            except ImportError as e:
                versions.append('not installed')
        except Exception as e:
            versions.append('version check failed: {}'.format(e))

        ## Gmsh version
        packages.append('gmsh')
        try:
            from fipy.meshes.gmshMesh import gmshVersion
            gmshversion = gmshVersion()
            if gmshversion is None:
                versions.append('not installed')
            else:
                versions.append(gmshversion)
        except Exception as e:
            versions.append('version check failed: {}'.format(e))

        packages.append("solver")
        try:
            from fipy.solvers import solver
            versions.append(solver)
        except Exception as e:
            versions.append(str(e))

        print()
        package_width = max(len(word) for word in packages)
        for package, version in zip(packages, versions):
            print("  ".join((package.ljust(package_width), version)))
        print()
Esempio n. 7
0
def _TestClass(base):
    class _test(base):
        description = str(base.description) + ", for FiPy and its examples"

        # List of option tuples: long name, short name (None if no short
        # name), and help string.
        user_options = base.user_options + [
            ('inline', None, "run FiPy with inline compilation enabled"),
            ('pythoncompiled=', None,
             "directory in which to put weave's work product"),
            ('Trilinos', None, "run FiPy using Trilinos solvers"),
            ('Pysparse', None, "run FiPy using Pysparse solvers (default)"),
            ('trilinos', None, "run FiPy using Trilinos solvers"),
            ('pysparse', None, "run FiPy using Pysparse solvers (default)"),
            ('scipy', None, "run FiPy using SciPy solvers"),
            ('Scipy', None, "run FiPy using SciPy solvers"),
            ('no-pysparse', None,
             "run FiPy without using the Pysparse solvers"),
            ('pyamg', None, "run FiPy without using the PyAMG solvers"),
            ('all', None, "run all non-interactive FiPy tests (default)"),
            ('really-all', None,
             "run *all* FiPy tests (including those requiring user input)"),
            ('examples', None, "test FiPy examples"),
            ('modules', None, "test FiPy code modules"),
            ('viewers', None,
             "test FiPy viewer modules (requires user input)"),
            ('cache', None, "run FiPy with Variable caching"),
            ('no-cache', None, "run FiPy without Variable caching"),
            ('timetests=', None,
             "file in which to put time spent on each test"),
            ('skfmm', None,
             "run FiPy using the Scikit-fmm level set solver (default)"),
            ('lsmlib', None,
             "run FiPy using the LSMLIB level set solver (default)"),
        ]

        def initialize_options(self):
            base.initialize_options(self)

            self.all = False
            self.really_all = False
            self.examples = False
            self.modules = False
            self.viewers = False

            self.inline = False
            self.pythoncompiled = None
            self.cache = False
            self.no_cache = True
            self.Trilinos = False
            self.Pysparse = False
            self.trilinos = False
            self.pysparse = False
            self.no_pysparse = False
            self.pyamg = False
            self.scipy = False
            self.timetests = None
            self.skfmm = False
            self.lsmlib = False

        def finalize_options(self):
            noSuiteOrModule = (self.test_suite is None
                               and self.test_module is None)

            if noSuiteOrModule:
                # keep base.finalize_options() from adding things we don't want
                self.test_suite = "dummy"

            base.finalize_options(self)

            if noSuiteOrModule:
                # setuptools completely changed how it uses test_suite and test_args with v. 18.0
                # we do our best to keep it confused
                self.test_suite = None

            if not (self.examples or self.modules or self.viewers):
                self.all = True
            if self.all or self.really_all:
                self.examples = True
                self.modules = True
            if self.really_all:
                self.viewers = True

            # If we drop setuptools < 18.0, the remaining lines can probably be removed

            self.test_args = list(self._test_args())

            if noSuiteOrModule:
                # setuptools completely changed how it uses test_suite and test_args with v. 18.0
                # we do our best to keep it confused
                self.test_suite = "dummy"

        def _test_args(self):
            # can't seem to delegate a generator until Python 3.3

            if self.verbose:
                yield '--verbose'
            if self.test_suite:
                yield self.test_suite

            if self.viewers:
                print "*" * 60
                print "*" + "".center(58) + "*"
                print "*" + "ATTENTION".center(58) + "*"
                print "*" + "".center(58) + "*"
                print "*" + "Some of the following tests require user interaction".center(
                    58) + "*"
                print "*" + "".center(58) + "*"
                print "*" * 60

                yield "fipy.viewers.testinteractive._suite"
            if self.modules:
                yield "fipy.test._suite"
            if self.examples:
                yield "examples.test._suite"

        def printPackageInfo(self):

            for pkg in [
                    'fipy', 'numpy', 'pysparse', 'scipy', 'matplotlib', 'gist',
                    'mpi4py'
            ]:

                try:
                    mod = __import__(pkg)

                    if hasattr(mod, '__version__'):
                        print pkg, 'version', mod.__version__
                    else:
                        print pkg, 'version not available'

                except ImportError, e:
                    print pkg, 'is not installed'

                except Exception, e:
                    print pkg, 'version check failed:', e

            ## PyTrilinos
            try:
                import PyTrilinos
                print PyTrilinos.version()
            except ImportError, e:
                print pkg, 'is not installed'
Esempio n. 8
0
 #  
 # ###################################################################
 ##

try:
    import scipy
except:
    pass

try:

    from PyTrilinos import Epetra
    import platform
    if platform.dist()[0] == 'debian':
        import PyTrilinos
        if '10.0.4' in PyTrilinos.version():
            try:
                from mpi4py import MPI
            except ImportError:
                raise Exception("Could not import mpi4py. The package mpi4py is a required package if you are using Trilinos on a Debian platform with Trilinos version 10.0.4 due to a Trilinos bug (see <http://matforge.org/fipy/ticket/420>). Try installing using 'easy_install mpi4py'.")

    from fipy.tools.commWrapper import CommWrapper

    parallel = CommWrapper(Epetra=Epetra)

    if parallel.Nproc > 1:

        try:
            from mpi4py import MPI
            from fipy.tools.mpi4pyCommWrapper import Mpi4pyCommWrapper
            parallel = Mpi4pyCommWrapper(Epetra=Epetra, MPI=MPI)
Esempio n. 9
0
def _TestClass(base):
    class _test(base):
        description = str(base.description) + ", for FiPy and its examples"

        # List of option tuples: long name, short name (None if no short
        # name), and help string.
        user_options = base.user_options + [
            ('inline', None, "run FiPy with inline compilation enabled"),
            ('pythoncompiled=', None, "directory in which to put weave's work product"),
            ('Trilinos', None, "run FiPy using Trilinos solvers"),
            ('Pysparse', None, "run FiPy using Pysparse solvers (default)"),
            ('trilinos', None, "run FiPy using Trilinos solvers"),
            ('pysparse', None, "run FiPy using Pysparse solvers (default)"),
            ('scipy', None, "run FiPy using SciPy solvers"),
            ('Scipy', None, "run FiPy using SciPy solvers"),
            ('no-pysparse',None, "run FiPy without using the Pysparse solvers"),
            ('pyamg',None, "run FiPy without using the PyAMG solvers"),
            ('all', None, "run all non-interactive FiPy tests (default)"),
            ('really-all', None, "run *all* FiPy tests (including those requiring user input)"),
            ('examples', None, "test FiPy examples"),
            ('modules', None, "test FiPy code modules"),
            ('viewers', None, "test FiPy viewer modules (requires user input)"),
            ('cache', None, "run FiPy with Variable caching"),
            ('no-cache', None, "run FiPy without Variable caching"),
            ('timetests=', None, "file in which to put time spent on each test"),
            ('skfmm', None, "run FiPy using the Scikit-fmm level set solver (default)"),
            ('lsmlib', None, "run FiPy using the LSMLIB level set solver (default)"),
           ]


        def initialize_options(self):
            base.initialize_options(self)
            
            self.all = False
            self.really_all = False
            self.examples = False
            self.modules = False
            self.viewers = False
            
            self.inline = False
            self.pythoncompiled = None
            self.cache = False
            self.no_cache = True
            self.Trilinos = False
            self.Pysparse = False
            self.trilinos = False
            self.pysparse = False
            self.no_pysparse = False
            self.pyamg = False
            self.scipy = False
            self.timetests = None
            self.skfmm = False
            self.lsmlib = False

        def finalize_options(self):
            noSuiteOrModule = (self.test_suite is None 
                               and self.test_module is None)
                
            base.finalize_options(self)
            
            if noSuiteOrModule:
                self.test_args.remove(self.distribution.test_suite)
                
            if not (self.examples or self.modules or self.viewers):
                self.all = True
            if self.all or self.really_all:
                self.examples = True
                self.modules = True
            if self.really_all:
                self.viewers = True
            
                
            if self.viewers:
                print "*" * 60
                print "*" + "".center(58) + "*"
                print "*" + "ATTENTION".center(58) + "*"
                print "*" + "".center(58) + "*"
                print "*" + "Some of the following tests require user interaction".center(58) + "*"
                print "*" + "".center(58) + "*"
                print "*" * 60
                
                self.test_args.append("fipy.viewers.testinteractive._suite")

            if self.modules:
                self.test_args.append("fipy.test._suite")
            
            if self.examples:
                self.test_args.append("examples.test._suite")

            if self.test_args and noSuiteOrModule:
                self.test_suite = "dummy"


        def printPackageInfo(self):
            
            for pkg in ['fipy', 'numpy', 'pysparse', 'scipy', 'matplotlib', 'gist', 'mpi4py']:
                
                try:
                    mod = __import__(pkg)
                    
                    if hasattr(mod, '__version__'):
                        print pkg,'version',mod.__version__
                    else:
                        print pkg,'version not available'
                        
                except ImportError, e:
                    print pkg,'is not installed'
                    
                except Exception, e:
                    print pkg, 'version check failed:', e

            ## PyTrilinos
            try:
                import PyTrilinos
                print PyTrilinos.version()
            except ImportError, e:
                print pkg,'is not installed'
Esempio n. 10
0
                if hasattr(mod, '__version__'):
                    print pkg, 'version', mod.__version__
                else:
                    print pkg, 'version not available'

            except ImportError, e:
                print pkg, 'is not installed'

            except Exception, e:
                print pkg, 'version check failed:', e

        ## PyTrilinos
        try:
            import PyTrilinos
            print PyTrilinos.version()
        except ImportError, e:
            print 'PyTrilinos is not installed'
        except Exception, e:
            print 'PyTrilinos version check failed:', e

        ## Mayavi uses a non-standard approach for storing its version number.
        try:
            from mayavi.__version__ import __version__ as mayaviversion
            print 'mayavi version', mayaviversion
        except ImportError, e:
            try:
                from enthought.mayavi.__version__ import __version__ as mayaviversion
                print 'enthought.mayavi version', mayaviversion
            except ImportError, e:
                print 'enthought.mayavi is not installed'