Changes in sasmodels/model_test.py [5024a56:d92182f] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/model_test.py
r5024a56 rd92182f 5 5 Usage:: 6 6 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 9 If model1 is 'all', then all except the remaining models will be tested. 10 Subgroups are also possible, such as 'py', 'single' or '1d'. See 11 :func:`core.list_models` for details. 10 12 11 13 Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1, 0.1), … … 45 47 from __future__ import print_function 46 48 49 import argparse 47 50 import sys 48 51 import unittest … … 89 92 suite = unittest.TestSuite() 90 93 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]) 92 97 skip = models[1:] 93 models = list_models(models[0])94 e lse:98 models = group 99 except Exception: 95 100 skip = [] 96 101 for model_name in models: … … 167 172 # test using cuda if desired and available 168 173 if 'cuda' in loaders and use_cuda(): 169 test_name = "%s-cuda" %model_name174 test_name = "%s-cuda" % model_info.id 170 175 test_method_name = "test_%s_cuda" % model_info.id 171 176 # Using dtype=None so that the models that are only … … 474 479 475 480 476 def main(*models):477 # type: (*str) -> int478 """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 TestRunner485 test_args = {'output': 'logs'}486 except ImportError:487 from unittest import TextTestRunner as TestRunner488 test_args = {}489 490 if models and models[0] == '-v':491 verbosity = 2492 models = models[1:]493 else:494 verbosity = 1495 if models and models[0] == 'opencl':496 if not use_opencl():497 print("opencl is not available")498 return 1499 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 1505 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, and525 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 1532 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 0536 537 538 481 def model_tests(): 539 482 # type: () -> Iterator[Callable[[], None]] … … 570 513 571 514 515 def 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 572 570 if __name__ == "__main__": 573 sys.exit(main( *sys.argv[1:]))571 sys.exit(main())
Note: See TracChangeset
for help on using the changeset viewer.