Changeset 191c648 in sasview


Ignore:
Timestamp:
Jun 13, 2014 7:19:28 PM (11 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:
1790664
Parents:
249a7c6
Message:

redo bumps constraints handling to allow pickling on windows

File:
1 edited

Legend:

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

    r249a7c6 r191c648  
    191191    #     resynth_data/restore_data/save/plot 
    192192 
     193class ParameterExpressions(object): 
     194    def __init__(self, models): 
     195        self.models = models 
     196        self._setup() 
     197 
     198    def _setup(self): 
     199        exprs = {} 
     200        for M in self.models: 
     201            exprs.update((".".join((M.name, k)), v) for k, v in M.constraints.items()) 
     202        if exprs: 
     203            symtab = dict((".".join((M.name, k)), p) 
     204                          for M in self.models 
     205                          for k,p in M.parameters().items()) 
     206            self.update = compile_constraints(symtab, exprs) 
     207        else: 
     208            self.update = lambda: 0 
     209 
     210    def __call__(self): 
     211        self.update() 
     212 
     213    def __getstate__(self): 
     214        return self.models 
     215 
     216    def __setstate__(self, state): 
     217        self.models = state 
     218        self._setup() 
     219 
    193220class BumpsFit(FitEngine): 
    194221    """ 
     
    218245        problem = FitProblem(models) 
    219246 
    220  
    221         # Build constraint expressions 
    222         exprs = {} 
    223         for M in models: 
    224             exprs.update((".".join((M.name, k)), v) for k, v in M.constraints.items()) 
    225         if exprs: 
    226             symtab = dict((".".join((M.name, k)), p) 
    227                           for M in models 
    228                           for k,p in M.parameters().items()) 
    229             constraints = compile_constraints(symtab, exprs) 
    230         else: 
    231             constraints = lambda: 0 
    232  
    233         # Override model update so that parameter constraints are applied 
    234         problem._model_update = problem.model_update 
    235         def model_update(): 
    236             constraints() 
    237             problem._model_update() 
    238         problem.model_update = model_update 
     247        # TODO: need better handling of parameter expressions and bounds constraints 
     248        # so that they are applied during polydispersity calculations.  This 
     249        # will remove the immediate need for the setp_hook in bumps, though 
     250        # bumps may still need something similar, such as a sane class structure 
     251        # which allows a subclass to override setp. 
     252        problem.setp_hook = ParameterExpressions(models) 
    239253 
    240254        # Run the fit 
Note: See TracChangeset for help on using the changeset viewer.