source: sasview/fittingview/src/sans/perspectives/fitting/fit_thread.py @ 8aa5788

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 8aa5788 was 8aa5788, checked in by Gervaise Alina <gervyh@…>, 13 years ago

allow compute smearer everything is needed

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