Changes in sasmodels/model_test.py [5024a56:d92182f] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    r5024a56 rd92182f  
    55Usage:: 
    66 
    7     python -m sasmodels.model_test [opencl|cuda|dll] model1 model2 ... 
    8  
    9     if model1 is 'all', then all except the remaining models will be tested 
     7    python -m sasmodels.model_test [opencl|cuda|dll|all] model1 model2 ... 
     8 
     9If model1 is 'all', then all except the remaining models will be tested. 
     10Subgroups are also possible, such as 'py', 'single' or '1d'.  See 
     11:func:`core.list_models` for details. 
    1012 
    1113Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1, 0.1), 
     
    4547from __future__ import print_function 
    4648 
     49import argparse 
    4750import sys 
    4851import unittest 
     
    8992    suite = unittest.TestSuite() 
    9093 
    91     if models[0] in core.KINDS: 
     94    try: 
     95        # See if the first model parses as a model group 
     96        group = list_models(models[0]) 
    9297        skip = models[1:] 
    93         models = list_models(models[0]) 
    94     else: 
     98        models = group 
     99    except Exception: 
    95100        skip = [] 
    96101    for model_name in models: 
     
    167172        # test using cuda if desired and available 
    168173        if 'cuda' in loaders and use_cuda(): 
    169             test_name = "%s-cuda"%model_name 
     174            test_name = "%s-cuda" % model_info.id 
    170175            test_method_name = "test_%s_cuda" % model_info.id 
    171176            # Using dtype=None so that the models that are only 
     
    474479 
    475480 
    476 def main(*models): 
    477     # type: (*str) -> int 
    478     """ 
    479     Run tests given is models. 
    480  
    481     Returns 0 if success or 1 if any tests fail. 
    482     """ 
    483     try: 
    484         from xmlrunner import XMLTestRunner as TestRunner 
    485         test_args = {'output': 'logs'} 
    486     except ImportError: 
    487         from unittest import TextTestRunner as TestRunner 
    488         test_args = {} 
    489  
    490     if models and models[0] == '-v': 
    491         verbosity = 2 
    492         models = models[1:] 
    493     else: 
    494         verbosity = 1 
    495     if models and models[0] == 'opencl': 
    496         if not use_opencl(): 
    497             print("opencl is not available") 
    498             return 1 
    499         loaders = ['opencl'] 
    500         models = models[1:] 
    501     elif models and models[0] == 'cuda': 
    502         if not use_cuda(): 
    503             print("cuda is not available") 
    504             return 1 
    505         loaders = ['cuda'] 
    506         models = models[1:] 
    507     elif models and models[0] == 'dll': 
    508         # TODO: test if compiler is available? 
    509         loaders = ['dll'] 
    510         models = models[1:] 
    511     else: 
    512         loaders = ['dll'] 
    513         if use_opencl(): 
    514             loaders.append('opencl') 
    515         if use_cuda(): 
    516             loaders.append('cuda') 
    517     if not models: 
    518         print("""\ 
    519 usage: 
    520   python -m sasmodels.model_test [-v] [opencl|cuda|dll] model1 model2 ... 
    521  
    522 If -v is included on the command line, then use verbose output. 
    523  
    524 If no platform is specified, then models will be tested with dll, and 
    525 if available, OpenCL and CUDA; the compute target is ignored for pure python models. 
    526  
    527 If model1 is 'all', then all except the remaining models will be tested. 
    528  
    529 """) 
    530  
    531         return 1 
    532  
    533     runner = TestRunner(verbosity=verbosity, **test_args) 
    534     result = runner.run(make_suite(loaders, models)) 
    535     return 1 if result.failures or result.errors else 0 
    536  
    537  
    538481def model_tests(): 
    539482    # type: () -> Iterator[Callable[[], None]] 
     
    570513 
    571514 
     515def main(): 
     516    # type: (*str) -> int 
     517    """ 
     518    Run tests given is models. 
     519 
     520    Returns 0 if success or 1 if any tests fail. 
     521    """ 
     522    try: 
     523        from xmlrunner import XMLTestRunner as TestRunner 
     524        test_args = {'output': 'logs'} 
     525    except ImportError: 
     526        from unittest import TextTestRunner as TestRunner 
     527        test_args = {} 
     528 
     529    parser = argparse.ArgumentParser(description="Test SasModels Models") 
     530    parser.add_argument("-v", "--verbose", action="store_const", 
     531                        default=1, const=2, help="Use verbose output") 
     532    parser.add_argument("-e", "--engine", default="all", 
     533                        help="Engines on which to run the test.  " 
     534                        "Valid values are opencl, cuda, dll, and all. " 
     535                        "Defaults to all if no value is given") 
     536    parser.add_argument("models", nargs="*", 
     537                        help="The names of the models to be tested.  " 
     538                        "If the first model is 'all', then all but the listed " 
     539                        "models will be tested.  See core.list_models() for " 
     540                        "names of other groups, such as 'py' or 'single'.") 
     541    args, models = parser.parse_known_args() 
     542 
     543    if args.engine == "opencl": 
     544        if not use_opencl(): 
     545            print("opencl is not available") 
     546            return 1 
     547        loaders = ['opencl'] 
     548    elif args.engine == "dll": 
     549        loaders = ["dll"] 
     550    elif args.engine == "cuda": 
     551        if not use_cuda(): 
     552            print("cuda is not available") 
     553            return 1 
     554        loaders = ['cuda'] 
     555    elif args.engine == "all": 
     556        loaders = ['dll'] 
     557        if use_opencl(): 
     558            loaders.append('opencl') 
     559        if use_cuda(): 
     560            loaders.append('cuda') 
     561    else: 
     562        print("unknown engine " + args.engine) 
     563        return 1 
     564 
     565    runner = TestRunner(verbosity=args.verbose, **test_args) 
     566    result = runner.run(make_suite(loaders, args.models)) 
     567    return 1 if result.failures or result.errors else 0 
     568 
     569 
    572570if __name__ == "__main__": 
    573     sys.exit(main(*sys.argv[1:])) 
     571    sys.exit(main()) 
Note: See TracChangeset for help on using the changeset viewer.