Changes in / [26d9368:2f46e83] in sasmodels
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
sascomp
r424fe00 r6708a6a 19 19 20 20 import sasmodels.compare 21 sasmodels.compare.main( *sys.argv[1:])21 sasmodels.compare.main() 22 22 23 23 if __name__ == "__main__": -
sasmodels/compare.py
r050c2c8 r050c2c8 789 789 790 790 791 def parse_opts( argv):792 # type: ( List[str]) -> Dict[str, Any]791 def parse_opts(): 792 # type: () -> Dict[str, Any] 793 793 """ 794 794 Parse command line options. 795 795 """ 796 796 MODELS = core.list_models() 797 flags = [arg for arg in argv797 flags = [arg for arg in sys.argv[1:] 798 798 if arg.startswith('-')] 799 values = [arg for arg in argv799 values = [arg for arg in sys.argv[1:] 800 800 if not arg.startswith('-') and '=' in arg] 801 positional_args = [arg for arg in argv801 args = [arg for arg in sys.argv[1:] 802 802 if not arg.startswith('-') and '=' not in arg] 803 803 models = "\n ".join("%-15s"%v for v in MODELS) 804 if len( positional_args) == 0:804 if len(args) == 0: 805 805 print(USAGE) 806 806 print("\nAvailable models:") 807 807 print(columnize(MODELS, indent=" ")) 808 return None809 if len( positional_args) > 3:808 sys.exit(1) 809 if len(args) > 3: 810 810 print("expected parameters: model N1 N2") 811 811 812 name = positional_args[0]812 name = args[0] 813 813 try: 814 814 model_info = core.load_model_info(name) … … 816 816 print(str(exc)) 817 817 print("Could not find model; use one of:\n " + models) 818 return None818 sys.exit(1) 819 819 820 820 invalid = [o[1:] for o in flags … … 823 823 if invalid: 824 824 print("Invalid options: %s"%(", ".join(invalid))) 825 return None825 sys.exit(1) 826 826 827 827 … … 898 898 del engines[2:] 899 899 900 n1 = int( positional_args[1]) if len(positional_args) > 1 else 1901 n2 = int( positional_args[2]) if len(positional_args) > 2 else 1900 n1 = int(args[1]) if len(args) > 1 else 1 901 n2 = int(args[2]) if len(args) > 2 else 1 902 902 use_sasview = any(engine == 'sasview' and count > 0 903 903 for engine, count in zip(engines, [n1, n2])) … … 916 916 s = set(p.split('_pd')[0] for p in pars) 917 917 print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s)))) 918 return None918 sys.exit(1) 919 919 presets[k] = float(v) if not k.endswith('type') else v 920 920 … … 970 970 from bumps.gui.app_frame import AppFrame # type: ignore 971 971 972 problem = FitProblem(Explore(opts)) 972 973 is_mac = "cocoa" in wx.version() 973 # Create an app if not running embedded 974 app = wx.App() if wx.GetApp() is None else None 975 problem = FitProblem(Explore(opts)) 976 frame = AppFrame(parent=None, title="explore", size=(1000,700)) 974 app = wx.App() 975 frame = AppFrame(parent=None, title="explore") 977 976 if not is_mac: frame.Show() 978 977 frame.panel.set_model(model=problem) … … 980 979 frame.panel.aui.Split(0, wx.TOP) 981 980 if is_mac: frame.Show() 982 # If running withing an app, start the main loop 983 if app: app.MainLoop() 981 app.MainLoop() 984 982 985 983 class Explore(object): … … 1050 1048 1051 1049 1052 def main( *argv):1053 # type: ( *str) -> None1050 def main(): 1051 # type: () -> None 1054 1052 """ 1055 1053 Main program. 1056 1054 """ 1057 opts = parse_opts(argv) 1058 if opts is not None: 1059 if opts['explore']: 1060 explore(opts) 1061 else: 1062 compare(opts) 1055 opts = parse_opts() 1056 if opts['explore']: 1057 explore(opts) 1058 else: 1059 compare(opts) 1063 1060 1064 1061 if __name__ == "__main__": 1065 main( *sys.argv[1:])1062 main() -
sasmodels/compare_many.py
r424fe00 r40a87fa 229 229 print_models() 230 230 231 def main( argv):231 def main(): 232 232 """ 233 233 Main program. 234 234 """ 235 if len( argv) not in (5, 6):235 if len(sys.argv) not in (6, 7): 236 236 print_help() 237 return238 239 model = argv[0]237 sys.exit(1) 238 239 model = sys.argv[1] 240 240 if not (model in MODELS) and (model != "all"): 241 241 print('Bad model %s. Use "all" or one of:'%model) 242 242 print_models() 243 return243 sys.exit(1) 244 244 try: 245 count = int( argv[1])246 is2D = argv[2].startswith('2d')247 assert argv[2][1] == 'd'248 Nq = int( argv[2][2:])249 mono = argv[3] == 'mono'250 cutoff = float( argv[3]) if not mono else 0251 base = argv[4]252 comp = argv[5] if len(argv) > 5else "sasview"245 count = int(sys.argv[2]) 246 is2D = sys.argv[3].startswith('2d') 247 assert sys.argv[3][1] == 'd' 248 Nq = int(sys.argv[3][2:]) 249 mono = sys.argv[4] == 'mono' 250 cutoff = float(sys.argv[4]) if not mono else 0 251 base = sys.argv[5] 252 comp = sys.argv[6] if len(sys.argv) > 6 else "sasview" 253 253 except Exception: 254 254 traceback.print_exc() 255 255 print_usage() 256 return256 sys.exit(1) 257 257 258 258 data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0., … … 265 265 if __name__ == "__main__": 266 266 #from .compare import push_seed 267 #with push_seed(1): main( sys.argv[1:])268 main( sys.argv[1:])267 #with push_seed(1): main() 268 main() -
sasmodels/custom/__init__.py
r2a0c7a6 r40a87fa 17 17 def load_module_from_path(fullname, path): 18 18 """load module from *path* as *fullname*""" 19 spec = spec_from_file_location(fullname, os.path.expanduser(path))19 spec = spec_from_file_location(fullname, path) 20 20 module = module_from_spec(spec) 21 21 spec.loader.exec_module(module) … … 26 26 def load_module_from_path(fullname, path): 27 27 """load module from *path* as *fullname*""" 28 module = imp.load_source(fullname, os.path.expanduser(path))28 module = imp.load_source(fullname, path) 29 29 #os.unlink(path+"c") # remove the automatic pyc file 30 30 return module … … 35 35 name = basename(splitext(path)[0]) 36 36 # Placing the model in the 'sasmodels.custom' name space. 37 kernel_module = load_module_from_path('sasmodels.custom.'+name, 38 os.path.expanduser(path)) 37 kernel_module = load_module_from_path('sasmodels.custom.'+name, path) 39 38 return kernel_module -
sasmodels/direct_model.py
r4cc161e rbde38b5 85 85 if model_info.ER is None: 86 86 return 1.0 87 elif not model_info.parameters.form_volume_parameters:88 # handle the case where ER is provided but model is not polydisperse89 return model_info.ER()90 87 else: 91 88 value, weight = _vol_pars(model_info, pars) … … 104 101 if model_info.VR is None: 105 102 return 1.0 106 elif not model_info.parameters.form_volume_parameters:107 # handle the case where ER is provided but model is not polydisperse108 return model_info.VR()109 103 else: 110 104 value, weight = _vol_pars(model_info, pars) … … 158 152 for p in model_info.parameters.call_parameters 159 153 if p.type == 'volume'] 160 #import pylab; pylab.plot(vol_pars[0][0],vol_pars[0][1]); pylab.show()161 154 value, weight = dispersion_mesh(model_info, vol_pars) 162 155 return value, weight … … 402 395 model = build_model(model_info) 403 396 calculator = DirectModel(data, model) 404 pars = dict((k, (float(v) if not k.endswith("_pd_type") elsev))397 pars = dict((k, float(v)) 405 398 for pair in sys.argv[3:] 406 399 for k, v in [pair.split('=')]) -
sasmodels/generate.py
r2e49f9e r52ec91e 362 362 for long double precision. 363 363 """ 364 source = _fix_tgmath_int(source)365 364 if dtype == F16: 366 365 fbytes = 2 … … 392 391 source = re.sub(r'(^|[^a-zA-Z0-9_]c?)double(([248]|16)?($|[^a-zA-Z0-9_]))', 393 392 r'\1%s\2'%type_name, source) 394 source = _tag_float(source, constant_flag)395 return source396 397 TGMATH_INT_RE = re.compile(r"""398 (?: # Non-capturing match; not lookbehind since pattern length is variable399 \b # word boundary400 # various math functions401 (a?(sin|cos|tan)h? | atan2402 | erfc? | tgamma403 | exp(2|10|m1)? | log(2|10|1p)? | pow[nr]? | sqrt | rsqrt | rootn404 | fabs | fmax | fmin405 )406 \s*[(]\s* # open parenthesis407 )408 [+-]?(0|[1-9]\d*) # integer409 (?= # lookahead match: don't want to move from end of int410 \s*[,)] # comma or close parenthesis for end of argument411 ) # end lookahead412 """, re.VERBOSE)413 def _fix_tgmath_int(source):414 # type: (str) -> str415 """416 Replace f(integer) with f(integer.) for sin, cos, pow, etc.417 418 OS X OpenCL complains that it can't resolve the type generic calls to419 the standard math functions when they are called with integer constants,420 but this does not happen with the Windows Intel driver for example.421 To avoid confusion on the matrix marketplace, automatically promote422 integers to floats if we recognize them in the source.423 424 The specific functions we look for are:425 426 trigonometric: sin, asin, sinh, asinh, etc., and atan2427 exponential: exp, exp2, exp10, expm1, log, log2, log10, logp1428 power: pow, pown, powr, sqrt, rsqrt, rootn429 special: erf, erfc, tgamma430 float: fabs, fmin, fmax431 432 Note that we don't convert the second argument of dual argument433 functions: atan2, fmax, fmin, pow, powr. This could potentially434 be a problem for pow(x, 2), but that case seems to work without change.435 """436 out = TGMATH_INT_RE.sub(r'\g<0>.', source)437 return out438 439 440 # Floating point regular expression441 #442 # Define parts:443 #444 # E = [eE][+-]?\d+ : Exponent445 # P = [.] : Decimal separator446 # N = [1-9]\d* : Natural number, no leading zeros447 # Z = 0 : Zero448 # F = \d+ : Fractional number, maybe leading zeros449 # F? = \d* : Optional fractional number450 #451 # We want to reject bare natural numbers and bare decimal points, so we452 # need to tediously outline the cases where we have either a fraction or453 # an exponent:454 #455 # ( ZP | ZPF | ZE | ZPE | ZPFE | NP | NPF | NE | NPE | NPFE | PF | PFE )456 #457 #458 # We can then join cases by making parts optional. The following are459 # some ways to do this:460 #461 # ( (Z|N)(P|PF|E|PE|PFE) | PFE? ) # Split on lead462 # => ( (Z|N)(PF?|(PF?)?E) | PFE? )463 # ( ((Z|N)PF?|PF)E? | (Z|N)E) # Split on point464 # ( (ZP|ZPF|NP|NPF|PF) | (Z|ZP|ZPF|N|NP|NPF|PF)E ) # Split on E465 # => ( ((Z|N)PF?|PF) | ((Z|N)(PF?)? | PF) E )466 FLOAT_RE = re.compile(r"""467 (?<!\w) # use negative lookbehind since '.' confuses \b test468 # use split on lead to match float ( (Z|N)(PF?|(PF?)?E) | PFE? )469 ( ( 0 | [1-9]\d* ) # ( ( Z | N )470 ([.]\d* | ([.]\d*)? [eE][+-]?\d+ ) # (PF? | (PF?)? E )471 | [.]\d+ ([eE][+-]?\d+)? # | PF (E)?472 ) # )473 (?!\w) # use negative lookahead since '.' confuses \b test474 """, re.VERBOSE)475 def _tag_float(source, constant_flag):476 393 # Convert floating point constants to single by adding 'f' to the end, 477 394 # or long double with an 'L' suffix. OS/X complains if you don't do this. 478 out = FLOAT_RE.sub(r'\g<0>%s'%constant_flag, source) 479 #print("in",repr(source),"out",repr(out), constant_flag) 480 return out 481 482 def test_tag_float(): 483 484 cases=""" 485 ZP : 0. 486 ZPF : 0.0,0.01,0.1 487 Z E: 0e+001 488 ZP E: 0.E0 489 ZPFE: 0.13e-031 490 NP : 1., 12. 491 NPF : 1.0001, 1.1, 1.0 492 N E: 1e0, 37E-080 493 NP E: 1.e0, 37.E-080 494 NPFE: 845.017e+22 495 PF : .1, .0, .0100 496 PFE: .6e+9, .82E-004 497 # isolated cases 498 0. 499 1e0 500 0.13e-013 501 # untouched 502 struct3.e3, 03.05.67, 37 503 # expressions 504 3.75+-1.6e-7-27+13.2 505 a3.e2 - 0. 506 4*atan(1) 507 4.*atan(1.) 508 """ 509 510 output=""" 511 ZP : 0.f 512 ZPF : 0.0f,0.01f,0.1f 513 Z E: 0e+001f 514 ZP E: 0.E0f 515 ZPFE: 0.13e-031f 516 NP : 1.f, 12.f 517 NPF : 1.0001f, 1.1f, 1.0f 518 N E: 1e0f, 37E-080f 519 NP E: 1.e0f, 37.E-080f 520 NPFE: 845.017e+22f 521 PF : .1f, .0f, .0100f 522 PFE: .6e+9f, .82E-004f 523 # isolated cases 524 0.f 525 1e0f 526 0.13e-013f 527 # untouched 528 struct3.e3, 03.05.67, 37 529 # expressions 530 3.75f+-1.6e-7f-27+13.2f 531 a3.e2 - 0.f 532 4*atan(1) 533 4.f*atan(1.f) 534 """ 535 536 for case_in, case_out in zip(cases.split('\n'), output.split('\n')): 537 out = _tag_float(case_in, 'f') 538 assert case_out == out, "%r => %r"%(case_in, out) 395 source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 396 r'\g<0>%s'%constant_flag, source) 397 return source 539 398 540 399 … … 847 706 Iq_units = "The returned value is scaled to units of |cm^-1| |sr^-1|, absolute scale." 848 707 Sq_units = "The returned value is a dimensionless structure factor, $S(q)$." 849 docs = model_info.docs if model_info.docs is not None else "" 850 docs = convert_section_titles_to_boldface(docs) 708 docs = convert_section_titles_to_boldface(model_info.docs) 851 709 pars = make_partable(model_info.parameters.COMMON 852 710 + model_info.parameters.kernel_parameters) … … 860 718 861 719 862 # TODO: need a single source for rst_prolog; it is also in doc/rst_prolog863 RST_PROLOG = """\864 .. |Ang| unicode:: U+212B865 .. |Ang^-1| replace:: |Ang|\ :sup:`-1`866 .. |Ang^2| replace:: |Ang|\ :sup:`2`867 .. |Ang^-2| replace:: |Ang|\ :sup:`-2`868 .. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2`869 .. |Ang^3| replace:: |Ang|\ :sup:`3`870 .. |Ang^-3| replace:: |Ang|\ :sup:`-3`871 .. |Ang^-4| replace:: |Ang|\ :sup:`-4`872 .. |cm^-1| replace:: cm\ :sup:`-1`873 .. |cm^2| replace:: cm\ :sup:`2`874 .. |cm^-2| replace:: cm\ :sup:`-2`875 .. |cm^3| replace:: cm\ :sup:`3`876 .. |1e15cm^3| replace:: 10\ :sup:`15`\ cm\ :sup:`3`877 .. |cm^-3| replace:: cm\ :sup:`-3`878 .. |sr^-1| replace:: sr\ :sup:`-1`879 .. |P0| replace:: P\ :sub:`0`\880 881 .. |equiv| unicode:: U+2261882 .. |noteql| unicode:: U+2260883 .. |TM| unicode:: U+2122884 885 .. |cdot| unicode:: U+00B7886 .. |deg| unicode:: U+00B0887 .. |g/cm^3| replace:: g\ |cdot|\ cm\ :sup:`-3`888 .. |mg/m^2| replace:: mg\ |cdot|\ m\ :sup:`-2`889 .. |fm^2| replace:: fm\ :sup:`2`890 .. |Ang*cm^-1| replace:: |Ang|\ |cdot|\ cm\ :sup:`-1`891 """892 893 # TODO: make a better fake reference role894 RST_ROLES = """\895 .. role:: ref896 897 .. role:: numref898 899 """900 901 720 def make_html(model_info): 902 721 """ … … 904 723 """ 905 724 from . import rst2html 906 907 rst = make_doc(model_info) 908 return rst2html.rst2html("".join((RST_ROLES, RST_PROLOG, rst))) 909 910 def view_html(model_name): 911 from . import rst2html 912 from . import modelinfo 913 kernel_module = load_kernel_module(model_name) 914 info = modelinfo.make_model_info(kernel_module) 915 url = "file://"+dirname(info.filename)+"/" 916 rst2html.wxview(make_html(info), url=url) 725 return rst2html.convert(make_doc(model_info)) 917 726 918 727 def demo_time(): -
sasmodels/kerneldll.py
r3764ec1 r14a15a3 2 2 DLL driver for C kernels 3 3 4 If the environment variable *SAS_OPENMP* is set, then sasmodels 5 will attempt to compile with OpenMP flags so that the model can use all 6 available kernels. This may or may not be available on your compiler 7 toolchain. Depending on operating system and environment. 8 9 Windows does not have provide a compiler with the operating system. 10 Instead, we assume that TinyCC is installed and available. This can 11 be done with a simple pip command if it is not already available:: 12 13 pip install tinycc 14 15 If Microsoft Visual C++ is available (because VCINSTALLDIR is 16 defined in the environment), then that will be used instead. 17 Microsoft Visual C++ for Python is available from Microsoft: 4 The global attribute *ALLOW_SINGLE_PRECISION_DLLS* should be set to *True* if 5 you wish to allow single precision floating point evaluation for the compiled 6 models, otherwise it defaults to *False*. 7 8 The compiler command line is stored in the attribute *COMPILE*, with string 9 substitutions for %(source)s and %(output)s indicating what to compile and 10 where to store it. The actual command is system dependent. 11 12 On windows systems, you have a choice of compilers. *MinGW* is the GNU 13 compiler toolchain, available in packages such as anaconda and PythonXY, 14 or available stand alone. This toolchain has had difficulties on some 15 systems, and may or may not work for you. In order to build DLLs, *gcc* 16 must be on your path. If the environment variable *SAS_OPENMP* is given 17 then -fopenmp is added to the compiler flags. This requires a version 18 of MinGW compiled with OpenMP support. 19 20 An alternative toolchain uses the Microsoft Visual C++ compiler, available 21 free from microsoft: 18 22 19 23 `<http://www.microsoft.com/en-us/download/details.aspx?id=44266>`_ 20 24 21 If neither compiler is available, sasmodels will check for *MinGW*, 22 the GNU compiler toolchain. This available in packages such as Anaconda 23 and PythonXY, or available stand alone. This toolchain has had 24 difficulties on some systems, and may or may not work for you. 25 26 You can control which compiler to use by setting SAS_COMPILER in the 27 environment: 28 29 - tinycc (Windows): use the TinyCC compiler shipped with SasView 30 - msvc (Windows): use the Microsoft Visual C++ compiler 31 - mingw (Windows): use the MinGW GNU cc compiler 32 - unix (Linux): use the system cc compiler. 33 - unix (Mac): use the clang compiler. You will need XCode installed, and 34 the XCode command line tools. Mac comes with OpenCL drivers, so generally 35 this will not be needed. 36 37 Both *msvc* and *mingw* require that the compiler is available on your path. 38 For *msvc*, this can done by running vcvarsall.bat in a windows terminal. 39 Install locations are system dependent, such as: 25 Again, this requires that the compiler is available on your path. This is 26 done by running vcvarsall.bat in a windows terminal. Install locations are 27 system dependent, such as: 40 28 41 29 C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat … … 45 33 C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 46 34 47 OpenMP for *msvc* requires the Microsoft vcomp90.dll library, which doesn't 48 seem to be included with the compiler, nor does there appear to be a public 49 download location. There may be one on your machine already in a location 50 such as: 35 And again, the environment variable *SAS_OPENMP* controls whether OpenMP is 36 used to compile the C code. This requires the Microsoft vcomp90.dll library, 37 which doesn't seem to be included with the compiler, nor does there appear 38 to be a public download location. There may be one on your machine already 39 in a location such as: 51 40 52 41 C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll 53 42 54 If you copy this to somewhere on your path, such as the python directory or 55 the install directory for this application, then OpenMP should be supported. 56 57 For full control of the compiler, define a function 58 *compile_command(source,output)* which takes the name of the source file 59 and the name of the output file and returns a compile command that can be 60 evaluated in the shell. For even more control, replace the entire 61 *compile(source,output)* function. 62 63 The global attribute *ALLOW_SINGLE_PRECISION_DLLS* should be set to *False* if 64 you wish to prevent single precision floating point evaluation for the compiled 65 models, otherwise set it defaults to *True*. 43 If you copy this onto your path, such as the python directory or the install 44 directory for this application, then OpenMP should be supported. 66 45 """ 67 46 from __future__ import print_function … … 111 90 compiler = "unix" 112 91 113 ARCH = "" if ct.sizeof(c_void_p) > 4 else "x86" # 4 byte pointers on x8692 ARCH = "" if sys.maxint > 2**32 else "x86" # maxint=2**31-1 on 32 bit 114 93 if compiler == "unix": 115 94 # Generic unix compile -
sasmodels/model_test.py
r897ca7f r40a87fa 50 50 import numpy as np # type: ignore 51 51 52 from . import core 53 from .core import list_models, load_model_info, build_model 52 from .core import list_models, load_model_info, build_model, HAVE_OPENCL 54 53 from .direct_model import call_kernel, call_ER, call_VR 55 54 from .exception import annotate_exception … … 99 98 if is_py: # kernel implemented in python 100 99 test_name = "Model: %s, Kernel: python"%model_name 101 test_method_name = "test_%s_python" % model_ info.id100 test_method_name = "test_%s_python" % model_name 102 101 test = ModelTestCase(test_name, model_info, 103 102 test_method_name, … … 107 106 else: # kernel implemented in C 108 107 # test using opencl if desired and available 109 if 'opencl' in loaders and core.HAVE_OPENCL:108 if 'opencl' in loaders and HAVE_OPENCL: 110 109 test_name = "Model: %s, Kernel: OpenCL"%model_name 111 test_method_name = "test_%s_opencl" % model_ info.id110 test_method_name = "test_%s_opencl" % model_name 112 111 # Using dtype=None so that the models that are only 113 112 # correct for double precision are not tested using … … 123 122 if 'dll' in loaders: 124 123 test_name = "Model: %s, Kernel: dll"%model_name 125 test_method_name = "test_%s_dll" % model_ info.id124 test_method_name = "test_%s_dll" % model_name 126 125 test = ModelTestCase(test_name, model_info, 127 126 test_method_name, … … 250 249 return abs(target-actual)/shift < 1.5*10**-digits 251 250 252 def run_one(model): 253 # type: (str) -> None 254 """ 255 Run the tests for a single model, printing the results to stdout. 256 257 *model* can by a python file, which is handy for checking user defined 258 plugin models. 259 """ 260 # Note that running main() directly did not work from within the 261 # wxPython pycrust console. Instead of the results appearing in the 262 # window they were printed to the underlying console. 263 from unittest.runner import TextTestResult, _WritelnDecorator 264 265 # Build a object to capture and print the test results 266 stream = _WritelnDecorator(sys.stdout) # Add writeln() method to stream 267 verbosity = 2 268 descriptions = True 269 result = TextTestResult(stream, descriptions, verbosity) 270 271 # Build a test suite containing just the model 272 loaders = ['opencl'] 273 models = [model] 274 try: 275 suite = make_suite(loaders, models) 276 except Exception: 277 import traceback 278 stream.writeln(traceback.format_exc()) 279 return 280 281 # Run the test suite 282 suite.run(result) 283 284 # Print the failures and errors 285 for _, tb in result.errors: 286 stream.writeln(tb) 287 for _, tb in result.failures: 288 stream.writeln(tb) 289 290 # Check if there are user defined tests. 291 # Yes, it is naughty to peek into the structure of the test suite, and 292 # to assume that it contains only one test. 293 if not suite._tests[0].info.tests: 294 stream.writeln("Note: %s has no user defined tests."%model) 295 296 297 def main(*models): 298 # type: (*str) -> int 299 """ 300 Run tests given is models. 251 def main(): 252 # type: () -> int 253 """ 254 Run tests given is sys.argv. 301 255 302 256 Returns 0 if success or 1 if any tests fail. … … 309 263 test_args = {} 310 264 265 models = sys.argv[1:] 311 266 if models and models[0] == '-v': 312 267 verbosity = 2 … … 315 270 verbosity = 1 316 271 if models and models[0] == 'opencl': 317 if not core.HAVE_OPENCL:272 if not HAVE_OPENCL: 318 273 print("opencl is not available") 319 274 return 1 … … 363 318 364 319 if __name__ == "__main__": 365 sys.exit(main( *sys.argv[1:]))320 sys.exit(main()) -
sasmodels/models/core_multi_shell.py
r7b68dc5 r8c6fbbc 132 132 def ER(radius, n, thickness): 133 133 """Effective radius""" 134 n = int(n[0])# n cannot be polydisperse134 n = n[0] # n cannot be polydisperse 135 135 return np.sum(thickness[:n], axis=0) + radius 136 136 -
sasmodels/models/onion.py
r7b68dc5 r3cd1001 368 368 def ER(core_radius, n, thickness): 369 369 """Effective radius""" 370 return np.sum(thickness[: int(n[0])], axis=0) + core_radius370 return np.sum(thickness[:n[0]], axis=0) + core_radius 371 371 372 372 demo = { -
sasmodels/models/sphere.py
r7e6bea81 r9a4811a 2 2 For information about polarised and magnetic scattering, see 3 3 the :ref:`magnetism` documentation. 4 documentation. 4 5 5 6 Definition … … 15 16 16 17 where *scale* is a volume fraction, $V$ is the volume of the scatterer, 17 $r$ is the radius of the sphere and *background* is the background level.18 $r$ is the radius of the sphere, *background* is the background level and 18 19 *sld* and *sld_solvent* are the scattering length densities (SLDs) of the 19 scatterer and the solvent respectively , whose difference is $\Delta\rho$.20 scatterer and the solvent respectively. 20 21 21 22 Note that if your data is in absolute scale, the *scale* should represent … … 90 91 radius=120, 91 92 radius_pd=.2, radius_pd_n=45) 92 93 tests = [94 [{}, 0.2, 0.726362],95 [{"scale": 1., "background": 0., "sld": 6., "sld_solvent": 1.,96 "radius": 120., "radius_pd": 0.2, "radius_pd_n":45},97 0.2, 0.228843],98 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "ER", 120.],99 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "VR", 1.],100 ]101 102 -
sasmodels/rst2html.py
rb217c71 r40a87fa 10 10 from contextlib import contextmanager 11 11 12 # CRUFT: locale.getlocale() fails on some versions of OS X13 # See https://bugs.python.org/issue1837814 import locale15 if hasattr(locale, '_parse_localename'):16 try:17 locale._parse_localename('UTF-8')18 except ValueError:19 _old_parse_localename = locale._parse_localename20 def _parse_localename(localename):21 code = locale.normalize(localename)22 if code == 'UTF-8':23 return None, code24 else:25 return _old_parse_localename(localename)26 locale._parse_localename = _parse_localename27 28 12 from docutils.core import publish_parts 29 13 from docutils.writers.html4css1 import HTMLTranslator 30 14 from docutils.nodes import SkipNode 31 15 32 def wxview(html, url="", size=(850, 540)):33 import wx34 from wx.html2 import WebView35 frame = wx.Frame(None, -1, size=size)36 view = WebView.New(frame)37 view.SetPage(html, url)38 frame.Show()39 return frame40 16 41 def view_rst(filename): 42 from os.path import expanduser 43 with open(expanduser(filename)) as fid: 44 rst = fid.read() 45 html = rst2html(rst) 46 wxview(html) 47 48 def rst2html(rst, part="whole", math_output="mathjax"): 17 def rst2html(rst, part="whole", math_output="html"): 49 18 r""" 50 19 Convert restructured text into simple html. … … 75 44 else: 76 45 settings = {"math-output": math_output} 77 78 # TODO: support stylesheets79 #html_root = "/full/path/to/_static/"80 #sheets = [html_root+s for s in ["basic.css","classic.css"]]81 #settings["embed_styesheet"] = True82 #settings["stylesheet_path"] = sheets83 46 84 47 # math2html and mathml do not support \frac12 … … 141 104 assert replace_dollar(u"and $mid$ too") == u"and :math:`mid` too" 142 105 assert replace_dollar(u"$first$, $mid$, $last$") == u":math:`first`, :math:`mid`, :math:`last`" 143 assert replace_dollar(u "dollar\\$ escape") == u"dollar$ escape"144 assert replace_dollar(u "dollar \\$escape\\$ too") == u"dollar $escape$ too"106 assert replace_dollar(ur"dollar\$ escape") == u"dollar$ escape" 107 assert replace_dollar(ur"dollar \$escape\$ too") == u"dollar $escape$ too" 145 108 assert replace_dollar(u"spaces $in the$ math") == u"spaces :math:`in the` math" 146 assert replace_dollar(u "emb\\ $ed$\\ ed") == u"emb\\ :math:`ed`\\ ed"109 assert replace_dollar(ur"emb\ $ed$\ ed") == ur"emb\ :math:`ed`\ ed" 147 110 assert replace_dollar(u"$first$a") == u"$first$a" 148 111 assert replace_dollar(u"a$last$") == u"a$last$" -
sasmodels/weights.py
rf1a8811 rf1a8811 10 10 import numpy as np # type: ignore 11 11 from scipy.special import gammaln # type: ignore 12 13 # TODO: include dispersion docs with the disperser models14 12 15 13 class Dispersion(object):
Note: See TracChangeset
for help on using the changeset viewer.