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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 319 - (show annotations) (download) (as text)
Thu Feb 23 12:30:40 2006 UTC (14 years, 9 months ago) by johnpye
File MIME type: text/x-python
File size: 4043 byte(s)
Fixed a bug with the diagnose window after a successful solve
Added preference: SolverReporter:close_on_converged
1 import ascend
2 import time
3 import gtk
4 import gtk.glade
5
6 class PythonSolverReporter(ascend.SolverReporter):
7 def __init__(self,GLADE_FILE,browser,numvars):
8 self.browser=browser
9 _xml = gtk.glade.XML(GLADE_FILE,"solverstatusdialog")
10 _xml.signal_autoconnect(self)
11
12 self.window = _xml.get_widget("solverstatusdialog")
13
14 self.numvars = _xml.get_widget("numvarsentry")
15 self.numblocks = _xml.get_widget("numblocksentry")
16 self.elapsedtime = _xml.get_widget("elapsedtimeentry")
17 self.numiterations = _xml.get_widget("numiterationsentry")
18 self.blockvars = _xml.get_widget("blockvarsentry")
19 self.blockiterations = _xml.get_widget("blockiterationsentry")
20 self.blockresidual = _xml.get_widget("blockresidualentry")
21 self.blockelapsedtime = _xml.get_widget("blockelapsedtimeentry")
22
23 self.progressbar = _xml.get_widget("progressbar")
24 self.closebutton = _xml.get_widget("closebutton")
25 self.stopbutton = _xml.get_widget("stopbutton")
26
27 print "SOLVER REPORTER ---- PYTHON"
28
29 self.solvedvars = 0;
30 self.updateinterval = 0.1;
31
32 _time = time.clock();
33 self.starttime = _time;
34 self.lasttime = 0;
35 self.blockstart = _time;
36 self.blocktime = 0;
37 self.elapsed = 0;
38 self.blocknum = 0;
39 self.guiinterrupt = False;
40
41 self.nv = numvars
42 self.numvars.set_text(str(self.nv))
43
44 ascend.SolverReporter.__init__(self)
45
46 while gtk.events_pending():
47 gtk.main_iteration()
48
49 def run(self):
50 self.window.run()
51
52 def on_stopbutton_clicked(self,*args):
53 print "STOPPING..."
54 self.guiinterrupt = True;
55
56 def on_solverstatusdialog_close(self,*args):
57 self.window.response(gtk.RESPONSE_CLOSE)
58
59 def on_solverstatusdialog_response(self,response,*args):
60 self.window.hide()
61 del(self.window)
62
63 def fill_values(self,status):
64 print "FILLING VALUES..."
65 self.numblocks.set_text("%d of %d" % (status.getCurrentBlockNum(),status.getNumBlocks()))
66 # try:
67 #
68 self.elapsedtime.set_text("%0.1f s" % self.elapsed)
69 self.numiterations.set_text(str(status.getIterationNum()))
70 self.blockvars.set_text(str(status.getCurrentBlockSize()))
71 self.blockiterations.set_text(str(status.getCurrentBlockIteration()))
72 self.blockresidual.set_text("%8.5e" % status.getBlockResidualRMS())
73 self.blockelapsedtime.set_text("%0.1f s" % self.blocktime)
74
75 # _frac = self.status.getNumConverged() / self.numvars()
76 # self.progressbar.set_text("%d vars converged..." % self.status.getNumConverged())
77 # self.progressbar.set_fraction(_frac)
78 # print "TRYING..."
79 # except RuntimeError,e:
80 # print "ERROR OF SOME SORT"
81 _frac = float(status.getNumConverged()) / self.nv
82 print "FRACTION = ",_frac
83 self.progressbar.set_text("%d vars converged..." % status.getNumConverged());
84 self.progressbar.set_fraction(_frac)
85
86 def report(self,status):
87 _time = time.clock();
88 _sincelast = _time - self.lasttime
89 if status.getCurrentBlockNum() > self.blocknum:
90 self.blocknum = status.getCurrentBlockNum()
91 self.blockstart = _time
92 if self.lasttime==0 or _sincelast > self.updateinterval or status.isConverged():
93 self.lasttime = _time;
94 self.elapsed = _time - self.starttime
95 print "UPDATING!"
96 self.fill_values(status)
97
98 while gtk.events_pending():
99 gtk.main_iteration()
100
101 if status.isConverged() or status.isDiverged() or status.isInterrupted():
102 return 1
103 if self.guiinterrupt:
104 return 2
105 return 0
106
107 def finalise(self,status):
108 _p = self.browser.prefs;
109 _close_on_converged = _p.getBoolPref("SolverReporter","close_on_converged");
110
111 if status.isConverged() and _close_on_converged:
112 self.window.response(gtk.RESPONSE_CLOSE)
113 return
114
115 self.fill_values(status)
116
117 if status.isConverged():
118 self.progressbar.set_fraction(1.0)
119 self.progressbar.set_text("Converged")
120 elif status.hasExceededTimeLimit():
121 self.progressbar.set_text("Exceeded time limit")
122 elif status.hasExceededIterationLimit():
123 self.progressbar.set_text("Exceeded iteration limit")
124 elif status.isDiverged():
125 self.progressbar.set_text("Diverged")
126
127 self.closebutton.set_sensitive(True)
128 self.stopbutton.set_sensitive(False)
129
130

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