source: sasview/fittingview/src/sans/perspectives/fitting/fit_thread.py @ 2bb37c3

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2bb37c3 was 2bb37c3, checked in by Gervaise Alina <gervyh@…>, 13 years ago

make sure the console print some updates only

  • Property mode set to 100644
File size: 3.6 KB
Line 
1
2import sys
3import time
4from data_util.calcthread import CalcThread
5
6def map_getattr(classInstance, classFunc, *args):
7    """
8    Take an instance of a class and a function name as a string.
9    Execute class.function and return result
10    """
11    return  getattr(classInstance,classFunc)(*args)
12
13def map_apply(arguments):
14    return apply(arguments[0], arguments[1:])
15
16class FitThread(CalcThread):
17    """Thread performing the fit """
18   
19    def __init__(self, 
20                  fn,
21                  page_id,
22                   handler,
23                    batch_outputs,
24                    batch_inputs=None,             
25                  pars=None,
26                 completefn = None,
27                 updatefn   = None,
28                 yieldtime  = 0.01,
29                 worktime   = 0.01,
30                 ftol       = None,
31                 reset_flag = False):
32        CalcThread.__init__(self,completefn,
33                 updatefn,
34                 yieldtime,
35                 worktime)
36        self.handler = handler
37        self.fitter = fn
38        self.pars = pars
39        self.batch_inputs = batch_inputs
40        self.batch_outputs = batch_outputs
41        self.page_id = page_id
42        self.starttime = time.time()
43        self.updatefn = updatefn
44        #Relative error desired in the sum of squares.
45        self.ftol = ftol
46        self.reset_flag = reset_flag
47   
48    def isquit(self):
49        """
50        :raise KeyboardInterrupt: when the thread is interrupted
51       
52        """
53        try:
54            CalcThread.isquit(self)
55        except KeyboardInterrupt:
56            raise KeyboardInterrupt
57       
58    def compute(self):
59        """
60        Perform a fit
61        """
62        msg = ""
63        try:
64            import copy
65            list_handler = []
66            list_curr_thread = [] 
67            list_ftol = []
68            list_reset_flag = []
69            list_map_get_attr = []
70            list_fit_function = []
71            list_q = []
72            for i in range(len(self.fitter)):
73                list_handler.append(self.handler)
74                list_q.append(None)
75                list_curr_thread.append(None)
76                list_ftol.append(self.ftol)
77                list_reset_flag.append(self.reset_flag)
78                list_fit_function.append('fit')
79                list_map_get_attr.append(map_getattr)
80            #from multiprocessing import Pool
81            inputs = zip(list_map_get_attr,self.fitter, list_fit_function,
82                          list_q, list_q, list_handler,list_curr_thread,list_ftol,
83                         list_reset_flag)
84            result =  map(map_apply, inputs)
85   
86            self.complete(result=result,
87                          batch_inputs=self.batch_inputs,
88                           batch_outputs=self.batch_outputs,
89                          page_id=self.page_id,
90                          pars = self.pars,
91                          elapsed=time.time()-self.starttime)
92           
93        except KeyboardInterrupt, msg:
94            # Thread was interrupted, just proceed and re-raise.
95            # Real code should not print, but this is an example...
96            #print "keyboard exception"
97            #Stop on exception during fitting. Todo: need to put
98            #some mssg and reset progress bar.
99           
100            if self.handler is not None:
101                self.handler.error(msg=msg)
102        except:
103            if self.handler is not None:
104                self.handler.error(msg=str(sys.exc_value))
105           
106       
107   
Note: See TracBrowser for help on using the repository browser.