Changeset 1a6cd57 in sasmodels


Ignore:
Timestamp:
Oct 11, 2016 9:25:56 AM (7 years ago)
Author:
jhbakker
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
2ccb775, 997d4eb
Parents:
c1904f6
Message:

commit of stuff from master from fast-merge

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • doc/ref/gpu/gpu_computations.rst

    r711f17e r1a6cd57  
    55**************** 
    66SasView model evaluations can run on your graphics card (GPU) or they can run 
    7 on the processor (CPU). 
     7on the processor (CPU). In general, calculations performed on the GPU will run faster. 
    88 
    99To run on the GPU, your computer must have OpenCL drivers installed. 
     
    3939chose to run the model. 
    4040 
    41 If you don't want to use OpenCL, you can set *SAS_OPENCL=None* 
    42 in the environment, and it will only use normal programs. 
     41**If you don't want to use OpenCL, you can set** *SAS_OPENCL=None* 
     42**in your environment settings, and it will only use normal programs.** 
    4343 
    4444If you want to use one of the other devices, you can run the following 
  • sasmodels/compare.py

    rbb2d187 r1a6cd57  
    8080    -edit starts the parameter explorer 
    8181    -default/-demo* use demo vs default parameters 
     82    -html shows the model docs instead of running the model 
    8283 
    8384Any two calculation engines can be selected for comparison: 
     
    736737    'linear', 'log', 'q4', 
    737738    'hist', 'nohist', 
    738     'edit', 
     739    'edit', 'html', 
    739740    'demo', 'default', 
    740741    ]) 
     
    845846        'use_demo'  : True, 
    846847        'zero'      : False, 
     848        'html'      : False, 
    847849    } 
    848850    engines = [] 
     
    886888        elif arg == '-demo':    opts['use_demo'] = True 
    887889        elif arg == '-default':    opts['use_demo'] = False 
     890        elif arg == '-html':    opts['html'] = True 
    888891    # pylint: enable=bad-whitespace 
    889892 
     
    961964    return opts 
    962965 
     966def show_docs(opts): 
     967    # type: (Dict[str, Any]) -> None 
     968    """ 
     969    show html docs for the model 
     970    """ 
     971    import wx  # type: ignore 
     972    from .generate import view_html_from_info 
     973    app = wx.App() if wx.GetApp() is None else None 
     974    view_html_from_info(opts['def']) 
     975    if app: app.MainLoop() 
     976 
     977 
    963978def explore(opts): 
    964979    # type: (Dict[str, Any]) -> None 
    965980    """ 
    966     Explore the model using the Bumps GUI. 
     981    explore the model using the bumps gui. 
    967982    """ 
    968983    import wx  # type: ignore 
     
    10571072    opts = parse_opts(argv) 
    10581073    if opts is not None: 
    1059         if opts['explore']: 
     1074        if opts['html']: 
     1075            show_docs(opts) 
     1076        elif opts['explore']: 
    10601077            explore(opts) 
    10611078        else: 
  • sasmodels/custom/__init__.py

    r2a0c7a6 r1a6cd57  
    88to occur without error. 
    99""" 
     10from __future__ import division, print_function 
    1011 
     12import sys 
    1113import os 
    1214from os.path import basename, splitext 
     
    2628    def load_module_from_path(fullname, path): 
    2729        """load module from *path* as *fullname*""" 
     30        # Clear out old definitions, if any 
     31        if fullname in sys.modules: 
     32            del sys.modules[fullname] 
    2833        module = imp.load_source(fullname, os.path.expanduser(path)) 
    2934        #os.unlink(path+"c")  # remove the automatic pyc file 
  • sasmodels/generate.py

    r462a115 r1a6cd57  
    912912 
    913913def view_html(model_name): 
    914     from . import rst2html 
    915914    from . import modelinfo 
    916915    kernel_module = load_kernel_module(model_name) 
    917916    info = modelinfo.make_model_info(kernel_module) 
     917    view_html_from_info(info) 
     918 
     919def view_html_from_info(info): 
     920    from . import rst2html 
    918921    url = "file://"+dirname(info.filename)+"/" 
    919922    rst2html.wxview(make_html(info), url=url) 
  • sasmodels/model_test.py

    r897ca7f r1a6cd57  
    121121 
    122122            # test using dll if desired 
    123             if 'dll' in loaders: 
     123            if 'dll' in loaders or not core.HAVE_OPENCL: 
    124124                test_name = "Model: %s, Kernel: dll"%model_name 
    125125                test_method_name = "test_%s_dll" % model_info.id 
     
    270270 
    271271    # Build a test suite containing just the model 
    272     loaders = ['opencl'] 
     272    loaders = ['opencl'] if core.HAVE_OPENCL else ['dll'] 
    273273    models = [model] 
    274274    try: 
     
    288288        stream.writeln(tb) 
    289289 
    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) 
     290    # Warn if there are no user defined tests. 
     291    # Note: the test suite constructed above only has one test in it, which 
     292    # runs through some smoke tests to make sure the model runs, then runs 
     293    # through the input-output pairs given in the model definition file.  To 
     294    # check if any such pairs are defined, therefore, we just need to check if 
     295    # they are in the first test of the test suite.  We do this with an 
     296    # iterator since we don't have direct access to the list of tests in the 
     297    # test suite. 
     298    for test in suite: 
     299        if not test.info.tests: 
     300            stream.writeln("Note: %s has no user defined tests."%model) 
     301        break 
     302    else: 
     303        stream.writeln("Note: no test suite created --- this should never happen") 
    295304 
    296305 
     
    325334        models = models[1:] 
    326335    elif models and models[0] == 'opencl_and_dll': 
    327         loaders = ['opencl', 'dll'] 
     336        loaders = ['opencl', 'dll'] if core.HAVE_OPENCL else ['dll'] 
    328337        models = models[1:] 
    329338    else: 
    330         loaders = ['opencl', 'dll'] 
     339        loaders = ['opencl', 'dll'] if core.HAVE_OPENCL else ['dll'] 
    331340    if not models: 
    332341        print("""\ 
     
    357366    Run "nosetests sasmodels" on the command line to invoke it. 
    358367    """ 
    359     tests = make_suite(['opencl', 'dll'], ['all']) 
     368    loaders = ['opencl', 'dll'] if core.HAVE_OPENCL else ['dll'] 
     369    tests = make_suite(loaders, ['all']) 
    360370    for test_i in tests: 
    361         yield test_i.run_all 
     371        # In order for nosetest to see the correct test name, need to set 
     372        # the description attribute of the returned function.  Since we 
     373        # can't do this for the returned instance, wrap it in a lambda and 
     374        # set the description on the lambda.  Otherwise we could just do: 
     375        #    yield test_i.run_all 
     376        L = lambda: test_i.run_all() 
     377        L.description = test_i.test_name 
     378        yield L 
    362379 
    363380 
  • sasmodels/models/core_shell_bicelle.py

    r416f5c7 r1a6cd57  
    4040.. math:: 
    4141 
    42     I(Q,\alpha) = \frac{\text{scale}}{V} \cdot 
     42    I(Q,\alpha) = \frac{\text{scale}}{V_t} \cdot 
    4343        F(Q,\alpha)^2 + \text{background} 
    4444 
  • sasmodels/models/multilayer_vesicle.py

    r9a4811a r1a6cd57  
    55This model is a trivial extension of the core_shell_sphere function to include 
    66*N* shells where the core is filled with solvent and the shells are interleaved 
    7 with layers of solvent. For *N = 1*, this returns the same as the vesicle model. 
    8 The shell thicknessess and SLD are constant across all shells as expected for 
     7with layers of solvent. For *N = 1*, this returns the same as the vesicle model, 
     8except for the normalisation, which here is to outermost volume. 
     9The shell thicknessess and SLD are constant for all shells as expected for 
    910a multilayer vesicle. 
    1011 
     
    1516See the :ref:`core-shell-sphere` model for more documentation. 
    1617 
     18The 1D scattering intensity is calculated in the following way (Guinier, 1955) 
     19 
     20.. math:: 
     21 
     22    P(q) = \frac{\text{scale.volfraction}}{V_t} F^2(q) + \text{background} 
     23 
     24where 
     25 
     26.. math:: 
     27 
     28     F(q) = (\rho_{shell}-\rho_{solv}) \sum_{i=1}^{n\_pairs} \left[ 
     29     3V(R_i)\frac{\sin(qR_i)-qR_i\cos(qR_i)}{(qR_i)^3} \\ 
     30      - 3V(R_i+t_s)\frac{\sin(q(R_i+t_s))-q(R_i+t_s)\cos(q(R_i+t_s))}{(q(R_i+t_s))^3} 
     31     \right] 
     32 
     33 
     34where $R_i = r_c + (i-1)(t_s + t_w)$ 
     35    
     36where $V_t$ is the volume of the whole particle, $V(R)$ is the volume of a sphere 
     37of radius $R$, $r_c$ is the radius of the core, $\rho_{shell}$ is the scattering length  
     38density of a shell, $\rho_{solv}$ is the scattering length density of the solvent. 
     39 
     40 
    1741The 2D scattering intensity is the same as 1D, regardless of the orientation 
    1842of the q vector which is defined as: 
     
    2246    q = \sqrt{q_x^2 + q_y^2} 
    2347 
    24 .. note: 
    25     The outer most radius 
    26     $radius + n_pairs * thicn_shell + (n_pairs - 1) * thick_solvent$ 
    27     is used as the effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 
     48 
     49The outer most radius 
     50 
     51$radius + n\_pairs * thick\_shell + (n\_pairs- 1) * thick\_solvent$ 
     52 
     53is used for both the volume fraction normalization and for the  
     54effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 
    2855 
    2956For information about polarised and magnetic scattering, see 
     
    6289    sld_solvent: solvent scattering length density 
    6390    sld: shell scattering length density 
    64     n_pairs:number of pairs of water/shell 
     91    n_pairs:number of "shell plus solvent" layer pairs 
    6592    background: incoherent background 
    6693        """ 
     
    7198parameters = [ 
    7299    ["volfraction", "",  0.05, [0.0, 1],  "", "volume fraction of vesicles"], 
    73     ["radius", "Ang", 60.0, [0.0, inf],  "", "Core radius of the multishell"], 
    74     ["thick_shell", "Ang",        10.0, [0.0, inf],  "", "Shell thickness"], 
    75     ["thick_solvent", "Ang",        10.0, [0.0, inf],  "", "Water thickness"], 
    76     ["sld_solvent",    "1e-6/Ang^2",  6.4, [-inf, inf], "sld", "Core scattering length density"], 
     100    ["radius", "Ang", 60.0, [0.0, inf],  "", "radius of solvent filled core"], 
     101    ["thick_shell", "Ang",        10.0, [0.0, inf],  "", "thickness of one shell"], 
     102    ["thick_solvent", "Ang",        10.0, [0.0, inf],  "", "solvent thickness between shells"], 
     103    ["sld_solvent",    "1e-6/Ang^2",  6.4, [-inf, inf], "sld", "solvent scattering length density"], 
    77104    ["sld",   "1e-6/Ang^2",  0.4, [-inf, inf], "sld", "Shell scattering length density"], 
    78     ["n_pairs",     "",            2.0, [1.0, inf],  "", "Number of pairs of water and shell"], 
     105    ["n_pairs",     "",            2.0, [1.0, inf],  "", "Number of shell plus solvent layer pairs"], 
    79106    ] 
    80107# pylint: enable=bad-whitespace, line-too-long 
  • sasmodels/models/vesicle.py

    r42356c8 r1a6cd57  
    7575        thickness: the shell thickness 
    7676        sld: the shell SLD 
    77         sld_slovent: the solvent (and core) SLD 
     77        sld_solvent: the solvent (and core) SLD 
    7878        background: incoherent background 
    7979        volfraction: shell volume fraction 
  • sasmodels/sasview_model.py

    r5b37fd6 r1a6cd57  
    115115    Load a custom model given the model path. 
    116116    """ 
    117     #print("load custom", path) 
    118117    kernel_module = custom.load_custom_kernel_module(path) 
    119118    try: 
     
    124123        if model.name == "": 
    125124            model.name = splitext(basename(path))[0] 
     125        if not hasattr(model, 'filename'): 
     126            model.filename = kernel_module.__file__ 
     127            # For old models, treat .pyc and .py files interchangeably. 
     128            # This is needed because of the Sum|Multi(p1,p2) types of models 
     129            # and the convoluted way in which they are created. 
     130            if model.filename.endswith(".py"): 
     131                logging.info("Loading %s as .pyc", model.filename) 
     132                model.filename = model.filename+'c' 
     133        if not hasattr(model, 'id'): 
     134            model.id = splitext(basename(model.filename))[0] 
    126135    except AttributeError: 
    127136        model_info = modelinfo.make_model_info(kernel_module) 
    128137        model = _make_model_from_info(model_info) 
     138 
     139    # If a model name already exists and we are loading a different model, 
     140    # use the model file name as the model name. 
     141    if model.name in MODELS and not model.filename == MODELS[model.name].filename: 
     142        _previous_name = model.name 
     143        model.name = model.id 
     144         
     145        # If the new model name is still in the model list (for instance, 
     146        # if we put a cylinder.py in our plug-in directory), then append 
     147        # an identifier. 
     148        if model.name in MODELS and not model.filename == MODELS[model.name].filename: 
     149            model.name = model.id + '_user' 
     150        logging.info("Model %s already exists: using %s [%s]", _previous_name, model.name, model.filename) 
     151 
    129152    MODELS[model.name] = model 
    130153    return model 
     
    154177    attrs = _generate_model_attributes(model_info) 
    155178    attrs['__init__'] = __init__ 
     179    attrs['filename'] = model_info.filename 
    156180    ConstructedModel = type(model_info.name, (SasviewModel,), attrs) # type: SasviewModelType 
    157181    return ConstructedModel 
     
    311335        else: 
    312336            hidden = set() 
     337        if self._model_info.structure_factor: 
     338            hidden.add('scale') 
     339            hidden.add('background') 
     340            self._model_info.parameters.defaults['background'] = 0. 
    313341 
    314342        self._persistency_dict = {} 
     
    575603                            magnetic=is_magnetic) 
    576604        calculator.release() 
    577         try: 
    578             self._model.release() 
    579         except: 
    580             pass 
     605        self._model.release() 
    581606        return result 
    582607 
     
    659684                return [self.multiplicity], [1.0] 
    660685            else: 
    661                 return [np.NaN], [1.0] 
     686                # For hidden parameters use the default value. 
     687                value = self._model_info.parameters.defaults.get(par.name, np.NaN) 
     688                return [value], [1.0] 
    662689        elif par.polydisperse: 
    663690            dis = self.dispersion[par.name] 
     
    680707    cylinder = Cylinder() 
    681708    return cylinder.evalDistribution([0.1, 0.1]) 
     709 
     710def test_structure_factor(): 
     711    # type: () -> float 
     712    """ 
     713    Test that a sasview model (cylinder) can be run. 
     714    """ 
     715    Model = _make_standard_model('hardsphere') 
     716    model = Model() 
     717    value = model.evalDistribution([0.1, 0.1]) 
     718    if np.isnan(value): 
     719        raise ValueError("hardsphere returns null") 
    682720 
    683721def test_rpa(): 
Note: See TracChangeset for help on using the changeset viewer.