Changeset 12f77e9 in sasmodels for sasmodels/sasview_model.py
- Timestamp:
- Oct 30, 2018 8:56:38 AM (5 years ago)
- Branches:
- master
- Children:
- 4e96703
- Parents:
- 1657e21 (diff), c6084f1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/sasview_model.py
raa25fc7 r12f77e9 67 67 #: set of defined models (standard and custom) 68 68 MODELS = {} # type: Dict[str, SasviewModelType] 69 # TODO: remove unused MODEL_BY_PATH cache once sasview no longer references it 69 70 #: custom model {path: model} mapping so we can check timestamps 70 71 MODEL_BY_PATH = {} # type: Dict[str, SasviewModelType] 72 #: Track modules that we have loaded so we can determine whether the model 73 #: has changed since we last reloaded. 74 _CACHED_MODULE = {} # type: Dict[str, "module"] 71 75 72 76 def find_model(modelname): … … 111 115 Load a custom model given the model path. 112 116 """ 113 model = MODEL_BY_PATH.get(path, None)114 if model is not None and model.timestamp == getmtime(path):115 #logger.info("Model already loaded %s", path)116 return model117 118 117 #logger.info("Loading model %s", path) 118 119 # Load the kernel module. This may already be cached by the loader, so 120 # only requires checking the timestamps of the dependents. 119 121 kernel_module = custom.load_custom_kernel_module(path) 120 if hasattr(kernel_module, 'Model'): 121 model = kernel_module.Model 122 123 # Check if the module has changed since we last looked. 124 reloaded = kernel_module != _CACHED_MODULE.get(path, None) 125 _CACHED_MODULE[path] = kernel_module 126 127 # Turn the module into a model. We need to do this in even if the 128 # model has already been loaded so that we can determine the model 129 # name and retrieve it from the MODELS cache. 130 model = getattr(kernel_module, 'Model', None) 131 if model is not None: 122 132 # Old style models do not set the name in the class attributes, so 123 133 # set it here; this name will be overridden when the object is created … … 132 142 model_info = modelinfo.make_model_info(kernel_module) 133 143 model = make_model_from_info(model_info) 134 model.timestamp = getmtime(path)135 144 136 145 # If a model name already exists and we are loading a different model, … … 148 157 _previous_name, model.name, model.filename) 149 158 150 MODELS[model.name] = model 151 MODEL_BY_PATH[path] = model 152 return model 159 # Only update the model if the module has changed 160 if reloaded or model.name not in MODELS: 161 MODELS[model.name] = model 162 163 return MODELS[model.name] 153 164 154 165 … … 377 388 hidden.add('background') 378 389 self._model_info.parameters.defaults['background'] = 0. 390 391 # Update the parameter lists to exclude any hidden parameters 392 self.magnetic_params = tuple(pname for pname in self.magnetic_params 393 if pname not in hidden) 394 self.orientation_params = tuple(pname for pname in self.orientation_params 395 if pname not in hidden) 379 396 380 397 self._persistency_dict = {} … … 791 808 return value, [value], [1.0] 792 809 810 @classmethod 811 def runTests(cls): 812 """ 813 Run any tests built into the model and captures the test output. 814 815 Returns success flag and output 816 """ 817 from .model_test import check_model 818 return check_model(cls._model_info) 819 793 820 def test_cylinder(): 794 821 # type: () -> float … … 878 905 Model = _make_standard_model('sphere') 879 906 model = Model() 880 model.setParam(' M0:sld', 8)907 model.setParam('sld_M0', 8) 881 908 q = np.linspace(-0.35, 0.35, 500) 882 909 qx, qy = np.meshgrid(q, q)
Note: See TracChangeset
for help on using the changeset viewer.