[cig-commits] r6185 - in short/3D/PyLith/branches/pylith-0.8: . pylith3d/pylith3d

leif at geodynamics.org leif at geodynamics.org
Wed Mar 7 16:12:10 PST 2007


Author: leif
Date: 2007-03-07 16:12:09 -0800 (Wed, 07 Mar 2007)
New Revision: 6185

Removed:
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/PetscUtil.py
Modified:
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_run.py
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py
   short/3D/PyLith/branches/pylith-0.8/setup.py
Log:
Removed support for .keyval files (this is a bit premature, since I
still haven't finished updating the examples).

Moved PETSc/Pyre integration stuff into the framework.  PyLith v0.8
now requires Pythia v0.8.1.3b1.  Re-run 'configure' to get it.


Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py	2007-03-07 22:00:39 UTC (rev 6184)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py	2007-03-08 00:12:09 UTC (rev 6185)
@@ -29,19 +29,29 @@
 #
 
 
-from mpi.Application import Application as BaseApplication
+from cig.cs.petsc import PetscApplication
 
 
-class Application(BaseApplication):
+class Application(PetscApplication):
 
 
+    name = "pylith3d"
+
+
+    # Tell the framework where to find PETSc functions.
+    import pylith3d as petsc
+
+
+    # Use PETSc-style command line parsing.
+    from cig.cs.petsc import PetscCommandlineParser as CommandlineParser
+
+
     def main(self, *args, **kwds):
     
 #        from time import clock as now
 #        start = now()
         pl3dsetup = self.inventory.setup
         import pylith3d
-        pylith3d.PetscInitialize(self.petscArgs)
 
         scanner = self.inventory.scanner
 
@@ -71,79 +81,29 @@
         return
 
 
-    def __init__(self, name="pylith3d"):
-        BaseApplication.__init__(self, name)
-        return
+    class Inventory(PetscApplication.Inventory):
 
-
-    def _configure(self):
-        import sys
-        
-        self.petscArgs = [sys.executable]
-        
-        ksp_monitor = self.inventory.ksp_monitor
-        if ksp_monitor:
-            self.petscArgs.append("-ksp_monitor")
-            if ksp_monitor != "true":
-                self.petscArgs.append(ksp_monitor)
-        
-        if self.inventory.ksp_view:
-            self.petscArgs.append("-ksp_view")
-        
-        ksp_rtol = self.inventory.ksp_rtol
-        if ksp_rtol:
-            self.petscArgs.extend(["-ksp_rtol", ksp_rtol])
-        
-        if self.inventory.log_summary:
-            self.petscArgs.append("-log_summary")
-
-        pc_type = self.inventory.pc_type
-        sub_pc_type = self.inventory.sub_pc_type
-        self.petscArgs.extend(["-pc_type", pc_type, "-sub_pc_type", sub_pc_type])
-
-        if self.inventory.start_in_debugger:
-            self.petscArgs.append("-start_in_debugger")
-
-        debugger_pause = self.inventory.debugger_pause
-        if debugger_pause:
-            self.petscArgs.extend(["-debugger_pause", debugger_pause])
-
-        self.petscArgs.extend(self.inventory.petsc.getArgs())
-
-        return
-
-
-    def createCommandlineParser(self):
-        from PetscUtil import PetscCommandlineParser
-        return PetscCommandlineParser()
-
-
-    class Inventory(BaseApplication.Inventory):
-
         import pyre.inventory
+        from cig.cs.petsc import PetscProperty
         from Pylith3d_scan import Pylith3d_scan
         from Pylith3d_setup import Pylith3d_setup
         from Pylith3d_run import Pylith3d_run
-        from PetscUtil import PetscFacility
 
         scanner = pyre.inventory.facility("scanner", factory=Pylith3d_scan)
         setup = pyre.inventory.facility("setup", factory=Pylith3d_setup)
         solver = pyre.inventory.facility("solver", factory=Pylith3d_run)
 
         # declare PETSc options that are of interest to PyLith
-        ksp_monitor = pyre.inventory.str("ksp_monitor")
-        ksp_view = pyre.inventory.bool("ksp_view")
-        ksp_rtol = pyre.inventory.str("ksp_rtol")
-        log_summary = pyre.inventory.bool("log_summary")
-        pc_type = pyre.inventory.str("pc_type")
-        sub_pc_type = pyre.inventory.str("sub_pc_type")
-        start_in_debugger = pyre.inventory.str("start_in_debugger")
-        debugger_pause = pyre.inventory.str("debugger_pause")
+        ksp_monitor        = PetscProperty()
+        ksp_view           = PetscProperty()
+        ksp_rtol           = PetscProperty()
+        log_summary        = PetscProperty()
+        pc_type            = PetscProperty()
+        sub_pc_type        = PetscProperty()
+        start_in_debugger  = PetscProperty()
+        debugger_pause     = PetscProperty()
 
-        # a dummy facility for passing arbitrary options to PETSc
-        petsc = PetscFacility("petsc")
 
-
 # version
 # $Id: Application.py,v 1.5 2005/04/15 00:18:21 willic3 Exp $
 

Deleted: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/PetscUtil.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/PetscUtil.py	2007-03-07 22:00:39 UTC (rev 6184)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/PetscUtil.py	2007-03-08 00:12:09 UTC (rev 6185)
@@ -1,162 +0,0 @@
-#!/usr/bin/env python
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-#  PyLith by Charles A. Williams, Brad Aagaard, and Matt Knepley
-#
-#  Copyright (c) 2004-2006 Rensselaer Polytechnic Institute
-#
-#  Permission is hereby granted, free of charge, to any person obtaining
-#  a copy of this software and associated documentation files (the
-#  "Software"), to deal in the Software without restriction, including
-#  without limitation the rights to use, copy, modify, merge, publish,
-#  distribute, sublicense, and/or sell copies of the Software, and to
-#  permit persons to whom the Software is furnished to do so, subject to
-#  the following conditions:
-#
-#  The above copyright notice and this permission notice shall be
-#  included in all copies or substantial portions of the Software.
-#
-#  THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
-#  EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
-#  MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
-#  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-#  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-#  OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
-#  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#
-
-
-from pyre.applications.CommandlineParser import CommandlineParser
-
-
-class PetscCommandlineParser(CommandlineParser):
-    """A parser which mimics PETSc's command line processing."""
-
-    # The logic used here is derived from the 'while' loop at the end
-    # of PetscOptionsInsert().  However, this doesn't check for "bad"
-    # MPICH options, as these should have been removed by MPI_Init().
-
-
-    def _parse(self, argv, root):
-        
-        self.action = None
-        self.argv = argv
-        self.processed = []
-        self.unprocessed = []
-        
-        while self.argv:
-            
-            arg = self.argv.pop(0)
-            
-            iname = self._filterNonOptionArgument(arg)
-            if iname is None:
-                continue
-            
-            if iname.lower() == "options_file":
-                # NYI
-                if self.argv:
-                    filename = self.argv.pop(0)
-                else:
-                    pass # error
-                continue
-
-            if (not self.argv) or self._isOptionArgument(self.argv[0]):
-                iname, value = self._parseArgument(iname)
-            else:
-                value = self.argv.pop(0)
-
-            self._processArgument(iname, value, root)
-
-        return
-
-
-    def _optionPrefix(self, arg):
-        for prefix in self.prefixes:
-            if arg.startswith(prefix):
-                return prefix
-        return None
-
-
-    def _isOptionArgument(self, arg):
-        import string
-        prefix = self._optionPrefix(arg)
-        if prefix is not None:
-            candidate = arg[len(prefix):]
-            if (prefix == "-" and
-                len(candidate) > 0 and
-                candidate[0] in string.digits):
-                return False
-            return True
-        return False
-
-
-    def _filterNonOptionArgument(self, arg):
-        
-        prefix = self._optionPrefix(arg)
-        
-        if prefix is not None:
-            self._debug.line("    prefix: '%s starts with '%s'" % (arg, prefix))
-            candidate = arg[len(prefix):]
-            return candidate
-        
-        # prefix matching failed; leave this argument alone
-        self._debug.line("    prefix: '%s' is not an option" % arg)
-        self.processed.append(arg)
-        return None
-
-
-
-from pyre.components import Component
-
-
-class Petsc(Component):
-
-
-    def updateConfiguration(self, registry):
-        self.options = [
-            (name, descriptor.value) for name, descriptor in registry.properties.iteritems()
-            ]
-        return []
-
-
-    def getArgs(self):
-        args = []
-        for iname, value in self.options:
-            args.append('-' + iname)
-            if value != 'true':
-                args.append(value)
-        return args
-
-
-    def __init__(self, name):
-        Component.__init__(self, name, name)
-        self.options = []
-        return
-
-
-
-from pyre.inventory.Facility import Facility
-
-
-class PetscFacility(Facility):
-
-
-    def __init__(self, name):
-        Facility.__init__(self, name=name, factory=Petsc, args=[name])
-        return
-
-
-    def _retrieveComponent(self, instance, componentName):
-        petsc = Petsc(componentName)
-
-        import pyre.parsing.locators
-        locator = pyre.parsing.locators.simple('built-in')
-
-        return petsc, locator
-
-
-
-# End of file 

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_run.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_run.py	2007-03-07 22:00:39 UTC (rev 6184)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_run.py	2007-03-08 00:12:09 UTC (rev 6185)
@@ -650,7 +650,6 @@
                     self.viscousStage,                                 # PETSc logging
                     self.iterateEvent)
         pylith3d.destroyPETScMat(self.A,self.rhs,self.sol)
-        pylith3d.PetscFinalize()
 
         self.trace.log("Hello from pl3drun.run (end)!")
         

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py	2007-03-07 22:00:39 UTC (rev 6184)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Pylith3d_scan.py	2007-03-08 00:12:09 UTC (rev 6185)
@@ -49,19 +49,20 @@
         return
 
 
-    def configureProperties(self, context):
-        """set the values of all the properties and facilities in my inventory"""
+    def _configure(self):
 
+        super(Pylith3d_scan, self)._configure()
+
+        # Help is currently broken.  With this ugly hack, it at least
+        # works for the scanner.
+        if self._helpRequested:
+            return
+        # This method also breaks tab completion :-(
+
         #
-        # First, configure my properties as defined by the framework.
+        # Open input files.  Log I/O errors.
         #
         
-        super(Pylith3d_scan, self).configureProperties(context)
-        
-        #
-        # Second, open input files.  Log I/O errors.
-        #
-        
         self._summaryIOError = self.CanNotOpenInputOutputFilesError()
 
         inputFile = self.inputFile
@@ -99,18 +100,6 @@
         self._differentialForceInputFile  = inputFile(Inventory.differentialForceInputFile,  unused)
         self._slipperyWinklerInputFile    = inputFile(Inventory.slipperyWinklerInputFile,    unused)
 
-        def openKeywordEqualsValueFile(filename, flags, mode):
-            from CodecKeyVal import CodecKeyVal
-            from os.path import splitext
-            base, ext = splitext(filename)
-            assert ext == ".keyval"
-            codec = CodecKeyVal()
-            shelf = codec.open(base, mode)
-            return shelf
-        
-        self._keywordEqualsValueFile      = inputFileStream(Inventory.keywordEqualsValueFile, optional,
-                                                            opener=openKeywordEqualsValueFile)
-
         # The call to glob() is somewhat crude -- basically, determine
         # if any files might be in the way.
         self._ucdOutputRoot               = macroString(Inventory.ucdOutputRoot)
@@ -138,31 +127,7 @@
             import sys
             sys.exit("%s: configuration error(s)" % self.name)
 
-        #
-        # Third, read the data from the .keyval file -- potentially
-        # reconfiguring some of my properties.
-        #
-        
-        if self._keywordEqualsValueFile:
-            registry = self._keywordEqualsValueFile['inventory']
-            registry = registry.getFacility("pylith3d")
-            registry = registry.getFacility("scanner")
-            if registry:
-                # Transfer .keyval input to my private registry...
-                self.updateConfiguration(registry)
-                # ..and from there to my inventory.
-                self.inventory.configureProperties(context)
 
-        #
-        # Finally, decorate any missing traits with my name.
-        #
-        
-        self._claim(context)
-
-        return
-
-
-    def _configure(self):
         # get values for extra input (category 2)
 
         self.winklerScaleX = self.inventory.winklerScaleX
@@ -678,15 +643,12 @@
             }
         return expandMacros(descriptor.value, InventoryAdapter(self.inventory, builtins))
 
-    def ioFileStream(self, trait, flags, mode, category, opener=None):
+    def ioFileStream(self, trait, flags, mode, category):
         value = self.macroString(trait)
         stream = None
         if category.tryOpen:
             try:
-                if opener is None:
-                    stream = os.fdopen(os.open(value, flags), mode)
-                else:
-                    stream = opener(value, flags, mode)
+                stream = os.fdopen(os.open(value, flags), mode)
             except (OSError, IOError), error:
                 descriptor = self.inventory.getTraitDescriptor(trait.name)
                 self._summaryIOError.openFailed(trait, descriptor, value, error, category)
@@ -698,8 +660,8 @@
             stream.close()
         return value
     
-    def inputFileStream(self, trait, category, opener=None):
-        return self.ioFileStream(trait, os.O_RDONLY, "r", category, opener=opener)[1]
+    def inputFileStream(self, trait, category):
+        return self.ioFileStream(trait, os.O_RDONLY, "r", category)[1]
     
     def outputFile(self, trait, category):
         value, stream = self.ioFileStream(trait, os.O_WRONLY|os.O_CREAT|os.O_EXCL, "w", category)
@@ -763,9 +725,6 @@
         fullOutputInputFile.meta['tip'] = "Pathname for file defining when to provide output (overrides default from inputFileRoot)."
 
         # Optional input files.
-        keywordEqualsValueFile = InputFile("keywordEqualsValueFile",default="${inputFileRoot}.keyval")
-        keywordEqualsValueFile.meta['tip'] = "Pathname for keyword = value file (overrides default from inputFileRoot)."
-
         winklerInputFile = InputFile("winklerInputFile",default="${inputFileRoot}.wink")
         winklerInputFile.meta['tip'] = "Pathname for Winkler force input file (overrides default from inputFileRoot)."
 

Modified: short/3D/PyLith/branches/pylith-0.8/setup.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/setup.py	2007-03-07 22:00:39 UTC (rev 6184)
+++ short/3D/PyLith/branches/pylith-0.8/setup.py	2007-03-08 00:12:09 UTC (rev 6185)
@@ -14,9 +14,7 @@
     packages = find_packages("pylith3d"),
     
     install_requires = [
-    'pythia[mpi] >= 0.8.1.0, < 0.8.2a',
-    #'numpy',
-    #'mercurial',
+    'pythia[mpi] >= 0.8.1.3b1, < 0.8.2a',
     ],
 
     author = 'Charles A. Williams, Brad Aagaard, and Matt Knepley',
@@ -25,4 +23,9 @@
     license = 'other',
     url = 'http://www.geodynamics.org/cig/software/packages/short/pylith/',
 
+    # temporary
+    dependency_links = [
+    'http://crust.geodynamics.org/~leif/shipping/',
+    ]
+
 )



More information about the cig-commits mailing list