/[ascend]/trunk/pygtk/interface/solverreporter.py
ViewVC logotype

Diff of /trunk/pygtk/interface/solverreporter.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 320 by johnpye, Thu Feb 23 12:30:40 2006 UTC revision 321 by johnpye, Thu Feb 23 14:14:36 2006 UTC
# Line 4  import gtk Line 4  import gtk
4  import gtk.glade  import gtk.glade
5    
6  class PythonSolverReporter(ascend.SolverReporter):  class PythonSolverReporter(ascend.SolverReporter):
7      def __init__(self,GLADE_FILE,browser,numvars):      def __init__(self,browser,interval):
8          self.browser=browser          self.browser=browser
9            self.updateinterval = interval
10            self.reporter = self.browser.reporter
11            if self.reporter==None:
12                raise RuntimeError("Can't find reporter")
13            self.starttime = time.clock()
14            self.statusbarcontext = self.browser.statusbar.get_context_id("pythonsolverreporter")
15            self.browser.statusbar.push(self.statusbarcontext,"Solving...")
16            ascend.SolverReporter.__init__(self)
17    
18        def report_to_browser(self,status):
19            self.browser.statusbar.pop(self.statusbarcontext)
20    
21            if status.isConverged():
22                self.reporter.reportSuccess("Converged")
23                return
24            elif status.hasExceededTimeLimit():
25                _msg = "Solver exceeded time limit"
26            elif status.hasExceededIterationLimit():
27                _msg = "Solver exceeded iteration limit"
28            elif status.isDiverged():
29                _msg = "Solver diverged"
30            else:
31                _msg = "Solve failed (unknown reason: check console)"
32    
33            _msg = _msg + " while solving block %d/%d (%d vars in block)" % (status.getCurrentBlockNum(),
34                    status.getNumBlocks(),status.getCurrentBlockSize() )
35            self.reporter.reportError(_msg)
36    
37    
38    
39    class PopupSolverReporter(PythonSolverReporter):
40        def __init__(self,GLADE_FILE,browser,numvars):
41            _updateinterval=0.1
42            PythonSolverReporter.__init__(self,browser,_updateinterval)
43    
44          _xml = gtk.glade.XML(GLADE_FILE,"solverstatusdialog")          _xml = gtk.glade.XML(GLADE_FILE,"solverstatusdialog")
45          _xml.signal_autoconnect(self)          _xml.signal_autoconnect(self)
46    
# Line 27  class PythonSolverReporter(ascend.Solver Line 62  class PythonSolverReporter(ascend.Solver
62          print "SOLVER REPORTER ---- PYTHON"          print "SOLVER REPORTER ---- PYTHON"
63    
64          self.solvedvars = 0;          self.solvedvars = 0;
         self.updateinterval = 0.1;  
65    
         _time = time.clock();  
         self.starttime = _time;  
66          self.lasttime = 0;          self.lasttime = 0;
67          self.blockstart = _time;          self.blockstart = self.starttime;
68          self.blocktime = 0;          self.blocktime = 0;
69          self.elapsed = 0;          self.elapsed = 0;
70          self.blocknum = 0;          self.blocknum = 0;
# Line 41  class PythonSolverReporter(ascend.Solver Line 73  class PythonSolverReporter(ascend.Solver
73          self.nv = numvars          self.nv = numvars
74          self.numvars.set_text(str(self.nv))          self.numvars.set_text(str(self.nv))
75    
         ascend.SolverReporter.__init__(self)  
   
76          while gtk.events_pending():          while gtk.events_pending():
77              gtk.main_iteration()              gtk.main_iteration()
78    
# Line 63  class PythonSolverReporter(ascend.Solver Line 93  class PythonSolverReporter(ascend.Solver
93      def fill_values(self,status):      def fill_values(self,status):
94          print "FILLING VALUES..."          print "FILLING VALUES..."
95          self.numblocks.set_text("%d of %d" % (status.getCurrentBlockNum(),status.getNumBlocks()))          self.numblocks.set_text("%d of %d" % (status.getCurrentBlockNum(),status.getNumBlocks()))
96  #       try:  
 #            
97          self.elapsedtime.set_text("%0.1f s" % self.elapsed)          self.elapsedtime.set_text("%0.1f s" % self.elapsed)
98          self.numiterations.set_text(str(status.getIterationNum()))          self.numiterations.set_text(str(status.getIterationNum()))
99          self.blockvars.set_text(str(status.getCurrentBlockSize()))          self.blockvars.set_text(str(status.getCurrentBlockSize()))
# Line 72  class PythonSolverReporter(ascend.Solver Line 101  class PythonSolverReporter(ascend.Solver
101          self.blockresidual.set_text("%8.5e" % status.getBlockResidualRMS())          self.blockresidual.set_text("%8.5e" % status.getBlockResidualRMS())
102          self.blockelapsedtime.set_text("%0.1f s" % self.blocktime)          self.blockelapsedtime.set_text("%0.1f s" % self.blocktime)
103    
 #           _frac = self.status.getNumConverged() / self.numvars()  
 #           self.progressbar.set_text("%d vars converged..." % self.status.getNumConverged())  
 #           self.progressbar.set_fraction(_frac)  
 #           print "TRYING..."  
 #       except RuntimeError,e:  
 #           print "ERROR OF SOME SORT"  
104          _frac = float(status.getNumConverged()) / self.nv          _frac = float(status.getNumConverged()) / self.nv
105          print "FRACTION = ",_frac          print "FRACTION = ",_frac
106          self.progressbar.set_text("%d vars converged..." % status.getNumConverged());          self.progressbar.set_text("%d vars converged..." % status.getNumConverged());
# Line 106  class PythonSolverReporter(ascend.Solver Line 129  class PythonSolverReporter(ascend.Solver
129    
130      def finalise(self,status):      def finalise(self,status):
131          _p = self.browser.prefs;          _p = self.browser.prefs;
132          _close_on_converged = _p.getBoolPref("SolverReporter","close_on_converged");          _close_on_converged = _p.getBoolPref("SolverReporter","close_on_converged",True);
133            _close_on_nonconverged = _p.getBoolPref("SolverReporter","close_on_nonconverged",False);
134    
135          if status.isConverged() and _close_on_converged:          if status.isConverged() and _close_on_converged:
136                self.report_to_browser(status)
137                self.window.response(gtk.RESPONSE_CLOSE)
138                return
139            
140            if not status.isConverged() and _close_on_nonconverged:
141                self.report_to_browser(status)
142              self.window.response(gtk.RESPONSE_CLOSE)              self.window.response(gtk.RESPONSE_CLOSE)
143              return                    return
144    
145          self.fill_values(status)          self.fill_values(status)
146    
# Line 126  class PythonSolverReporter(ascend.Solver Line 156  class PythonSolverReporter(ascend.Solver
156                                    
157          self.closebutton.set_sensitive(True)          self.closebutton.set_sensitive(True)
158          self.stopbutton.set_sensitive(False)          self.stopbutton.set_sensitive(False)
159    
160            self.report_to_browser(status)
161    
162    
163    class SimpleSolverReporter(PythonSolverReporter):
164        def __init__(self,browser):
165            print "CREATING SIMPLESOLVERREPORTER..."
166            _update = 0.1
167            PythonSolverReporter.__init__(self,browser,_update)
168            self.lasttime = self.starttime
169    
170        def report(self,status):
171            _time = time.clock()
172            if _time - self.lasttime > self.updateinterval:
173                self.lasttime = _time
174                _msg = "Solved %d vars in %d iterations" % (status.getNumConverged(),status.getIterationNum())
175                self.browser.statusbar.push(self.statusbarcontext, _msg )
176    
177            while gtk.events_pending():
178                gtk.main_iteration()
179            return 0
180    
181        def finalise(self,status):
182            self.report_to_browser(status)
183                    
               

Legend:
Removed from v.320  
changed lines
  Added in v.321

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22