Changeset 792


Ignore:
Timestamp:
06/10/15 13:01:55 (11 months ago)
Author:
mmckerns
Message:

for speed, use contains instead of get and has_key

Location:
mystic
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • mystic/_math/compressed.py

    r776 r792  
    4949  """convert a list of binary strings to product measure coordinates""" 
    5050  reduce = True  # 'reduce' len=1 and len=0 results 
    51   if kwds.has_key('reduce'): reduce = kwds['reduce'] 
     51  if 'reduce' in kwds: reduce = kwds['reduce'] 
    5252  result = [tuple([j[0][j[1]] for j in \ 
    5353                  zip(positions,[int(i) for i in vk])]) for vk in binaries] 
  • mystic/_math/distance.py

    r776 r792  
    5454""" 
    5555  # dmin: force upconvert to x,x' to dimension >= dmin 
    56   dmin = 0 # default 
    57   if kwds.has_key('dmin'): 
    58     dmin = kwds['dmin'] 
     56  dmin = kwds['dmin'] if 'dmin' in kwds else 0 # default dimension 
    5957  from numpy import abs, asarray, newaxis as nwxs 
    6058  from __builtin__ import max 
     
    270268  tol = kwds.pop('tol', 0.0) 
    271269  cutoff = tol  # default is to zero out distances less than tolerance 
    272   if kwds.has_key('cutoff'): cutoff = kwds.pop('cutoff') 
     270  if 'cutoff' in kwds: cutoff = kwds.pop('cutoff') 
    273271  if cutoff is True: cutoff = tol 
    274272  elif cutoff is False: cutoff = None 
     
    329327  #       thus, we 'pass' on using constraints at this time... 
    330328  constraints = None   # default is no constraints 
    331   if kwds.has_key('constraints'): constraints = kwds.pop('constraints') 
     329  if 'constraints' in kwds: constraints = kwds.pop('constraints') 
    332330  if not constraints:  # if None (default), there are no constraints 
    333331    constraints = lambda x: x 
     
    338336 
    339337  cutoff = ytol  # default is to zero out distances less than tolerance 
    340   if kwds.has_key('cutoff'): cutoff = kwds.pop('cutoff') 
     338  if 'cutoff' in kwds: cutoff = kwds.pop('cutoff') 
    341339  if cutoff is True: cutoff = ytol 
    342340  elif cutoff is False: cutoff = None 
  • mystic/_math/legacydata.py

    r776 r792  
    325325    of any element less than the cutoff. 
    326326""" 
    327     tol = kwds.get('tol', 0.0) # get tolerance in y 
     327    tol = kwds['tol'] if 'tol' in kwds else 0.0 # get tolerance in y 
    328328    # default is to zero out distances less than tolerance 
    329     cutoff = kwds.get('cutoff', tol) 
     329    cutoff = kwds['cutoff'] if 'cutoff' in kwds else tol 
    330330    if cutoff is True: cutoff = tol 
    331331    elif cutoff is False: cutoff = None 
     
    375375    values are normalized by norm = hausdorff. 
    376376""" 
    377     ytol = kwds.get('ytol', 0.0) # get tolerance in y 
     377    ytol = kwds['ytol'] if 'ytol' in kwds else 0.0 # get tolerance in y 
    378378    # default is to zero out distances less than tolerance 
    379     cutoff = kwds.get('cutoff', ytol) 
     379    cutoff = kwds['cutoff'] if 'cutoff' in kwds else ytol 
    380380    if cutoff is True: cutoff = ytol 
    381381    elif cutoff is False: cutoff = None 
  • mystic/_math/measures.py

    r791 r792  
    303303  # plug in the 'constraints' function:  samples' = constrain(samples, weights) 
    304304  constrain = None   # default is no constraints 
    305   if kwds.has_key('constraints'): constrain = kwds['constraints'] 
     305  if 'constraints' in kwds: constrain = kwds['constraints'] 
    306306  if not constrain:  # if None (default), there are no constraints 
    307307    constraints = lambda x: x 
     
    333333 
    334334  # construct and configure optimizer 
    335   debug = False 
    336   if kwds.has_key('debug'): debug = kwds['debug'] 
     335  debug = kwds['debug'] if 'debug' in kwds else False 
    337336  npop = 200 
    338337  maxiter = 1000;  maxfun = 1e+6 
  • mystic/models/abstract_model.py

    r776 r792  
    7171 
    7272    def __call__(self,*args,**kwds): 
    73         coeffs = kwds.get('coeffs', args[0] if len(args) else []) 
     73        coeffs = kwds['coeffs'] if 'coeffs' in kwds else (args[0] if len(args) else []) 
    7474        if len(coeffs) != self.ndim: 
    7575            raise ValueError('input length does not match ndim (ndim=%d)' % self.ndim) 
  • mystic/mystic/_genSow.py

    r776 r792  
    3636corresponding properties as required inputs for the Monitor. 
    3737        """ 
    38         self.__args = [ i for i in args if self.__dict.has_key(i) ] 
     38        self.__args = [ i for i in args if i in self.__dict ] 
    3939        exec(self._genClass()) # generates Monitor() 
    4040        return Monitor() 
  • mystic/mystic/_symbolic.py

    r776 r792  
    271271    verbose = False  # if True, print debug info 
    272272    #-----------------------undocumented------------------------------- 
    273     if kwds.has_key('permute'): permute = kwds['permute'] 
    274     if kwds.has_key('warn'): warn = kwds['warn'] 
    275     if kwds.has_key('verbose'): verbose = kwds['verbose'] 
     273    permute = kwds['permute'] if 'permute' in kwds else permute 
     274    warn = kwds['warn'] if 'warn' in kwds else warn 
     275    verbose = kwds['verbose'] if 'verbose' in kwds else verbose 
    276276    #------------------------------------------------------------------ 
    277277    if target in [None, False]: 
     
    310310    # default is _locals with sympy imported 
    311311    _locals = {} 
    312     locals = kwds.get('locals', None) 
     312    locals = kwds['locals'] if 'locals' in kwds else None 
    313313    if locals is None: locals = {} 
    314314    try: 
     
    439439    verbose = False  # if True, print debug info 
    440440    #-----------------------undocumented------------------------------- 
    441     if kwds.has_key('permute'): permute = kwds['permute'] 
    442     if kwds.has_key('warn'): warn = kwds['warn'] 
    443     if kwds.has_key('verbose'): verbose = kwds['verbose'] 
     441    permute = kwds['permute'] if 'permute' in kwds else permute 
     442    warn = kwds['warn'] if 'warn' in kwds else warn 
     443    verbose = kwds['verbose'] if 'verbose' in kwds else verbose 
    444444    #------------------------------------------------------------------ 
    445445    if target in [None, False]: 
     
    478478    # default is _locals with sympy imported 
    479479    _locals = {} 
    480     locals = kwds.get('locals', None) 
     480    locals = kwds['locals'] if 'locals' in kwds else None 
    481481    if locals is None: locals = {} 
    482482    # if sympy not installed, return original constraints 
     
    699699    verbose = False # if True, print details from _classify_variables 
    700700    #-----------------------undocumented------------------------------- 
    701     if kwds.has_key('permute'): permute = kwds['permute'] 
    702     if kwds.has_key('warn'): warn = kwds['warn'] 
    703     if kwds.has_key('verbose'): verbose = kwds['verbose'] 
     701    permute = kwds['permute'] if 'permute' in kwds else permute 
     702    warn = kwds['warn'] if 'warn' in kwds else warn 
     703    verbose = kwds['verbose'] if 'verbose' in kwds else verbose 
    704704    #------------------------------------------------------------------ 
    705705    if target in [None, False]: 
     
    732732        return mystring 
    733733 
    734     locals = kwds.get('locals', None) 
     734    locals = kwds['locals'] if 'locals' in kwds else None 
    735735    if locals is None: locals = {} 
    736736 
  • mystic/mystic/abstract_ensemble_solver.py

    r785 r792  
    116116 
    117117        # default settings for nested optimization 
    118         nbins = [1]*dim 
    119         if kwds.has_key('nbins'): nbins = kwds['nbins'] 
     118        nbins = kwds['nbins'] if 'nbins' in kwds else [1]*dim 
    120119        if isinstance(nbins, int): 
    121120            from mystic.math.grid import randomly_bin 
    122121            nbins = randomly_bin(nbins, dim, ones=True, exact=True) 
    123122        self._nbins           = nbins 
    124         npts = 1 
    125         if kwds.has_key('npts'): npts = kwds['npts'] 
     123        npts = kwds['npts'] if 'npts' in kwds else 1 
    126124        self._npts            = npts 
    127125        from mystic.solvers import NelderMeadSimplexSolver 
     
    129127        self._bestSolver      = None # 'best' solver (after Solve) 
    130128        self._total_evals     = 0 # total function calls (after Solve) 
    131         if kwds.has_key('nbins'): NP = reduce(lambda x,y:x*y, nbins) 
    132         else: NP = npts #XXX: merge npts/nbins kwds? 
     129        NP = reduce(lambda x,y:x*y, nbins) if 'nbins' in kwds else npts 
    133130        self._allSolvers      = [None for j in range(NP)] 
    134131        return 
  • mystic/mystic/abstract_launcher.py

    r776 r792  
    120120            except KeyError: 
    121121                nodes = args[0] 
    122         else: nodes = kwds.get('nodes', self.__nodes) 
     122        else: nodes = kwds['nodes'] if 'nodes' in kwds else self.__nodes 
    123123        try: self.nodes = nodes 
    124124        except TypeError: pass  # then self.nodes is read-only 
  • mystic/mystic/abstract_solver.py

    r791 r792  
    110110    signal_handler   - catches the interrupt signal. 
    111111        """ 
    112         NP = 1 
    113         if kwds.has_key('npop'): NP = kwds['npop'] 
     112        NP = kwds['npop'] if 'npop' in kwds else 1 
     113       #self._max = kwds['max'] if 'max' in kwds else False 
    114114 
    115115        self.nDim             = dim 
     
    150150        self._cost            = (None, None, None) 
    151151        #                       (cost, raw_cost, args) #,callback) 
    152         self._termination     = lambda x, *ar, **kw: False if len(ar) < 1 or ar[0] is False or kw.get('info',True) == False else '' #XXX: better default ? 
     152        self._termination     = lambda x, *ar, **kw: False if len(ar) < 1 or ar[0] is False or (kw['info'] if 'info' in kw else True) == False else '' #XXX: better default ? 
    153153        # (get termination details with self._termination.__doc__) 
    154154 
     
    170170 
    171171    def __energy_history(self): 
    172         """get the energy_history (default: energy_history = _stepmon.y)""" 
    173         if self._energy_history is None: return self._stepmon.y 
     172        """get the energy_history (default: energy_history = _stepmon._y)""" 
     173        if self._energy_history is None: return self._stepmon._y 
    174174        return self._energy_history 
    175175 
    176176    def __set_energy_history(self, energy): 
    177         """set the energy_history (energy=None will sync with _stepmon.y)""" 
     177        """set the energy_history (energy=None will sync with _stepmon._y)""" 
    178178        self._energy_history = energy 
    179179        return 
     
    280280        else: 
    281281            raise TypeError, "'%s' is not a monitor instance" % monitor 
    282         self.energy_history   = self._stepmon.y 
    283         self.solution_history = self._stepmon.x 
     282        self.energy_history   = None # sync with self._stepmon 
     283        self.solution_history = None # sync with self._stepmon 
    284284        return 
    285285 
     
    506506    - generations = maximum number of solver iterations (i.e. steps) 
    507507    - evaluations = maximum number of function evaluations""" 
    508         self._maxiter = generations 
    509         self._maxfun = evaluations 
    510508        # backward compatibility 
    511         if kwds.has_key('maxiter'): 
    512             self._maxiter = kwds['maxiter'] 
    513         if kwds.has_key('maxfun'): 
    514             self._maxfun = kwds['maxfun'] 
     509        self._maxiter = kwds['maxiter'] if 'maxiter' in kwds else generations 
     510        self._maxfun = kwds['maxfun'] if 'maxfun' in kwds else evaluations 
    515511        # handle if new (reset counter, instead of extend counter) 
    516512        if new: 
     
    699695        [settings.update({i:j}) for (i,j) in kwds.items() if i in settings] 
    700696        # backward compatibility 
    701         if kwds.has_key('EvaluationMonitor'): \ 
    702            self.SetEvaluationMonitor(kwds.get('EvaluationMonitor')) 
    703         if kwds.has_key('StepMonitor'): \ 
    704            self.SetGenerationMonitor(kwds.get('StepMonitor')) 
    705         if kwds.has_key('penalty'): \ 
    706            self.SetPenalty(kwds.get('penalty')) 
    707         if kwds.has_key('constraints'): \ 
    708            self.SetConstraints(kwds.get('constraints')) 
     697        if 'EvaluationMonitor' in kwds: \ 
     698           self.SetEvaluationMonitor(kwds['EvaluationMonitor']) 
     699        if 'StepMonitor' in kwds: \ 
     700           self.SetGenerationMonitor(kwds['StepMonitor']) 
     701        if 'penalty' in kwds: \ 
     702           self.SetPenalty(kwds['penalty']) 
     703        if 'constraints' in kwds: \ 
     704           self.SetConstraints(kwds['constraints']) 
    709705        return settings 
    710706 
  • mystic/mystic/differential_evolution.py

    r791 r792  
    293293        scale=self.scale             #multiplier for mutation impact 
    294294        [settings.update({i:j}) for (i,j) in kwds.items() if i in settings] 
    295         self.probability = kwds.get('CrossProbability', probability) 
    296         self.scale = kwds.get('ScalingFactor', scale) 
     295        word = 'CrossProbability' 
     296        self.probability = kwds[word] if word in kwds else probability 
     297        word = 'ScalingFactor' 
     298        self.scale = kwds[word] if word in kwds else scale 
    297299        self.strategy = getattr(settings['strategy'],'__name__','Best1Bin') 
    298300        return settings 
     
    471473        scale=self.scale             #multiplier for mutation impact 
    472474        [settings.update({i:j}) for (i,j) in kwds.items() if i in settings] 
    473         self.probability = kwds.get('CrossProbability', probability) 
    474         self.scale = kwds.get('ScalingFactor', scale) 
     475        word = 'CrossProbability' 
     476        self.probability = kwds[word] if word in kwds else probability 
     477        word = 'ScalingFactor' 
     478        self.scale = kwds[word] if word in kwds else scale 
    475479        self.strategy = getattr(settings['strategy'],'__name__','Best1Bin') 
    476480        return settings 
     
    573577 
    574578    """ 
    575     invariant_current = True 
    576     if kwds.has_key('invariant_current'): 
    577         invariant_current = kwds['invariant_current'] 
     579    invariant_current = kwds['invariant_current'] if 'invariant_current' in kwds else True 
    578580    kwds['invariant_current'] = invariant_current 
    579581    return diffev(cost,x0,npop,args=args,bounds=bounds,ftol=ftol,gtol=gtol, 
     
    643645 
    644646    """ 
    645     invariant_current = False 
    646     if kwds.has_key('invariant_current'): 
    647         invariant_current = kwds['invariant_current'] 
    648     handler = False 
    649     if kwds.has_key('handler'): 
    650         handler = kwds['handler'] 
     647    invariant_current = kwds['invariant_current'] if 'invariant_current' in kwds else False 
     648    handler = kwds['handler'] if 'handler' in kwds else False 
    651649 
    652650    from mystic.strategy import Best1Bin 
    653     strategy = Best1Bin 
    654     if kwds.has_key('strategy'): 
    655         strategy = kwds['strategy'] 
     651    strategy = kwds['strategy'] if 'strategy' in kwds else Best1Bin 
    656652    from mystic.monitors import Monitor 
    657     stepmon = Monitor() 
    658     evalmon = Monitor() 
    659     if kwds.has_key('itermon'): 
    660         stepmon = kwds['itermon'] 
    661     if kwds.has_key('evalmon'): 
    662         evalmon = kwds['evalmon'] 
     653    stepmon = kwds['itermon'] if 'itermon' in kwds else Monitor() 
     654    evalmon = kwds['evalmon'] if 'evalmon' in kwds else Monitor() 
     655 
    663656    if gtol: #if number of generations provided, use ChangeOverGeneration  
    664657        from mystic.termination import ChangeOverGeneration 
     
    676669    solver.SetEvaluationMonitor(evalmon) 
    677670    solver.SetGenerationMonitor(stepmon) 
    678     if kwds.has_key('penalty'): 
    679         penalty = kwds['penalty'] 
    680         solver.SetPenalty(penalty) 
    681     if kwds.has_key('constraints'): 
    682         constraints = kwds['constraints'] 
    683         solver.SetConstraints(constraints) 
     671    if 'penalty' in kwds: 
     672        solver.SetPenalty(kwds['penalty']) 
     673    if 'constraints' in kwds: 
     674        solver.SetConstraints(kwds['constraints']) 
    684675    if bounds is not None: 
    685676        minb,maxb = unpair(bounds) 
  • mystic/mystic/ensemble.py

    r791 r792  
    8585        sigint_callback = kwds.pop('sigint_callback', None) 
    8686        settings = self._process_inputs(kwds) 
    87         disp = settings.get('disp', False) 
    88         echo = settings.get('callback', None) #XXX: every iteration every run 
     87        disp = settings['disp'] if 'disp' in settings else False 
     88        echo = settings['callback'] if 'callback' in settings else None 
    8989#       for key in settings: 
    9090#           exec "%s = settings['%s']" % (key,key) 
     
    279279        sigint_callback = kwds.pop('sigint_callback', None) 
    280280        settings = self._process_inputs(kwds) 
    281         disp = settings.get('disp', False) 
    282         echo = settings.get('callback', None) #XXX: every iteration every run 
     281        disp = settings['disp'] if 'disp' in settings else False 
     282        echo = settings['callback'] if 'callback' in settings else None 
    283283#       for key in settings: 
    284284#           exec "%s = settings['%s']" % (key,key) 
     
    479479 
    480480    """ 
    481     handler = False 
    482     if kwds.has_key('handler'): 
    483         handler = kwds['handler'] 
     481    handler = kwds['handler'] if 'handler' in kwds else False 
    484482    from mystic.solvers import NelderMeadSimplexSolver as _solver 
    485     if kwds.has_key('solver'): 
    486         _solver = kwds['solver'] 
     483    if 'solver' in kwds: _solver = kwds['solver'] 
    487484 
    488485    from mystic.monitors import Monitor 
    489     stepmon = Monitor() 
    490     evalmon = Monitor() 
    491     if kwds.has_key('itermon'): 
    492         stepmon = kwds['itermon'] 
    493     if kwds.has_key('evalmon'): 
    494         evalmon = kwds['evalmon'] 
     486    stepmon = kwds['itermon'] if 'itermon' in kwds else Monitor() 
     487    evalmon = kwds['evalmon'] if 'evalmon' in kwds else Monitor() 
    495488 
    496489    gtol = 10 # termination generations (scipy: 2, default: 10) 
    497     if kwds.has_key('gtol'): 
    498         gtol = kwds['gtol'] 
     490    if 'gtol' in kwds: gtol = kwds['gtol'] 
    499491    if gtol: #if number of generations is provided, use NCOG 
    500492        from mystic.termination import NormalizedChangeOverGeneration 
     
    509501    solver.SetEvaluationMonitor(evalmon) 
    510502    solver.SetGenerationMonitor(stepmon) 
    511     if kwds.has_key('penalty'): 
    512         penalty = kwds['penalty'] 
    513         solver.SetPenalty(penalty) 
    514     if kwds.has_key('constraints'): 
    515         constraints = kwds['constraints'] 
    516         solver.SetConstraints(constraints) 
     503    if 'penalty' in kwds: 
     504        solver.SetPenalty(kwds['penalty']) 
     505    if 'constraints' in kwds: 
     506        solver.SetConstraints(kwds['constraints']) 
    517507    if bounds is not None: 
    518508        minb,maxb = unpair(bounds) 
     
    610600 
    611601    """ 
    612     handler = False 
    613     if kwds.has_key('handler'): 
    614         handler = kwds['handler'] 
     602    handler = kwds['handler'] if 'handler' in kwds else False 
    615603    from mystic.solvers import NelderMeadSimplexSolver as _solver 
    616     if kwds.has_key('solver'): 
    617         _solver = kwds['solver'] 
     604    if 'solver' in kwds: _solver = kwds['solver'] 
    618605 
    619606    from mystic.monitors import Monitor 
    620     stepmon = Monitor() 
    621     evalmon = Monitor() 
    622     if kwds.has_key('itermon'): 
    623         stepmon = kwds['itermon'] 
    624     if kwds.has_key('evalmon'): 
    625         evalmon = kwds['evalmon'] 
     607    stepmon = kwds['itermon'] if 'itermon' in kwds else Monitor() 
     608    evalmon = kwds['evalmon'] if 'evalmon' in kwds else Monitor() 
    626609 
    627610    gtol = 10 # termination generations (scipy: 2, default: 10) 
    628     if kwds.has_key('gtol'): 
    629         gtol = kwds['gtol'] 
     611    if 'gtol' in kwds: gtol = kwds['gtol'] 
    630612    if gtol: #if number of generations is provided, use NCOG 
    631613        from mystic.termination import NormalizedChangeOverGeneration 
     
    640622    solver.SetEvaluationMonitor(evalmon) 
    641623    solver.SetGenerationMonitor(stepmon) 
    642     if kwds.has_key('penalty'): 
    643         penalty = kwds['penalty'] 
    644         solver.SetPenalty(penalty) 
    645     if kwds.has_key('constraints'): 
    646         constraints = kwds['constraints'] 
    647         solver.SetConstraints(constraints) 
     624    if 'penalty' in kwds: 
     625        solver.SetPenalty(kwds['penalty']) 
     626    if 'constraints' in kwds: 
     627        solver.SetConstraints(kwds['constraints']) 
    648628    if bounds is not None: 
    649629        minb,maxb = unpair(bounds) 
  • mystic/mystic/munge.py

    r791 r792  
    114114  steps, energy = read_monitor(mon) 
    115115  f = open(log_file,'w') 
    116   if kwds.has_key('header'): 
    117     header = kwds.pop('header') 
    118     f.write('# %s\n' % header) 
     116  if 'header' in kwds: 
     117    f.write('# %s\n' % kwds.pop('header')) 
    119118  for variable,value in kwds.items(): # write remaining kwds as variables 
    120119    f.write('%s = %s\n' % (variable,value)) 
     
    129128  monitor = write_monitor( *raw_to_support( *read_monitor(mon) ) ) 
    130129  header = "written in 'support' format" 
    131   if kwds.has_key('header'): 
     130  if 'header' in kwds: 
    132131    header += "\n# " + str(kwds.pop('header')) 
    133132  write_raw_file(monitor,log_file,header=header,**kwds) 
     
    138137  monitor = write_monitor( *raw_to_converge( *read_monitor(mon) ) ) 
    139138  header = "written in 'converge' format" 
    140   if kwds.has_key('header'): 
     139  if 'header' in kwds: 
    141140    header += "\n# " + str(kwds.pop('header')) 
    142141  write_raw_file(monitor,log_file,header=header,**kwds) 
  • mystic/mystic/scipy_optimize.py

    r791 r792  
    363363 
    364364    """ 
    365     handler = False 
    366     if kwds.has_key('handler'): 
    367         handler = kwds['handler'] 
     365    handler = kwds['handler'] if 'handler' in kwds else False 
    368366 
    369367    from mystic.monitors import Monitor 
    370     stepmon = Monitor() 
    371     evalmon = Monitor() 
    372     if kwds.has_key('itermon'): 
    373         stepmon = kwds['itermon'] 
    374     if kwds.has_key('evalmon'): 
    375         evalmon = kwds['evalmon'] 
     368    stepmon = kwds['itermon'] if 'itermon' in kwds else Monitor() 
     369    evalmon = kwds['evalmon'] if 'evalmon' in kwds else Monitor() 
    376370 
    377371    if xtol: #if tolerance in x is provided, use CandidateRelativeTolerance 
     
    386380    solver.SetEvaluationMonitor(evalmon) 
    387381    solver.SetGenerationMonitor(stepmon) 
    388     if kwds.has_key('penalty'): 
    389         penalty = kwds['penalty'] 
    390         solver.SetPenalty(penalty) 
    391     if kwds.has_key('constraints'): 
    392         constraints = kwds['constraints'] 
    393         solver.SetConstraints(constraints) 
     382    if 'penalty' in kwds: 
     383        solver.SetPenalty(kwds['penalty']) 
     384    if 'constraints' in kwds: 
     385        solver.SetConstraints(kwds['constraints']) 
    394386    if bounds is not None: 
    395387        minb,maxb = unpair(bounds) 
     
    602594        direc=self._direc    #initial direction set 
    603595        [settings.update({i:j}) for (i,j) in kwds.items() if i in settings] 
    604         self._direc = kwds.get('direc', direc) 
     596        self._direc = kwds['direc'] if 'direc' in kwds else direc 
    605597        self.xtol = settings['xtol'] 
    606598        return settings 
     
    706698    #        - should just pass 'direc', and then hands-off ?  How return it ? 
    707699 
    708     handler = False 
    709     if kwds.has_key('handler'): 
    710         handler = kwds['handler'] 
     700    handler = kwds['handler'] if 'handler' in kwds else False 
    711701 
    712702    from mystic.monitors import Monitor 
    713     stepmon = Monitor() 
    714     evalmon = Monitor() 
    715     if kwds.has_key('itermon'): 
    716         stepmon = kwds['itermon'] 
    717     if kwds.has_key('evalmon'): 
    718         evalmon = kwds['evalmon'] 
     703    stepmon = kwds['itermon'] if 'itermon' in kwds else Monitor() 
     704    evalmon = kwds['evalmon'] if 'evalmon' in kwds else Monitor() 
    719705 
    720706    gtol = 2 # termination generations (scipy: 2, default: 10) 
    721     if kwds.has_key('gtol'): 
    722         gtol = kwds['gtol'] 
     707    if 'gtol' in kwds: gtol = kwds['gtol'] 
    723708    if gtol: #if number of generations is provided, use NCOG 
    724709        from mystic.termination import NormalizedChangeOverGeneration as NCOG 
     
    733718    solver.SetEvaluationMonitor(evalmon) 
    734719    solver.SetGenerationMonitor(stepmon) 
    735     if kwds.has_key('penalty'): 
    736         penalty = kwds['penalty'] 
    737         solver.SetPenalty(penalty) 
    738     if kwds.has_key('constraints'): 
    739         constraints = kwds['constraints'] 
    740         solver.SetConstraints(constraints) 
     720    if 'penalty' in kwds: 
     721        solver.SetPenalty(kwds['penalty']) 
     722    if 'constraints' in kwds: 
     723        solver.SetConstraints(kwds['constraints']) 
    741724    if bounds is not None: 
    742725        minb,maxb = unpair(bounds) 
  • mystic/mystic/solvers.py

    r776 r792  
    8080def LoadSolver(filename=None, **kwds): 
    8181    """load solver state from a restart file""" 
    82     if filename is None: filename = kwds.get('_state', None) 
     82    if filename is None: 
     83        filename = kwds['_state'] if '_state' in kwds else None 
    8384    #XXX: only allow a list override keys (lookup values from self) 
    8485#   if filename is None: filename = self._state 
  • mystic/scripts/mystic_log_reader.py

    r776 r792  
    9898 
    9999# parse file contents to get (i,id), cost, and parameters 
    100 from mystic.munge import logfile_reader 
    101 step, param, cost = logfile_reader(filename) 
     100from mystic.munge import logfile_reader, read_raw_file 
     101try: 
     102    step, param, cost = logfile_reader(filename) 
     103except SyntaxError: 
     104    read_raw_file(filename) 
     105    msg = "incompatible file format, try 'support_convergence.py'" 
     106    raise SyntaxError(msg) 
    102107 
    103108# ignore everything after 'stop' 
  • mystic/tests/test_solver_compare.py

    r776 r792  
    2424  exec "s1 = solvers.%s" % solver1 
    2525  exec "s2 = solvers.%s" % solver2 
    26   maxiter = kwds.get('maxiter', None) 
    27   maxfun = kwds.get('maxfun', None) 
     26  maxiter = kwds['maxiter'] if 'maxiter' in kwds else None 
     27  maxfun = kwds['maxfun'] if 'maxfun' in kwds else None 
    2828  s1_x = s1(rosen, x0, disp=0, full_output=True, **kwds) 
    2929  s2_x = s2(rosen, x0, disp=0, full_output=True, **kwds) 
     
    4848  exec "my = solvers.%s" % solvername 
    4949  exec "sp = %s" % solvername 
    50   maxiter = kwds.get('maxiter', None) 
    51   maxfun = kwds.get('maxfun', None) 
     50  maxiter = kwds['maxiter'] if 'maxiter' in kwds else None 
     51  maxfun = kwds['maxfun'] if 'maxfun' in kwds else None 
    5252  my_x = my(rosen, x0, disp=0, full_output=True, **kwds) 
    5353# itermon = kwds.pop('itermon',None) 
Note: See TracChangeset for help on using the changeset viewer.