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

Contents of /trunk/pygtk/solverreporter.py

Parent Directory Parent Directory | Revision Log Revision Log


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

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