Changeset d247047 in sasmodels


Ignore:
Timestamp:
Oct 1, 2016 10:04:32 PM (4 years ago)
Author:
butler
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
f837f0b, 3a45c2c, 8e960b0
Parents:
5f1acda (diff), 79906d1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://github.com/SasView/sasmodels.git

Files:
15 edited

Legend:

Unmodified
Added
Removed
  • sascomp

    r6708a6a r424fe00  
    1919 
    2020    import sasmodels.compare 
    21     sasmodels.compare.main() 
     21    sasmodels.compare.main(*sys.argv[1:]) 
    2222 
    2323if __name__ == "__main__": 
  • sasmodels/__init__.py

    rb2377b0 r79906d1  
    1414defining new models. 
    1515""" 
    16 __version__ = "0.93" 
     16__version__ = "0.94" 
    1717 
    1818def data_files(): 
  • sasmodels/compare.py

    r050c2c8 r41e7f2e  
    789789 
    790790 
    791 def parse_opts(): 
    792     # type: () -> Dict[str, Any] 
     791def parse_opts(argv): 
     792    # type: (List[str]) -> Dict[str, Any] 
    793793    """ 
    794794    Parse command line options. 
    795795    """ 
    796796    MODELS = core.list_models() 
    797     flags = [arg for arg in sys.argv[1:] 
     797    flags = [arg for arg in argv 
    798798             if arg.startswith('-')] 
    799     values = [arg for arg in sys.argv[1:] 
     799    values = [arg for arg in argv 
    800800              if not arg.startswith('-') and '=' in arg] 
    801     args = [arg for arg in sys.argv[1:] 
     801    positional_args = [arg for arg in argv 
    802802            if not arg.startswith('-') and '=' not in arg] 
    803803    models = "\n    ".join("%-15s"%v for v in MODELS) 
    804     if len(args) == 0: 
     804    if len(positional_args) == 0: 
    805805        print(USAGE) 
    806806        print("\nAvailable models:") 
    807807        print(columnize(MODELS, indent="  ")) 
    808         sys.exit(1) 
    809     if len(args) > 3: 
     808        return None 
     809    if len(positional_args) > 3: 
    810810        print("expected parameters: model N1 N2") 
    811811 
    812     name = args[0] 
     812    name = positional_args[0] 
    813813    try: 
    814814        model_info = core.load_model_info(name) 
     
    816816        print(str(exc)) 
    817817        print("Could not find model; use one of:\n    " + models) 
    818         sys.exit(1) 
     818        return None 
    819819 
    820820    invalid = [o[1:] for o in flags 
     
    823823    if invalid: 
    824824        print("Invalid options: %s"%(", ".join(invalid))) 
    825         sys.exit(1) 
     825        return None 
    826826 
    827827 
     
    898898        del engines[2:] 
    899899 
    900     n1 = int(args[1]) if len(args) > 1 else 1 
    901     n2 = int(args[2]) if len(args) > 2 else 1 
     900    n1 = int(positional_args[1]) if len(positional_args) > 1 else 1 
     901    n2 = int(positional_args[2]) if len(positional_args) > 2 else 1 
    902902    use_sasview = any(engine == 'sasview' and count > 0 
    903903                      for engine, count in zip(engines, [n1, n2])) 
     
    916916            s = set(p.split('_pd')[0] for p in pars) 
    917917            print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s)))) 
    918             sys.exit(1) 
     918            return None 
    919919        presets[k] = float(v) if not k.endswith('type') else v 
    920920 
     
    970970    from bumps.gui.app_frame import AppFrame  # type: ignore 
    971971 
     972    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 
    972975    problem = FitProblem(Explore(opts)) 
    973     is_mac = "cocoa" in wx.version() 
    974     app = wx.App() 
    975     frame = AppFrame(parent=None, title="explore") 
     976    frame = AppFrame(parent=None, title="explore", size=(1000,700)) 
    976977    if not is_mac: frame.Show() 
    977978    frame.panel.set_model(model=problem) 
     
    979980    frame.panel.aui.Split(0, wx.TOP) 
    980981    if is_mac: frame.Show() 
    981     app.MainLoop() 
     982    # If running withing an app, start the main loop 
     983    if app: app.MainLoop() 
    982984 
    983985class Explore(object): 
     
    10481050 
    10491051 
    1050 def main(): 
    1051     # type: () -> None 
     1052def main(*argv): 
     1053    # type: (*str) -> None 
    10521054    """ 
    10531055    Main program. 
    10541056    """ 
    1055     opts = parse_opts() 
    1056     if opts['explore']: 
    1057         explore(opts) 
    1058     else: 
    1059         compare(opts) 
     1057    opts = parse_opts(argv) 
     1058    if opts is not None: 
     1059        if opts['explore']: 
     1060            explore(opts) 
     1061        else: 
     1062            compare(opts) 
    10601063 
    10611064if __name__ == "__main__": 
    1062     main() 
     1065    main(*sys.argv[1:]) 
  • sasmodels/compare_many.py

    r40a87fa r424fe00  
    229229    print_models() 
    230230 
    231 def main(): 
     231def main(argv): 
    232232    """ 
    233233    Main program. 
    234234    """ 
    235     if len(sys.argv) not in (6, 7): 
     235    if len(argv) not in (5, 6): 
    236236        print_help() 
    237         sys.exit(1) 
    238  
    239     model = sys.argv[1] 
     237        return 
     238 
     239    model = argv[0] 
    240240    if not (model in MODELS) and (model != "all"): 
    241241        print('Bad model %s.  Use "all" or one of:'%model) 
    242242        print_models() 
    243         sys.exit(1) 
     243        return 
    244244    try: 
    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" 
     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 0 
     251        base = argv[4] 
     252        comp = argv[5] if len(argv) > 5 else "sasview" 
    253253    except Exception: 
    254254        traceback.print_exc() 
    255255        print_usage() 
    256         sys.exit(1) 
     256        return 
    257257 
    258258    data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0., 
     
    265265if __name__ == "__main__": 
    266266    #from .compare import push_seed 
    267     #with push_seed(1): main() 
    268     main() 
     267    #with push_seed(1): main(sys.argv[1:]) 
     268    main(sys.argv[1:]) 
  • sasmodels/custom/__init__.py

    r40a87fa r2a0c7a6  
    1717    def load_module_from_path(fullname, path): 
    1818        """load module from *path* as *fullname*""" 
    19         spec = spec_from_file_location(fullname, path) 
     19        spec = spec_from_file_location(fullname, os.path.expanduser(path)) 
    2020        module = module_from_spec(spec) 
    2121        spec.loader.exec_module(module) 
     
    2626    def load_module_from_path(fullname, path): 
    2727        """load module from *path* as *fullname*""" 
    28         module = imp.load_source(fullname, path) 
     28        module = imp.load_source(fullname, os.path.expanduser(path)) 
    2929        #os.unlink(path+"c")  # remove the automatic pyc file 
    3030        return module 
     
    3535    name = basename(splitext(path)[0]) 
    3636    # Placing the model in the 'sasmodels.custom' name space. 
    37     kernel_module = load_module_from_path('sasmodels.custom.'+name, path) 
     37    kernel_module = load_module_from_path('sasmodels.custom.'+name, 
     38                                          os.path.expanduser(path)) 
    3839    return kernel_module 
  • sasmodels/direct_model.py

    rbde38b5 r4cc161e  
    8585    if model_info.ER is None: 
    8686        return 1.0 
     87    elif not model_info.parameters.form_volume_parameters: 
     88        # handle the case where ER is provided but model is not polydisperse 
     89        return model_info.ER() 
    8790    else: 
    8891        value, weight = _vol_pars(model_info, pars) 
     
    101104    if model_info.VR is None: 
    102105        return 1.0 
     106    elif not model_info.parameters.form_volume_parameters: 
     107        # handle the case where ER is provided but model is not polydisperse 
     108        return model_info.VR() 
    103109    else: 
    104110        value, weight = _vol_pars(model_info, pars) 
     
    152158                for p in model_info.parameters.call_parameters 
    153159                if p.type == 'volume'] 
     160    #import pylab; pylab.plot(vol_pars[0][0],vol_pars[0][1]); pylab.show() 
    154161    value, weight = dispersion_mesh(model_info, vol_pars) 
    155162    return value, weight 
     
    395402    model = build_model(model_info) 
    396403    calculator = DirectModel(data, model) 
    397     pars = dict((k, float(v)) 
     404    pars = dict((k, (float(v) if not k.endswith("_pd_type") else v)) 
    398405                for pair in sys.argv[3:] 
    399406                for k, v in [pair.split('=')]) 
  • sasmodels/generate.py

    r52ec91e r2e49f9e  
    362362    for long double precision. 
    363363    """ 
     364    source = _fix_tgmath_int(source) 
    364365    if dtype == F16: 
    365366        fbytes = 2 
     
    391392    source = re.sub(r'(^|[^a-zA-Z0-9_]c?)double(([248]|16)?($|[^a-zA-Z0-9_]))', 
    392393                    r'\1%s\2'%type_name, source) 
     394    source = _tag_float(source, constant_flag) 
     395    return source 
     396 
     397TGMATH_INT_RE = re.compile(r""" 
     398(?: # Non-capturing match; not lookbehind since pattern length is variable 
     399  \b              # word boundary 
     400   # various math functions 
     401  (a?(sin|cos|tan)h? | atan2 
     402   | erfc? | tgamma 
     403   | exp(2|10|m1)? | log(2|10|1p)? | pow[nr]? | sqrt | rsqrt | rootn 
     404   | fabs | fmax | fmin 
     405   ) 
     406  \s*[(]\s*       # open parenthesis 
     407) 
     408[+-]?(0|[1-9]\d*) # integer 
     409(?=               # lookahead match: don't want to move from end of int 
     410  \s*[,)]         # comma or close parenthesis for end of argument 
     411)                 # end lookahead 
     412""", re.VERBOSE) 
     413def _fix_tgmath_int(source): 
     414    # type: (str) -> str 
     415    """ 
     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 to 
     419    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 promote 
     422    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 atan2 
     427        exponential:   exp, exp2, exp10, expm1, log, log2, log10, logp1 
     428        power:         pow, pown, powr, sqrt, rsqrt, rootn 
     429        special:       erf, erfc, tgamma 
     430        float:         fabs, fmin, fmax 
     431 
     432    Note that we don't convert the second argument of dual argument 
     433    functions: atan2, fmax, fmin, pow, powr.  This could potentially 
     434    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 out 
     438 
     439 
     440# Floating point regular expression 
     441# 
     442# Define parts: 
     443# 
     444#    E = [eE][+-]?\d+    : Exponent 
     445#    P = [.]             : Decimal separator 
     446#    N = [1-9]\d*        : Natural number, no leading zeros 
     447#    Z = 0               : Zero 
     448#    F = \d+             : Fractional number, maybe leading zeros 
     449#    F? = \d*            : Optional fractional number 
     450# 
     451# We want to reject bare natural numbers and bare decimal points, so we 
     452# need to tediously outline the cases where we have either a fraction or 
     453# 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 are 
     459# some ways to do this: 
     460# 
     461#   ( (Z|N)(P|PF|E|PE|PFE) | PFE? )                   # Split on lead 
     462#     => ( (Z|N)(PF?|(PF?)?E) | PFE? ) 
     463#   ( ((Z|N)PF?|PF)E? | (Z|N)E)                       # Split on point 
     464#   ( (ZP|ZPF|NP|NPF|PF) | (Z|ZP|ZPF|N|NP|NPF|PF)E )  # Split on E 
     465#     => ( ((Z|N)PF?|PF) | ((Z|N)(PF?)? | PF) E ) 
     466FLOAT_RE = re.compile(r""" 
     467    (?<!\w)  # use negative lookbehind since '.' confuses \b test 
     468    # 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 test 
     474    """, re.VERBOSE) 
     475def _tag_float(source, constant_flag): 
    393476    # Convert floating point constants to single by adding 'f' to the end, 
    394477    # or long double with an 'L' suffix.  OS/X complains if you don't do this. 
    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 
     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 
     482def test_tag_float(): 
     483 
     484    cases=""" 
     485ZP  : 0. 
     486ZPF : 0.0,0.01,0.1 
     487Z  E: 0e+001 
     488ZP E: 0.E0 
     489ZPFE: 0.13e-031 
     490NP  : 1., 12. 
     491NPF : 1.0001, 1.1, 1.0 
     492N  E: 1e0, 37E-080 
     493NP E: 1.e0, 37.E-080 
     494NPFE: 845.017e+22 
     495 PF : .1, .0, .0100 
     496 PFE: .6e+9, .82E-004 
     497# isolated cases 
     4980. 
     4991e0 
     5000.13e-013 
     501# untouched 
     502struct3.e3, 03.05.67, 37 
     503# expressions 
     5043.75+-1.6e-7-27+13.2 
     505a3.e2 - 0. 
     5064*atan(1) 
     5074.*atan(1.) 
     508""" 
     509 
     510    output=""" 
     511ZP  : 0.f 
     512ZPF : 0.0f,0.01f,0.1f 
     513Z  E: 0e+001f 
     514ZP E: 0.E0f 
     515ZPFE: 0.13e-031f 
     516NP  : 1.f, 12.f 
     517NPF : 1.0001f, 1.1f, 1.0f 
     518N  E: 1e0f, 37E-080f 
     519NP E: 1.e0f, 37.E-080f 
     520NPFE: 845.017e+22f 
     521 PF : .1f, .0f, .0100f 
     522 PFE: .6e+9f, .82E-004f 
     523# isolated cases 
     5240.f 
     5251e0f 
     5260.13e-013f 
     527# untouched 
     528struct3.e3, 03.05.67, 37 
     529# expressions 
     5303.75f+-1.6e-7f-27+13.2f 
     531a3.e2 - 0.f 
     5324*atan(1) 
     5334.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) 
    398539 
    399540 
     
    706847    Iq_units = "The returned value is scaled to units of |cm^-1| |sr^-1|, absolute scale." 
    707848    Sq_units = "The returned value is a dimensionless structure factor, $S(q)$." 
    708     docs = convert_section_titles_to_boldface(model_info.docs) 
     849    docs = model_info.docs if model_info.docs is not None else "" 
     850    docs = convert_section_titles_to_boldface(docs) 
    709851    pars = make_partable(model_info.parameters.COMMON 
    710852                         + model_info.parameters.kernel_parameters) 
     
    718860 
    719861 
     862# TODO: need a single source for rst_prolog; it is also in doc/rst_prolog 
     863RST_PROLOG = """\ 
     864.. |Ang| unicode:: U+212B 
     865.. |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+2261 
     882.. |noteql| unicode:: U+2260 
     883.. |TM| unicode:: U+2122 
     884 
     885.. |cdot| unicode:: U+00B7 
     886.. |deg| unicode:: U+00B0 
     887.. |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 role 
     894RST_ROLES = """\ 
     895.. role:: ref 
     896 
     897.. role:: numref 
     898 
     899""" 
     900 
    720901def make_html(model_info): 
    721902    """ 
     
    723904    """ 
    724905    from . import rst2html 
    725     return rst2html.convert(make_doc(model_info)) 
     906 
     907    rst = make_doc(model_info) 
     908    return rst2html.rst2html("".join((RST_ROLES, RST_PROLOG, rst))) 
     909 
     910def 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) 
    726917 
    727918def demo_time(): 
  • sasmodels/kerneldll.py

    r14a15a3 r3764ec1  
    22DLL driver for C kernels 
    33 
    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: 
     4If the environment variable *SAS_OPENMP* is set, then sasmodels 
     5will attempt to compile with OpenMP flags so that the model can use all 
     6available kernels.  This may or may not be available on your compiler 
     7toolchain.  Depending on operating system and environment. 
     8 
     9Windows does not have provide a compiler with the operating system. 
     10Instead, we assume that TinyCC is installed and available.  This can 
     11be done with a simple pip command if it is not already available:: 
     12 
     13    pip install tinycc 
     14 
     15If Microsoft Visual C++ is available (because VCINSTALLDIR is 
     16defined in the environment), then that will be used instead. 
     17Microsoft Visual C++ for Python is available from Microsoft: 
    2218 
    2319    `<http://www.microsoft.com/en-us/download/details.aspx?id=44266>`_ 
    2420 
    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: 
     21If neither compiler is available, sasmodels will check for *MinGW*, 
     22the GNU compiler toolchain. This available in packages such as Anaconda 
     23and PythonXY, or available stand alone. This toolchain has had 
     24difficulties on some systems, and may or may not work for you. 
     25 
     26You can control which compiler to use by setting SAS_COMPILER in the 
     27environment: 
     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 
     37Both *msvc* and *mingw* require that the compiler is available on your path. 
     38For *msvc*, this can done by running vcvarsall.bat in a windows terminal. 
     39Install locations are system dependent, such as: 
    2840 
    2941    C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
     
    3345    C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
    3446 
    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: 
     47OpenMP for *msvc* requires the Microsoft vcomp90.dll library, which doesn't 
     48seem to be included with the compiler, nor does there appear to be a public 
     49download location.  There may be one on your machine already in a location 
     50such as: 
    4051 
    4152    C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll 
    4253 
    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. 
     54If you copy this to somewhere on your path, such as the python directory or 
     55the install directory for this application, then OpenMP should be supported. 
     56 
     57For full control of the compiler, define a function 
     58*compile_command(source,output)* which takes the name of the source file 
     59and the name of the output file and returns a compile command that can be 
     60evaluated in the shell.  For even more control, replace the entire 
     61*compile(source,output)* function. 
     62 
     63The global attribute *ALLOW_SINGLE_PRECISION_DLLS* should be set to *False* if 
     64you wish to prevent single precision floating point evaluation for the compiled 
     65models, otherwise set it defaults to *True*. 
    4566""" 
    4667from __future__ import print_function 
     
    90111    compiler = "unix" 
    91112 
    92 ARCH = "" if sys.maxint > 2**32 else "x86"  # maxint=2**31-1 on 32 bit 
     113ARCH = "" if ct.sizeof(c_void_p) > 4 else "x86"  # 4 byte pointers on x86 
    93114if compiler == "unix": 
    94115    # Generic unix compile 
  • sasmodels/model_test.py

    r40a87fa r897ca7f  
    5050import numpy as np  # type: ignore 
    5151 
    52 from .core import list_models, load_model_info, build_model, HAVE_OPENCL 
     52from . import core 
     53from .core import list_models, load_model_info, build_model 
    5354from .direct_model import call_kernel, call_ER, call_VR 
    5455from .exception import annotate_exception 
     
    9899        if is_py:  # kernel implemented in python 
    99100            test_name = "Model: %s, Kernel: python"%model_name 
    100             test_method_name = "test_%s_python" % model_name 
     101            test_method_name = "test_%s_python" % model_info.id 
    101102            test = ModelTestCase(test_name, model_info, 
    102103                                 test_method_name, 
     
    106107        else:   # kernel implemented in C 
    107108            # test using opencl if desired and available 
    108             if 'opencl' in loaders and HAVE_OPENCL: 
     109            if 'opencl' in loaders and core.HAVE_OPENCL: 
    109110                test_name = "Model: %s, Kernel: OpenCL"%model_name 
    110                 test_method_name = "test_%s_opencl" % model_name 
     111                test_method_name = "test_%s_opencl" % model_info.id 
    111112                # Using dtype=None so that the models that are only 
    112113                # correct for double precision are not tested using 
     
    122123            if 'dll' in loaders: 
    123124                test_name = "Model: %s, Kernel: dll"%model_name 
    124                 test_method_name = "test_%s_dll" % model_name 
     125                test_method_name = "test_%s_dll" % model_info.id 
    125126                test = ModelTestCase(test_name, model_info, 
    126127                                     test_method_name, 
     
    249250    return abs(target-actual)/shift < 1.5*10**-digits 
    250251 
    251 def main(): 
    252     # type: () -> int 
    253     """ 
    254     Run tests given is sys.argv. 
     252def 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 
     297def main(*models): 
     298    # type: (*str) -> int 
     299    """ 
     300    Run tests given is models. 
    255301 
    256302    Returns 0 if success or 1 if any tests fail. 
     
    263309        test_args = {} 
    264310 
    265     models = sys.argv[1:] 
    266311    if models and models[0] == '-v': 
    267312        verbosity = 2 
     
    270315        verbosity = 1 
    271316    if models and models[0] == 'opencl': 
    272         if not HAVE_OPENCL: 
     317        if not core.HAVE_OPENCL: 
    273318            print("opencl is not available") 
    274319            return 1 
     
    318363 
    319364if __name__ == "__main__": 
    320     sys.exit(main()) 
     365    sys.exit(main(*sys.argv[1:])) 
  • sasmodels/models/core_multi_shell.py

    r8c6fbbc r7b68dc5  
    132132def ER(radius, n, thickness): 
    133133    """Effective radius""" 
    134     n = n[0]  # n cannot be polydisperse 
     134    n = int(n[0])  # n cannot be polydisperse 
    135135    return np.sum(thickness[:n], axis=0) + radius 
    136136 
  • sasmodels/models/onion.py

    r3cd1001 r7b68dc5  
    368368def ER(core_radius, n, thickness): 
    369369    """Effective radius""" 
    370     return np.sum(thickness[:n[0]], axis=0) + core_radius 
     370    return np.sum(thickness[:int(n[0])], axis=0) + core_radius 
    371371 
    372372demo = { 
  • sasmodels/models/sphere.py

    r9a4811a r7e6bea81  
    22For information about polarised and magnetic scattering, see 
    33the :ref:`magnetism` documentation. 
    4 documentation. 
    54 
    65Definition 
     
    1615 
    1716where *scale* is a volume fraction, $V$ is the volume of the scatterer, 
    18 $r$ is the radius of the sphere, *background* is the background level and 
     17$r$ is the radius of the sphere and *background* is the background level. 
    1918*sld* and *sld_solvent* are the scattering length densities (SLDs) of the 
    20 scatterer and the solvent respectively. 
     19scatterer and the solvent respectively, whose difference is $\Delta\rho$. 
    2120 
    2221Note that if your data is in absolute scale, the *scale* should represent 
     
    9190            radius=120, 
    9291            radius_pd=.2, radius_pd_n=45) 
     92 
     93tests = [ 
     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

    r40a87fa rb217c71  
    1010from contextlib import contextmanager 
    1111 
     12# CRUFT: locale.getlocale() fails on some versions of OS X 
     13# See https://bugs.python.org/issue18378 
     14import locale 
     15if hasattr(locale, '_parse_localename'): 
     16    try: 
     17        locale._parse_localename('UTF-8') 
     18    except ValueError: 
     19        _old_parse_localename = locale._parse_localename 
     20        def _parse_localename(localename): 
     21            code = locale.normalize(localename) 
     22            if code == 'UTF-8': 
     23                return None, code 
     24            else: 
     25                return _old_parse_localename(localename) 
     26        locale._parse_localename = _parse_localename 
     27 
    1228from docutils.core import publish_parts 
    1329from docutils.writers.html4css1 import HTMLTranslator 
    1430from docutils.nodes import SkipNode 
    1531 
     32def wxview(html, url="", size=(850, 540)): 
     33    import wx 
     34    from wx.html2 import WebView 
     35    frame = wx.Frame(None, -1, size=size) 
     36    view = WebView.New(frame) 
     37    view.SetPage(html, url) 
     38    frame.Show() 
     39    return frame 
    1640 
    17 def rst2html(rst, part="whole", math_output="html"): 
     41def 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 
     48def rst2html(rst, part="whole", math_output="mathjax"): 
    1849    r""" 
    1950    Convert restructured text into simple html. 
     
    4475    else: 
    4576        settings = {"math-output": math_output} 
     77 
     78    # TODO: support stylesheets 
     79    #html_root = "/full/path/to/_static/" 
     80    #sheets = [html_root+s for s in ["basic.css","classic.css"]] 
     81    #settings["embed_styesheet"] = True 
     82    #settings["stylesheet_path"] = sheets 
    4683 
    4784    # math2html and mathml do not support \frac12 
     
    104141    assert replace_dollar(u"and $mid$ too") == u"and :math:`mid` too" 
    105142    assert replace_dollar(u"$first$, $mid$, $last$") == u":math:`first`, :math:`mid`, :math:`last`" 
    106     assert replace_dollar(ur"dollar\$ escape") == u"dollar$ escape" 
    107     assert replace_dollar(ur"dollar \$escape\$ too") == u"dollar $escape$ too" 
     143    assert replace_dollar(u"dollar\\$ escape") == u"dollar$ escape" 
     144    assert replace_dollar(u"dollar \\$escape\\$ too") == u"dollar $escape$ too" 
    108145    assert replace_dollar(u"spaces $in the$ math") == u"spaces :math:`in the` math" 
    109     assert replace_dollar(ur"emb\ $ed$\ ed") == ur"emb\ :math:`ed`\ ed" 
     146    assert replace_dollar(u"emb\\ $ed$\\ ed") == u"emb\\ :math:`ed`\\ ed" 
    110147    assert replace_dollar(u"$first$a") == u"$first$a" 
    111148    assert replace_dollar(u"a$last$") == u"a$last$" 
  • sasmodels/weights.py

    rf1a8811 r41e7f2e  
    1010import numpy as np  # type: ignore 
    1111from scipy.special import gammaln  # type: ignore 
     12 
     13# TODO: include dispersion docs with the disperser models 
    1214 
    1315class Dispersion(object): 
  • sasmodels/conversion_table.py

    r2f46e83 r5f1acda  
    144144    ], 
    145145    "core_shell_ellipsoid": [ 
     146        "CoreShellEllipsoidModel", 
     147        { 
     148            "phi": "axis_phi", 
     149            "sld_core": "sld_core", 
     150            "polar_shell": "polar_shell", 
     151            "sld_solvent": "sld_solvent", 
     152            "equat_shell": "equat_shell", 
     153            "equat_core": "equat_core", 
     154            "theta": "axis_theta", 
     155            "polar_core": "polar_core", 
     156            "sld_shell": "sld_shell" 
     157        } 
     158    ], 
     159    "core_shell_ellipsoid": [ 
    146160        "CoreShellEllipsoidXTModel", 
    147161        { 
Note: See TracChangeset for help on using the changeset viewer.