ometah-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oMetah-devel] ometah/experiment metahtest.py interface.py


From: Jean-Philippe Aumasson
Subject: [oMetah-devel] ometah/experiment metahtest.py interface.py
Date: Thu, 09 Jun 2005 08:43:21 -0400

CVSROOT:        /cvsroot/ometah
Module name:    ometah
Branch:         
Changes by:     Jean-Philippe Aumasson <address@hidden> 05/06/09 12:43:21

Modified files:
        experiment     : metahtest.py 
Added files:
        experiment     : interface.py 

Log message:
        * many changes...

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/experiment/interface.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/ometah/ometah/experiment/metahtest.py.diff?tr1=1.8&tr2=1.9&r1=text&r2=text

Patches:
Index: ometah/experiment/metahtest.py
diff -u ometah/experiment/metahtest.py:1.8 ometah/experiment/metahtest.py:1.9
--- ometah/experiment/metahtest.py:1.8  Tue Jun  7 15:34:33 2005
+++ ometah/experiment/metahtest.py      Thu Jun  9 12:43:20 2005
@@ -31,16 +31,43 @@
 
 TODO
 ------
+W = WIP
+D = Done
+P = Problem
+------
 
 TD histogramme 3D ?? transfo Xdim en 1 ou 2 dim...
 
-WIP.. fonctions 'plotAutrechosequedistribution (listOfPoints)'
+W Organisation fichiers (arborescence ? noms fichiers ? clé/ID unique ? ..?)
 
-WIP.. Exceptions ! Errors in log !
+Interface pour N runs, en plottant le nécessaire à chaque fois...
+1000 < N < 100 000
 
-Nommer fichiers en fx du problème...(à partir de l'instance de Header, crée à 
partir du header XML..)
+D renommer fonctions de plot selon les conventions
+
+P [déjà bcp de methodes, redondances dans les noms..] interface plus simple 
pour lancer un plottage
+
+D garder la sortie XML dans un fichier, et possibilité de parser à partir d'un 
fichier et non une sortie de ometah
+(=> pour plot sans lancement de ometah)
+
+D setBitmap & co comme méthodes d'interface, et noms de fichiers par défaut 
(nom pb, etc...)
+
+récupérer infos sur le problème à partir du header XML, et instancier un 
Header à remplir selon les vars parsées
+
+plottage de distribution : distrib pour chaque iteration, et pas pour 
l'ensemble...superposition des distributions ?
+
+W  modulariser le prog
+
+D création d'un répertoire pour placer les sortie, methode dans Interface pour 
fixer le path, et pour le nom de fichier par défaut
+
+D add function name in error logs
+
+D renommage fichiers de sortie, copiés dans un répertoire donné (ou pas)
+
+D attributs __path et __defaultfilename dans l'Interface
+
+privater les méthodes non publiques ( add __ )
 
-Organisation fichiers (arborescence ? noms fichiers ? clé/ID unique ? ..?)
 
 /----
 
@@ -60,116 +87,30 @@
 fonctions statistiques :
 r.sd(list) (standard deviation)
 r.var(list) (variance)
+r.median(list) (mediane)
 
+conventions pour le nommage des fonctions de plot :
 
-"""
+plot +
+[valeur source : value, solutions] +
+[domaine : iteration, optimum ] +
+[valeur plottée : distribution, std, mean ...] +
+[modèle affiché : histogramme, boxes ...]
+
+model :
+main has an interface (interface.Interface)
+XMLParser gives a Header an a list of Points
+interface plots the lists of Points
+Interface has NOT Header or Points...
+H & P given by XMLParser to main, which use their data in Interface
 
-import os
-import sys
-import time
-import string
-from rpy import *
-import datetime
+code performance tips :
+http://www.szgti.bmf.hu/harp/python/fastpython.html
 
 
-def setPostscriptOutput(filename):
-    """  set a postscript output file """
-    r.postscript(filename, paper='letter')
-
-def setBitmapOutput(filename):
-    """ set a bitmap (png) output file """
-    r.bitmap(filename, res=150)
-
-def datedFileName(name, extension):
-    """ return a string of today's date + given string """
-    s = datetime.date.today().isoformat()
-    return name + s + extension
-
-
-class Interface:
-    """ the main interface with ometah output """
-    
-    LOG_ON = 0
-
-    def __init__(self, args):
-        """ constructor, from command line arguments """
-        self.__argv = [''] + args[1:]
-        self.__logfile = datedFileName("", ".log")
-    
-    def execOmetah(self, path):
-        """ execute ometah with given arguments,
-        returns the file objects corresponding to the cmd output """
-        cmd = path + string.join(self.__argv)
-        try:
-            fd = os.popen(cmd)
-        except:
-            sef.log('ERROR : wrong path to ometah')
-        return fd
-    
-    def setAttributes():
-        """ set class attributes from XML parsing """
-        dimension = 1
-        
-    def plotDistribution(self, plist, breaks):
-        """ plot from informations read in xml file """        
-        vlist = []
-        for x in plist:
-            vlist.append(float(x.value))
-        r.hist(vlist, breaks, col='green', main='Distribution', xlab='Values')
-    
-    def plotValues(self, plist, dimension):
-        """ plot values """
-        if dimension == 1 :
-            vlist = []
-            for x in plist:
-                vlist.append(float(x.value))
-            r.plot(vlist, type='o', col='red', main='Values evolution', 
xlab='Points', ylab='Value')
-        elif dimension == 2:
-            self.log('ERROR : dimension 2')
-
-    def plotClusters(self, plist, iterations):
-        """ plot the given list in iterations clusters """
-        clist = []                      # is a list of lists, which are the 
iterations
-        ppi = len(plist) / iterations
-        if ppi != int(ppi):
-            self.log('ERROR : Iteration number does not match list size\n')
-            return -1
-        for i in range(iterations):     # for each iteration  
-            buf = []                    # buf is a set of points for an 
iteration
-            for j in range(ppi):        # for each point of the cluster
-                buf.append( float((plist[i * (ppi-1) + j]).value) )
-            clist.append(buf)           # add the created cluster to our 
plotted list                        
-        r.boxplot(clist, style='quantile', col='orange', main='Boxes of 
samples', xlab='Iterations')
-
-    def plotSD(self, plist, iterations):
-        """ plot the standard deviation for each iteration cluster """
-        sdlist = []
-        bflist = []
-        ppi = len(plist) / iterations
-        if ppi != int(ppi):
-            self.log('ERROR : Iteration number does not match list size\n')
-            return -1
-        for i in range(iterations):
-            buf = []
-            for j in range(ppi):
-                buf.append( float((plist[i * (ppi-1) + j]).value))
-            bflist.append(buf)
-        for i in bflist:
-            sdlist.append(r.sd(i))
-        r.plot(sdlist, col='blue', type='o', main='Standard deviations', 
xlab='Iteration', ylab='SD')
-        
-    
-    def log(self, string):
-        """ will write log of current job in a *.log file with date,
-        pb name, output files... """    
-        if self.LOG_ON:
-            fd = open(self.__logfile, 'a')
-            fd.write(string)
-            fd.close()
-    
-    def setLog(self, boolean):
-        self.LOG_ON = boolean
+"""
 
+from rpy import *
 
 
 class XMLParser:
@@ -246,6 +187,10 @@
     def getIterations(self):
         return self.__iterations
 
+    def toString(self):
+        """ to generate a file name for the interface """
+        s = self.__problemName + "_" + self.__metahName;
+        return s
 
 class Point:
     """ a point has a set of coordinates, and a value """
@@ -259,6 +204,13 @@
 
 def main():
     """ main() """
+
+    import time
+    t = time.time()
+
+    import sys
+    import interface
+
     
     # path to ometah binary
     __OMETAH_PATH = "../ometah"
@@ -269,52 +221,74 @@
     # nb of breaks in the distribution histogram
     __HIST_BREAKS = 20
 
-    interface = Interface(sys.argv)
-    interface.setLog(1)
+    # create a new Interface instance
+    intfc = interface.Interface(sys.argv)
+
+    # active the logs
+    intfc.setLog(1)
+
+    # set path to save logs and output files
+    intfc.setPath("tests")
+
     slog = "\n[ Starting at " + time.ctime() + " ] \n"
-    interface.log(slog)
+    intfc.log(slog)
 
     # fd = XML output
-    fd = interface.execOmetah(__OMETAH_PATH)    
-    interface.log('ometah execution ... OK\n')
-    
-    # skip first line to avoid bug in parsing
+    fd = intfc.getXmlFromExecOmetah(__OMETAH_PATH)    
+    intfc.log('ometah execution ... OK\n')
+
+    # to get xml output from a file
+    # fd = intfc.getXmlFromFile(pathToTheFile)
+
+    # plan B to output XML, cos seek => error (file objects and FDs)
+    fileOut = intfc.copyToDisk(fd, 'ometah_output')
+    fd.close()
+    fd = open(fileOut, 'r')    
+
+    # to avoid bug during parsing
     fd.readline()
-    
-    parser = XMLParser(fd, interface)
+
+    parser = XMLParser(fd, intfc)
     parser.readXml()
-    interface.log('parsing XML :  readXML() ... OK\n')
+    fd.close() # we don't need it anymore
+    intfc.log('parsing XML :  readXML() ... OK\n')
     
     pointsList = parser.getPoints()
-    interface.log('getting points list : getPoints() ...  OK\n')
+    intfc.log('getting points list : getPoints() ...  OK\n')
 
-    setBitmapOutput(datedFileName(__R_OUT, '.png'))    
-    interface.plotDistribution(pointsList, __HIST_BREAKS)    
+    intfc.setPostscriptOutput(filename = 'valuesDistribHist')    
+    intfc.plotValuesIterationsDistribHist(pointsList, __HIST_BREAKS)    
     r.dev_off()
-    interface.log('outputing results : plotDistribution(...)  ...  OK\n')
+    intfc.log('outputing results : plotValuesIterationsDistribHist(...)  ...  
OK\n')
 
-    """
-    setBitmapOutput(datedFileName('values', '.png'))    
-    interface.plotValues(pointsList, 1)
+    """ # plotValues for each point
+    setBitmapOutput(filename = intfc.datedFileName('values', '.png'))    
+    intfc.plotValuesIterationsGraph(pointsList, 1)
     r.dev_off()
     interface.log('outputing results : plotValues(...)  ...  OK\n')
     """
-    setBitmapOutput(datedFileName('boxes', '.png'))
-    interface.plotClusters(pointsList, 10)
-    r.dev_off()
-    interface.log('outputing results : plotClusters(...)  ...  OK\n')
 
-    setBitmapOutput(datedFileName('standdev', '.png'))
-    interface.plotSD(pointsList, 10)
+    intfc.setPostscriptOutput(filename = 'valuesBoxes')
+    intfc.plotValuesIterationsBoxes(pointsList, 10)
+    r.dev_off()
+    intfc.log('outputing results : plotValuesIterationsBoxes(...)  ...  OK\n')
+    
+    intfc.setPostscriptOutput(filename = 'valuesStD')
+    intfc.plotValuesIterationsStdGraph(pointsList, 10)
     r.dev_off()
-    interface.log('outputing results : plotSD(...)  ...  OK\n')
+    intfc.log('outputing results : plotValuesIterationsStdGraph(...)  ...  
OK\n')
+    
+    slog = "\n[ End at " + time.ctime() + " ] \n"
+    intfc.log(slog)
 
+     
+    print "time :",  (time.time()-t)
 
-    slog = "\n[ End at " + time.ctime() + " ] \n"
-    interface.log(slog)
 
 
+    
 if __name__ == '__main__':
+
     main()
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]