Changes in / [0011ecc:9ae85f0] in sasmodels


Ignore:
Location:
sasmodels
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    rf72d70a rd504bcd  
    321321    if '*' in name: 
    322322        name = name.split('*')[0] 
    323  
    324     # Suppress magnetism for python models (not yet implemented) 
    325     if callable(model_info.Iq): 
    326         pars.update(suppress_magnetism(pars)) 
    327323 
    328324    if name == 'barbell': 
  • sasmodels/compare_many.py

    rf72d70a r424fe00  
    106106    header = ('\n"Model","%s","Count","%d","Dimension","%s"' 
    107107              % (name, N, "2D" if is_2d else "1D")) 
    108     if not mono: 
    109         header += ',"Cutoff",%g'%(cutoff,) 
     108    if not mono: header += ',"Cutoff",%g'%(cutoff,) 
    110109    print(header) 
    111110 
     
    162161    max_diff = [0] 
    163162    for k in range(N): 
    164         print("Model %s %d"%(name, k+1), file=sys.stderr) 
     163        print("%s %d"%(name, k), file=sys.stderr) 
    165164        seed = np.random.randint(1e6) 
    166165        pars_i = randomize_pars(model_info, pars, seed) 
    167166        constrain_pars(model_info, pars_i) 
    168         if 'sasview' in (base, comp): 
    169             constrain_new_to_old(model_info, pars_i) 
     167        constrain_new_to_old(model_info, pars_i) 
    170168        if mono: 
    171169            pars_i = suppress_pd(pars_i) 
     
    189187    Print the command usage string. 
    190188    """ 
    191     print("usage: compare_many.py MODEL COUNT (1dNQ|2dNQ) (CUTOFF|mono) (single|double|quad)", 
    192           file=sys.stderr) 
     189    print("usage: compare_many.py MODEL COUNT (1dNQ|2dNQ) (CUTOFF|mono) (single|double|quad)") 
    193190 
    194191 
     
    207204    print("""\ 
    208205 
    209 MODEL is the model name of the model or one of the model types listed in 
    210 sasmodels.core.list_models (all, py, c, double, single, opencl, 1d, 2d, 
    211 nonmagnetic, magnetic).  Model types can be combined, such as 2d+single. 
     206MODEL is the model name of the model or "all" for all the models 
     207in alphabetical order. 
    212208 
    213209COUNT is the number of randomly generated parameter sets to try. A value 
     
    224220below the cutoff will be ignored.  Use "mono" for monodisperse models.  The 
    225221choice of polydisperse parameters, and the number of points in the distribution 
    226 is set in compare.py defaults for each model.  Polydispersity is given in the 
    227 "demo" attribute of each model. 
     222is set in compare.py defaults for each model. 
    228223 
    229224PRECISION is the floating point precision to use for comparisons.  If two 
    230 precisions are given, then compare one to the other.  Precision is one of 
    231 fast, single, double for GPU or single!, double!, quad! for DLL.  If no 
    232 precision is given, then use single and double! respectively. 
     225precisions are given, then compare one to the other, ignoring sasview. 
    233226 
    234227Available models: 
     
    240233    Main program. 
    241234    """ 
    242     if len(argv) not in (3, 4, 5, 6): 
     235    if len(argv) not in (5, 6): 
    243236        print_help() 
    244237        return 
    245238 
    246     target = argv[0] 
    247     try: 
    248         model_list = [target] if target in MODELS else core.list_models(target) 
    249     except ValueError: 
    250         print('Bad model %s.  Use model type or one of:' % target, file=sys.stderr) 
     239    model = argv[0] 
     240    if not (model in MODELS) and (model != "all"): 
     241        print('Bad model %s.  Use "all" or one of:'%model) 
    251242        print_models() 
    252         print('model types: all, py, c, double, single, opencl, 1d, 2d, nonmagnetic, magnetic') 
    253243        return 
    254244    try: 
     
    257247        assert argv[2][1] == 'd' 
    258248        Nq = int(argv[2][2:]) 
    259         mono = len(argv) <= 3 or argv[3] == 'mono' 
     249        mono = argv[3] == 'mono' 
    260250        cutoff = float(argv[3]) if not mono else 0 
    261         base = argv[4] if len(argv) > 4 else "single" 
    262         comp = argv[5] if len(argv) > 5 else "double!" 
     251        base = argv[4] 
     252        comp = argv[5] if len(argv) > 5 else "sasview" 
    263253    except Exception: 
    264254        traceback.print_exc() 
     
    268258    data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0., 
    269259                             'accuracy': 'Low', 'view':'log', 'zero': False}) 
     260    model_list = [model] if model != "all" else MODELS 
    270261    for model in model_list: 
    271262        compare_instance(model, data, index, N=count, mono=mono, 
  • sasmodels/core.py

    r5124c969 r52e9a45  
    6969        * magnetic: models with an sld 
    7070        * nommagnetic: models without an sld 
    71  
    72     For multiple conditions, combine with plus.  For example, *c+single+2d* 
    73     would return all oriented models implemented in C which can be computed 
    74     accurately with single precision arithmetic. 
    75     """ 
    76     if kind and any(k not in KINDS for k in kind.split('+')): 
     71    """ 
     72    if kind and kind not in KINDS: 
    7773        raise ValueError("kind not in " + ", ".join(KINDS)) 
    7874    files = sorted(glob(joinpath(generate.MODEL_PATH, "[a-zA-Z]*.py"))) 
    7975    available_models = [basename(f)[:-3] for f in files] 
    80     if kind and '+' in kind: 
    81         all_kinds = kind.split('+') 
    82         condition = lambda name: all(_matches(name, k) for k in all_kinds) 
    83     else: 
    84         condition = lambda name: _matches(name, kind) 
    85     selected = [name for name in available_models if condition(name)] 
     76    selected = [name for name in available_models if _matches(name, kind)] 
    8677 
    8778    return selected 
  • sasmodels/model_test.py

    r598857b r1a6cd57  
    9797        is_py = callable(model_info.Iq) 
    9898 
    99         # Some OpenCL drivers seem to be flaky, and are not producing the 
    100         # expected result.  Since we don't have known test values yet for 
    101         # all of our models, we are instead going to compare the results 
    102         # for the 'smoke test' (that is, evaluation at q=0.1 for the default 
    103         # parameters just to see that the model runs to completion) between 
    104         # the OpenCL and the DLL.  To do this, we define a 'stash' which is 
    105         # shared between OpenCL and DLL tests.  This is just a list.  If the 
    106         # list is empty (which it will be when DLL runs, if the DLL runs 
    107         # first), then the results are appended to the list.  If the list 
    108         # is not empty (which it will be when OpenCL runs second), the results 
    109         # are compared to the results stored in the first element of the list. 
    110         # This is a horrible stateful hack which only makes sense because the 
    111         # test suite is thrown away after being run once. 
    112         stash = [] 
    113  
    11499        if is_py:  # kernel implemented in python 
    115100            test_name = "Model: %s, Kernel: python"%model_name 
     
    118103                                 test_method_name, 
    119104                                 platform="dll",  # so that 
    120                                  dtype="double", 
    121                                  stash=stash) 
     105                                 dtype="double") 
    122106            suite.addTest(test) 
    123107        else:   # kernel implemented in C 
    124  
    125             # test using dll if desired 
    126             if 'dll' in loaders or not core.HAVE_OPENCL: 
    127                 test_name = "Model: %s, Kernel: dll"%model_name 
    128                 test_method_name = "test_%s_dll" % model_info.id 
    129                 test = ModelTestCase(test_name, model_info, 
    130                                      test_method_name, 
    131                                      platform="dll", 
    132                                      dtype="double", 
    133                                      stash=stash) 
    134                 suite.addTest(test) 
    135  
    136108            # test using opencl if desired and available 
    137109            if 'opencl' in loaders and core.HAVE_OPENCL: 
     
    144116                test = ModelTestCase(test_name, model_info, 
    145117                                     test_method_name, 
    146                                      platform="ocl", dtype=None, 
    147                                      stash=stash) 
     118                                     platform="ocl", dtype=None) 
    148119                #print("defining", test_name) 
     120                suite.addTest(test) 
     121 
     122            # test using dll if desired 
     123            if 'dll' in loaders or not core.HAVE_OPENCL: 
     124                test_name = "Model: %s, Kernel: dll"%model_name 
     125                test_method_name = "test_%s_dll" % model_info.id 
     126                test = ModelTestCase(test_name, model_info, 
     127                                     test_method_name, 
     128                                     platform="dll", 
     129                                     dtype="double") 
    149130                suite.addTest(test) 
    150131 
     
    163144        """ 
    164145        def __init__(self, test_name, model_info, test_method_name, 
    165                      platform, dtype, stash): 
    166             # type: (str, ModelInfo, str, str, DType, List[Any]) -> None 
     146                     platform, dtype): 
     147            # type: (str, ModelInfo, str, str, DType) -> None 
    167148            self.test_name = test_name 
    168149            self.info = model_info 
    169150            self.platform = platform 
    170151            self.dtype = dtype 
    171             self.stash = stash  # container for the results of the first run 
    172152 
    173153            setattr(self, test_method_name, self.run_all) 
     
    187167                #({}, (0.0, 0.0), None), 
    188168                # test vector form 
    189                 ({}, [0.001, 0.01, 0.1], [None]*3), 
     169                ({}, [0.1]*2, [None]*2), 
    190170                ({}, [(0.1, 0.1)]*2, [None]*2), 
    191171                # test that ER/VR will run if they exist 
     
    194174                ] 
    195175 
    196             tests = smoke_tests + self.info.tests 
     176            tests = self.info.tests 
    197177            try: 
    198178                model = build_model(self.info, dtype=self.dtype, 
    199179                                    platform=self.platform) 
    200                 results = [self.run_one(model, test) for test in tests] 
    201                 if self.stash: 
    202                     for test, target, actual in zip(tests, self.stash[0], results): 
    203                         assert np.all(abs(target-actual) < 5e-5*abs(actual)),\ 
    204                             "GPU/CPU comparison expected %s but got %s for %s"%(target, actual, test[0]) 
    205                 else: 
    206                     self.stash.append(results) 
    207  
    208                 # Check for missing tests.  Only do so for the "dll" tests 
    209                 # to reduce noise from both opencl and dll, and because 
    210                 # python kernels use platform="dll". 
    211                 if self.platform == "dll": 
    212                     missing = [] 
    213                     ## Uncomment the following to require test cases 
    214                     #missing = self._find_missing_tests() 
    215                     if missing: 
    216                         raise ValueError("Missing tests for "+", ".join(missing)) 
     180                for test in smoke_tests + tests: 
     181                    self.run_one(model, test) 
     182 
     183                if not tests and self.platform == "dll": 
     184                    ## Uncomment the following to make forgetting the test 
     185                    ## values an error.  Only do so for the "dll" tests 
     186                    ## to reduce noise from both opencl and dll, and because 
     187                    ## python kernels use platform="dll". 
     188                    #raise Exception("No test cases provided") 
     189                    pass 
    217190 
    218191            except: 
    219192                annotate_exception(self.test_name) 
    220193                raise 
    221  
    222         def _find_missing_tests(self): 
    223             # type: () -> None 
    224             """make sure there are 1D, 2D, ER and VR tests as appropriate""" 
    225             model_has_VR = callable(self.info.VR) 
    226             model_has_ER = callable(self.info.ER) 
    227             model_has_1D = True 
    228             model_has_2D = any(p.type == 'orientation' 
    229                                for p in self.info.parameters.kernel_parameters) 
    230  
    231             # Lists of tests that have a result that is not None 
    232             single = [test for test in self.info.tests 
    233                       if not isinstance(test[2], list) and test[2] is not None] 
    234             tests_has_VR = any(test[1] == 'VR' for test in single) 
    235             tests_has_ER = any(test[1] == 'ER' for test in single) 
    236             tests_has_1D_single = any(isinstance(test[1], float) for test in single) 
    237             tests_has_2D_single = any(isinstance(test[1], tuple) for test in single) 
    238  
    239             multiple = [test for test in self.info.tests 
    240                         if isinstance(test[2], list) 
    241                             and not all(result is None for result in test[2])] 
    242             tests_has_1D_multiple = any(isinstance(test[1][0], float) 
    243                                         for test in multiple) 
    244             tests_has_2D_multiple = any(isinstance(test[1][0], tuple) 
    245                                         for test in multiple) 
    246  
    247             missing = [] 
    248             if model_has_VR and not tests_has_VR: 
    249                 missing.append("VR") 
    250             if model_has_ER and not tests_has_ER: 
    251                 missing.append("ER") 
    252             if model_has_1D and not (tests_has_1D_single or tests_has_1D_multiple): 
    253                 missing.append("1D") 
    254             if model_has_2D and not (tests_has_2D_single or tests_has_2D_multiple): 
    255                 missing.append("2D") 
    256  
    257             return missing 
    258194 
    259195        def run_one(self, model, test): 
     
    271207 
    272208            if x[0] == 'ER': 
    273                 actual = np.array([call_ER(model.info, pars)]) 
     209                actual = [call_ER(model.info, pars)] 
    274210            elif x[0] == 'VR': 
    275                 actual = np.array([call_VR(model.info, pars)]) 
     211                actual = [call_VR(model.info, pars)] 
    276212            elif isinstance(x[0], tuple): 
    277213                qx, qy = zip(*x) 
     
    302238                                    'f(%s); expected:%s; actual:%s' 
    303239                                    % (xi, yi, actual_yi)) 
    304             return actual 
    305240 
    306241    return ModelTestCase 
  • sasmodels/modelinfo.py

    r5124c969 r85fe7f8  
    730730    info.docs = kernel_module.__doc__ 
    731731    info.category = getattr(kernel_module, 'category', None) 
     732    info.single = getattr(kernel_module, 'single', True) 
     733    info.opencl = getattr(kernel_module, 'opencl', True) 
    732734    info.structure_factor = getattr(kernel_module, 'structure_factor', False) 
    733735    info.profile_axes = getattr(kernel_module, 'profile_axes', ['x', 'y']) 
     
    743745    info.profile = getattr(kernel_module, 'profile', None) # type: ignore 
    744746    info.sesans = getattr(kernel_module, 'sesans', None) # type: ignore 
    745     # Default single and opencl to True for C models.  Python models have callable Iq. 
    746     info.opencl = getattr(kernel_module, 'opencl', not callable(info.Iq)) 
    747     info.single = getattr(kernel_module, 'single', not callable(info.Iq)) 
    748747 
    749748    # multiplicity info 
Note: See TracChangeset for help on using the changeset viewer.