source: sasview/fittingview/src/sans/perspectives/fitting/fit_thread.py @ 33dd2e5

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

working on batch

  • Property mode set to 100644
File size: 3.3 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_outputs,
23                    batch_inputs=None,             
24                  pars=None,
25                 completefn = None,
26                 updatefn   = None,
27                 yieldtime  = 0.01,
28                 worktime   = 0.01,
29                 ftol       = None):
30        CalcThread.__init__(self,completefn,
31                 updatefn,
32                 yieldtime,
33                 worktime)
34        self.handler = handler
35        self.fitter = fn
36        self.pars = pars
37        self.batch_inputs = batch_inputs
38        self.batch_outputs = batch_outputs
39        self.page_id = page_id
40        self.starttime = 0
41        self.updatefn = updatefn
42        #Relative error desired in the sum of squares.
43        self.ftol = ftol
44   
45    def isquit(self):
46        """
47        :raise KeyboardInterrupt: when the thread is interrupted
48       
49        """
50        try:
51            CalcThread.isquit(self)
52        except KeyboardInterrupt:
53            raise KeyboardInterrupt
54       
55    def compute(self):
56        """
57        Perform a fit
58        """
59        msg = ""
60        try:
61            import copy
62            list_handler = []
63            list_curr_thread = [] 
64            list_ftol = []
65            list_map_get_attr = []
66            list_fit_function = []
67            list_q = []
68            for i in range(len(self.fitter)):
69                list_handler.append(None)
70                list_q.append(None)
71                list_curr_thread.append(None)
72                list_ftol.append(self.ftol)
73                list_fit_function.append('fit')
74                list_map_get_attr.append(map_getattr)
75            from multiprocessing import Pool
76            inputs = zip(list_map_get_attr,self.fitter, list_fit_function,
77                         list_handler, list_q, list_curr_thread, list_ftol)
78            result =  Pool(1).map(func=map_apply, 
79                               iterable=inputs)
80            self.complete(result=result,
81                          batch_inputs=self.batch_inputs,
82                           batch_outputs=self.batch_outputs,
83                          page_id=self.page_id,
84                          pars = self.pars)
85           
86        except KeyboardInterrupt, msg:
87            # Thread was interrupted, just proceed and re-raise.
88            # Real code should not print, but this is an example...
89            #print "keyboard exception"
90            #Stop on exception during fitting. Todo: need to put
91            #some mssg and reset progress bar.
92            raise
93            #if self.handler is not None:
94            #    self.handler.error(msg=msg)
95        except:
96            if self.handler is not None:
97                self.handler.error(msg=str(sys.exc_value))
98           
99       
100   
Note: See TracBrowser for help on using the repository browser.