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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 325 - (show annotations) (download) (as text)
Fri Feb 24 01:05:43 2006 UTC (18 years, 3 months ago) by johnpye
File MIME type: text/x-python
File size: 6026 byte(s)
Fixing up initial values in SolverReporter
Fixing 'block time'
1 import ascend
2 import time
3 import gtk
4 import gtk.glade
5
6 class PythonSolverReporter(ascend.SolverReporter):
7 def __init__(self,browser):
8 self.browser=browser
9 self.updateinterval = self.browser.prefs.getBoolPref("SolverReporter","update_interval", 0.5)
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 PythonSolverReporter.__init__(self,browser)
42
43 _xml = gtk.glade.XML(GLADE_FILE,"solverstatusdialog")
44 _xml.signal_autoconnect(self)
45
46 self.window = _xml.get_widget("solverstatusdialog")
47
48 self.numvars = _xml.get_widget("numvarsentry")
49 self.numblocks = _xml.get_widget("numblocksentry")
50 self.elapsedtime = _xml.get_widget("elapsedtimeentry")
51 self.numiterations = _xml.get_widget("numiterationsentry")
52 self.blockvars = _xml.get_widget("blockvarsentry")
53 self.blockiterations = _xml.get_widget("blockiterationsentry")
54 self.blockresidual = _xml.get_widget("blockresidualentry")
55 self.blockelapsedtime = _xml.get_widget("blockelapsedtimeentry")
56
57 self.progressbar = _xml.get_widget("progressbar")
58 self.closebutton = _xml.get_widget("closebutton")
59 self.stopbutton = _xml.get_widget("stopbutton")
60
61 print "SOLVER REPORTER ---- PYTHON"
62
63 self.solvedvars = 0;
64
65 self.lasttime = 0;
66 self.blockstart = self.starttime;
67 self.blocktime = 0;
68 self.elapsed = 0;
69 self.blocknum = 0;
70 self.guiinterrupt = False;
71 self.guitime = 0;
72
73 self.nv = numvars
74
75 while gtk.events_pending():
76 gtk.main_iteration()
77
78 def run(self):
79 self.window.run()
80
81 def on_stopbutton_clicked(self,*args):
82 print "STOPPING..."
83 self.guiinterrupt = True;
84
85 def on_solverstatusdialog_close(self,*args):
86 self.window.response(gtk.RESPONSE_CLOSE)
87
88 def on_solverstatusdialog_response(self,response,*args):
89 self.window.hide()
90 del(self.window)
91
92 def fill_values(self,status):
93 self.numblocks.set_text("%d of %d" % (status.getCurrentBlockNum(),status.getNumBlocks()))
94 self.numvars.set_text("%d of %d" % (status.getNumConverged(), self.nv))
95 self.elapsedtime.set_text("%0.1f s" % self.elapsed)
96 self.numiterations.set_text(str(status.getIterationNum()))
97 self.blockvars.set_text(str(status.getCurrentBlockSize()))
98 self.blockiterations.set_text(str(status.getCurrentBlockIteration()))
99 self.blockresidual.set_text("%8.5e" % status.getBlockResidualRMS())
100 self.blockelapsedtime.set_text("%0.1f s" % self.blocktime)
101
102 _frac = float(status.getNumConverged()) / self.nv
103 self.progressbar.set_text("%d vars converged..." % status.getNumConverged());
104 self.progressbar.set_fraction(_frac)
105
106 def report(self,status):
107 _time = time.clock();
108 _sincelast = _time - self.lasttime
109 if status.getCurrentBlockNum() > self.blocknum:
110 self.blocknum = status.getCurrentBlockNum()
111 self.blockstart = _time
112
113 if self.lasttime==0 or _sincelast > self.updateinterval or status.isConverged():
114 self.lasttime = _time;
115 self.elapsed = _time - self.starttime
116 self.blocktime = _time - self.blockstart
117 #print "UPDATING!"
118 self.fill_values(status)
119
120 while gtk.events_pending():
121 gtk.main_iteration()
122
123 self.guitime = self.guitime + (time.clock() - _time)
124
125 if status.isConverged() or status.isDiverged() or status.isInterrupted():
126 return 1
127 if self.guiinterrupt:
128 return 2
129 return 0
130
131 def finalise(self,status):
132 _time = time.clock()
133
134 _p = self.browser.prefs;
135 _close_on_converged = _p.getBoolPref("SolverReporter","close_on_converged",True);
136 _close_on_nonconverged = _p.getBoolPref("SolverReporter","close_on_nonconverged",False);
137
138
139 if status.isConverged() and _close_on_converged:
140 self.report_to_browser(status)
141 self.window.response(gtk.RESPONSE_CLOSE)
142 return
143
144 if not status.isConverged() and _close_on_nonconverged:
145 self.report_to_browser(status)
146 self.window.response(gtk.RESPONSE_CLOSE)
147 return
148
149 self.fill_values(status)
150
151 if status.isConverged():
152 self.progressbar.set_fraction(1.0)
153 self.progressbar.set_text("Converged")
154 elif status.hasExceededTimeLimit():
155 self.progressbar.set_text("Exceeded time limit")
156 elif status.hasExceededIterationLimit():
157 self.progressbar.set_text("Exceeded iteration limit")
158 elif status.isDiverged():
159 self.progressbar.set_text("Diverged")
160
161 self.closebutton.set_sensitive(True)
162 self.stopbutton.set_sensitive(False)
163
164 self.report_to_browser(status)
165
166 self.guitime = self.guitime + (time.clock() - _time)
167 print "TIME SPENT UPDATING SOLVER: %0.2f s" % self.guitime
168
169
170 class SimpleSolverReporter(PythonSolverReporter):
171 def __init__(self,browser):
172 print "CREATING SIMPLESOLVERREPORTER..."
173 PythonSolverReporter.__init__(self,browser)
174 self.lasttime = self.starttime
175
176 def report(self,status):
177 _time = time.clock()
178 if _time - self.lasttime > self.updateinterval:
179 self.lasttime = _time
180 _msg = "Solved %d vars in %d iterations" % (status.getNumConverged(),status.getIterationNum())
181 self.browser.statusbar.push(self.statusbarcontext, _msg )
182
183 while gtk.events_pending():
184 gtk.main_iteration()
185 return 0
186
187 def finalise(self,status):
188 self.report_to_browser(status)
189

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