Changeset d92182f in sasmodels
- Timestamp:
- Mar 11, 2019 11:30:49 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- d8eaa3d
- Parents:
- aee8dfb
- Location:
- sasmodels
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/core.py
r07646b6 rd92182f 64 64 * all: all models 65 65 * py: python models only 66 * c: compiled models only 67 * single: models which support single precision 68 * double: models which require double precision 69 * opencl: controls if OpenCL is supperessed 70 * 1d: models which are 1D only, or 2D using abs(q) 71 * 2d: models which can be 2D 72 * magnetic: models with an sld 73 * nommagnetic: models without an sld 66 * c: c models only 67 * single: c models which support single precision 68 * double: c models which require double precision 69 * opencl: c models which run in opencl 70 * dll: c models which do not run in opencl 71 * 1d: models without orientation 72 * 2d: models with orientation 73 * magnetic: models supporting magnetic sld 74 * nommagnetic: models without magnetic parameter 74 75 75 76 For multiple conditions, combine with plus. For example, *c+single+2d* … … 95 96 info = load_model_info(name) 96 97 pars = info.parameters.kernel_parameters 97 if kind == "py" and callable(info.Iq): 98 return True 99 elif kind == "c" and not callable(info.Iq): 100 return True 101 elif kind == "double" and not info.single: 102 return True 103 elif kind == "single" and info.single: 104 return True 105 elif kind == "opencl" and info.opencl: 106 return True 107 elif kind == "2d" and any(p.type == 'orientation' for p in pars): 108 return True 109 elif kind == "1d" and all(p.type != 'orientation' for p in pars): 110 return True 111 elif kind == "magnetic" and any(p.type == 'sld' for p in pars): 112 return True 113 elif kind == "nonmagnetic" and any(p.type != 'sld' for p in pars): 114 return True 98 # TODO: may be adding Fq to the list at some point 99 is_pure_py = callable(info.Iq) 100 if kind == "py": 101 return is_pure_py 102 elif kind == "c": 103 return not is_pure_py 104 elif kind == "double": 105 return not info.single and not is_pure_py 106 elif kind == "single": 107 return info.single and not is_pure_py 108 elif kind == "opencl": 109 return info.opencl 110 elif kind == "dll": 111 return not info.opencl and not is_pure_py 112 elif kind == "2d": 113 return any(p.type == 'orientation' for p in pars) 114 elif kind == "1d": 115 return all(p.type != 'orientation' for p in pars) 116 elif kind == "magnetic": 117 return any(p.type == 'sld' for p in pars) 118 elif kind == "nonmagnetic": 119 return not any(p.type == 'sld' for p in pars) 115 120 return False 116 121 … … 317 322 return numpy_dtype, fast, platform 318 323 319 def list_models_main():320 # type: () -> None321 """322 Run list_models as a main program. See :func:`list_models` for the323 kinds of models that can be requested on the command line.324 """325 import sys326 kind = sys.argv[1] if len(sys.argv) > 1 else "all"327 print("\n".join(list_models(kind)))328 329 324 def test_composite_order(): 330 325 def test_models(fst, snd): … … 386 381 assert target == actual, "%s != %s"%(target, actual) 387 382 383 def list_models_main(): 384 # type: () -> None 385 """ 386 Run list_models as a main program. See :func:`list_models` for the 387 kinds of models that can be requested on the command line. 388 """ 389 import sys 390 kind = sys.argv[1] if len(sys.argv) > 1 else "all" 391 try: 392 models = list_models(kind) 393 except Exception as exc: 394 print(list_models.__doc__) 395 return 1 396 397 print("\n".join(list_models(kind))) 398 388 399 if __name__ == "__main__": 389 400 list_models_main() -
sasmodels/model_test.py
raee8dfb 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), … … 90 92 suite = unittest.TestSuite() 91 93 92 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]) 93 97 skip = models[1:] 94 models = list_models(models[0])95 e lse:98 models = group 99 except Exception: 96 100 skip = [] 97 101 for model_name in models: … … 475 479 476 480 477 def main():478 # type: (*str) -> int479 """480 Run tests given is models.481 482 Returns 0 if success or 1 if any tests fail.483 """484 try:485 from xmlrunner import XMLTestRunner as TestRunner486 test_args = {'output': 'logs'}487 except ImportError:488 from unittest import TextTestRunner as TestRunner489 test_args = {}490 491 parser = argparse.ArgumentParser(description="Test SasModels Models")492 parser.add_argument("-v", "--verbose", action="store_const",493 default=1, const=2, help="Use verbose output")494 parser.add_argument("engine", metavar="[engine]",495 help="Engines on which to run the test. "496 "Valid values are opencl, dll, and opencl_and_dll. "497 "Defaults to opencl_and_dll if no value is given")498 parser.add_argument("models", nargs="*",499 help='The names of the models to be tested. '500 'If the first model is "all", then all except the '501 'remaining models will be tested.')502 args, models = parser.parse_known_args()503 504 if args.engine == "opencl":505 if not use_opencl():506 print("opencl is not available")507 return 1508 loaders = ['opencl']509 elif args.engine == "dll":510 loaders = ["dll"]511 elif args.engine == "cuda":512 if not use_cuda():513 print("cuda is not available")514 return 1515 loaders = ['cuda']516 else:517 # Default to running both engines518 loaders = ['dll']519 if use_opencl():520 loaders.append('opencl')521 if use_cuda():522 loaders.append('cuda')523 args.models.insert(0, args.engine)524 525 runner = TestRunner(verbosity=args.verbose, **test_args)526 result = runner.run(make_suite(loaders, args.models))527 return 1 if result.failures or result.errors else 0528 529 530 481 def model_tests(): 531 482 # type: () -> Iterator[Callable[[], None]] … … 562 513 563 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 564 570 if __name__ == "__main__": 565 571 sys.exit(main()) -
sasmodels/modelinfo.py
rfd7291e rd92182f 985 985 #: C code, either defined as a string, or in the sources. 986 986 shell_volume = None # type: Union[None, str, Callable[[np.ndarray], float]] 987 #: Computes the effective radius of the shape given the volume parameters. 988 #: Only needed for models defined in python that can be used for 989 #: monodisperse approximation for non-dilute solutions, P@S. The first 990 #: argument is the integer effective radius mode, with default 0. 991 effective_radius = None # type: Union[None, Callable[[int, np.ndarray], float]] 987 992 #: Returns *I(q, a, b, ...)* for parameters *a*, *b*, etc. defined 988 993 #: by the parameter table. *Iq* can be defined as a python function, or … … 996 1001 #: will return *I(q, a, b, ...)*. Multiplicity parameters are sent as 997 1002 #: pointers to doubles. Constants in floating point expressions should 998 #: include the decimal point. See :mod:`generate` for more details. 1003 #: include the decimal point. See :mod:`generate` for more details. If 1004 #: *have_Fq* is True, then Iq should return an interleaved array of 1005 #: $[\sum F(q_1), \sum F^2(q_1), \ldots, \sum F(q_n), \sum F^2(q_n)]$. 999 1006 Iq = None # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 1000 1007 #: Returns *I(qab, qc, a, b, ...)*. The interface follows :attr:`Iq`.
Note: See TracChangeset
for help on using the changeset viewer.