source: sasview/fittingview/src/sans/perspectives/fitting/fit_thread.py @ 7afcae8

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 7afcae8 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
RevLine 
[e9b4cc4]1
[66ff250]2import sys
[e54d2c32]3from data_util.calcthread import CalcThread
[e9b4cc4]4
[cc31608]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:])
[66ff250]14
[e9b4cc4]15class FitThread(CalcThread):
[ed2ea6a]16    """Thread performing the fit """
[e9b4cc4]17   
[58e0c83]18    def __init__(self, 
[e54d2c32]19                  fn,
[66ff250]20                  page_id,
[e54d2c32]21                   handler,
[8aa5788]22                   batch_result, 
[e54d2c32]23                  pars=None,
[e9b4cc4]24                 completefn = None,
25                 updatefn   = None,
26                 yieldtime  = 0.01,
[2296316]27                 worktime   = 0.01,
28                 ftol       = None):
[e9b4cc4]29        CalcThread.__init__(self,completefn,
30                 updatefn,
31                 yieldtime,
32                 worktime)
[e54d2c32]33        self.handler = handler
34        self.fitter = fn
[e9b4cc4]35        self.pars = pars
[8aa5788]36        self.batch_result = batch_result
[66ff250]37        self.page_id = page_id
[e9b4cc4]38        self.starttime = 0
[e54d2c32]39        self.updatefn = updatefn
[2296316]40        #Relative error desired in the sum of squares.
41        self.ftol = ftol
[e54d2c32]42   
[e9b4cc4]43    def isquit(self):
[ed2ea6a]44        """
[5062bbf]45        :raise KeyboardInterrupt: when the thread is interrupted
46       
[ed2ea6a]47        """
[e9b4cc4]48        try:
49            CalcThread.isquit(self)
50        except KeyboardInterrupt:
51            raise KeyboardInterrupt
[66ff250]52       
[e9b4cc4]53    def compute(self):
[ed2ea6a]54        """
[5062bbf]55        Perform a fit
[ed2ea6a]56        """
[40953a9]57        msg = ""
[cc31608]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
[67ae937]73            inputs = zip(list_map_get_attr,self.fitter, list_fit_function,
74                         list_handler, list_q, list_curr_thread,list_ftol)
[cc31608]75            result =  Pool(1).map(func=map_apply, 
76                               iterable=inputs)
[66ff250]77            #self.handler.starting_fit()
[e9b4cc4]78            self.complete(result= result,
[8aa5788]79                          batch_result=self.batch_result,
[66ff250]80                          page_id=self.page_id,
[6bbeacd4]81                          pars = self.pars)
[785c8233]82           
[e54d2c32]83        except KeyboardInterrupt, msg:
[e9b4cc4]84            # Thread was interrupted, just proceed and re-raise.
85            # Real code should not print, but this is an example...
[ad6dd4c]86            #print "keyboard exception"
[67ae937]87            #Stop on exception during fitting. Todo: need to put
88            #some mssg and reset progress bar.
[66ff250]89            raise
90            #if self.handler is not None:
91            #    self.handler.error(msg=msg)
92        except:
[f7f6886]93            if self.handler is not None:
94                self.handler.error(msg=str(sys.exc_value))
[66ff250]95           
96       
97   
Note: See TracBrowser for help on using the repository browser.