Changeset 35086c3 in sasview for src


Ignore:
Timestamp:
Jun 3, 2014 6:12:35 PM (10 years ago)
Author:
pkienzle
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
949aa2c
Parents:
ddfe1eb7
Message:

show fit progress for bumps

Location:
src/sans
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sans/fit/BumpsFitting.py

    r5044543 r35086c3  
    22BumpsFitting module runs the bumps optimizer. 
    33""" 
     4from datetime import timedelta, datetime 
     5 
    46import numpy 
    57 
     
    1315from .expression import compile_constraints 
    1416 
     17class Progress(object): 
     18    def __init__(self, history, max_step, pars, dof): 
     19        remaining_time = int(history.time[0]*(float(max_step)/history.step[0]-1)) 
     20        # Depending on the time remaining, either display the expected 
     21        # time of completion, or the amount of time remaining.  Use precision 
     22        # appropriate for the duration. 
     23        if remaining_time >= 1800: 
     24            completion_time = datetime.now() + timedelta(seconds=remaining_time) 
     25            if remaining_time >= 36000: 
     26                time = completion_time.strftime('%Y-%m-%d %H:%M') 
     27            else: 
     28                time = completion_time.strftime('%H:%M') 
     29        else: 
     30            if remaining_time >= 3600: 
     31                time = '%dh %dm'%(remaining_time//3600, (remaining_time%3600)//60) 
     32            elif remaining_time >= 60: 
     33                time = '%dm %ds'%(remaining_time//60, remaining_time%60) 
     34            else: 
     35                time = '%ds'%remaining_time 
     36        chisq = "%.3g"%(2*history.value[0]/dof) 
     37        step = "%d of %d"%(history.step[0], max_step) 
     38        header = "=== Steps: %s  chisq: %s  ETA: %s\n"%(step, chisq, time) 
     39        parameters = ["%15s: %-10.3g%s"%(k,v,("\n" if i%3==2 else " | ")) 
     40                      for i,(k,v) in enumerate(zip(pars,history.point[0]))] 
     41        self.msg = "".join([header]+parameters) 
     42 
     43    def __str__(self): 
     44        return self.msg 
     45 
     46 
    1547class BumpsMonitor(object): 
    16     def __init__(self, handler, max_step=0): 
     48    def __init__(self, handler, max_step, pars, dof): 
    1749        self.handler = handler 
    1850        self.max_step = max_step 
     51        self.pars = pars 
     52        self.dof = dof 
    1953 
    2054    def config_history(self, history): 
     
    2357    def __call__(self, history): 
    2458        if self.handler is None: return 
     59        self.handler.set_result(Progress(history, self.max_step, self.pars, self.dof)) 
    2560        self.handler.progress(history.step[0], self.max_step) 
    2661        if len(history.step)>1 and history.step[1] > history.step[0]: 
     
    252287    options = fitopts.options.copy() 
    253288    max_step = fitopts.options.get('steps', 0) + fitopts.options.get('burn', 0) 
     289    pars = [p.name for p in problem._parameters] 
    254290    options['monitors'] = [ 
    255         BumpsMonitor(handler, max_step), 
     291        BumpsMonitor(handler, max_step, pars, problem.dof), 
    256292        ConvergenceMonitor(), 
    257293        ] 
  • src/sans/perspectives/fitting/console.py

    r644ca73 r35086c3  
    128128             
    129129         
    130     def update_fit(self, msg="", last=False): 
     130    def update_fit(self, last=False): 
    131131        """ 
    132132        """ 
     
    135135        self.update_duration = t1 
    136136        self.fit_duration += self.elapsed_time 
    137         str_time = time.strftime("%a, %d %b %Y %H:%M:%S ", time.localtime(t1)) 
     137        str_time = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime(t1)) 
    138138        UPDATE_INTERVAL = 5.0 
    139139        u_flag = False 
     
    141141            self.fit_duration = 0 
    142142            u_flag = True 
    143         if not last: 
    144             msg += "Fit Updates ... %s \n" % str_time     
    145         else: 
    146             msg += "Final updates ........." 
     143        msg = str_time 
    147144        if u_flag or last: 
    148145            if self.result is not None: 
     
    163160                msg +=  str(self.result) 
    164161                msg += "\n" 
    165                 if not last: 
    166                     msg += "About %s s elapsed......... \n" % \ 
    167                                             str (UPDATE_INTERVAL) 
    168162            else: 
    169163                msg += "No result available\n" 
Note: See TracChangeset for help on using the changeset viewer.