Changeset faf83f2 in sasmodels


Ignore:
Timestamp:
Feb 9, 2017 2:39:36 AM (7 years ago)
Author:
wojciech
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
1896dff
Parents:
4c8a5b4 (diff), 1105286 (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

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/conversion_table.py

    rfa6d6fc r790b16bb  
    55names for each parameter in sasmodels.  This is used by :mod:`convert` to 
    66determine the equivalent parameter set when comparing a sasmodels model to 
    7 the models defined in SasView 3.1. 
     7the models defined in previous versions of SasView and sasmodels. This is now 
     8versioned based on the version number of SasView. 
     9 
     10When any sasmodels parameter or model name is changed, this must be modified to 
     11account for that. 
     12 
     13Usage: 
     14<old_Sasview_version> : { 
     15    <new_model_name> : [ 
     16        <old_model_name> , 
     17        { 
     18            <new_param_name_1> : <old_param_name_1>, 
     19            ... 
     20            <new_param_name_n> : <old_param_name_n> 
     21        } 
     22    ] 
     23} 
     24 
     25Any future parameter and model name changes can and should be given in this 
     26table for future compatibility. 
    827""" 
    928 
    10  
    1129CONVERSION_TABLE = { 
     30    (3,1,2) : { 
    1231    "adsorbed_layer": [ 
    1332        "Core2ndMomentModel", 
     
    211230    ], 
    212231    "correlation_length": [ 
    213         "CorrLengthModel", 
     232        "CorrLength", 
    214233        { 
    215234            "porod_scale": "scale_p", 
     
    218237            "lorentz_exp": "exponent_l", 
    219238            "cor_length": "length_l" 
    220         } 
     239        }, 
     240        "CorrLengthModel" 
    221241    ], 
    222242    "cylinder": [ 
     
    299319    ], 
    300320    "fractal_core_shell": [ 
    301         "FractalCoreShellModel", 
     321        "FractalCoreShell", 
    302322        { 
    303323            "sld_core": "core_sld", 
     
    309329            "cor_length": "cor_length", 
    310330            "volfraction": "volfraction", 
    311         } 
     331        }, 
     332        "FractalCoreShellModel" 
    312333    ], 
    313334    "fuzzy_sphere": [ 
     
    321342    ], 
    322343    "gauss_lorentz_gel": [ 
    323         "GaussLorentzGelModel", 
     344        "GaussLorentzGel", 
    324345        { 
    325346            "gauss_scale": "scale_g", 
     
    328349            "background": "background", 
    329350            "lorentz_scale": "scale_l" 
    330         } 
     351        }, 
     352        "GaussLorentzGelModel" 
    331353    ], 
    332354    "gaussian_peak": [ 
    333         "PeakGaussModel", 
     355        "Peak Gauss Model", 
    334356        { 
    335357            "peak_pos": "q0", 
    336358            "sigma": "B", 
    337         } 
     359        }, 
     360        "PeakGaussModel", 
    338361    ], 
    339362    "gel_fit": [ 
     
    343366            "lorentz_scale": "lScale", 
    344367            "guinier_scale": "gScale", 
    345             "fractal_dim": "scale", 
     368            "fractal_dim": "FractalExp", 
    346369            "cor_length": "zeta", 
    347370        } 
    348371    ], 
    349372    "guinier": [ 
     373        "Guinier", 
     374        { 
     375            "rg": "rg" 
     376        }, 
    350377        "GuinierModel", 
    351         { 
    352             "rg": "rg" 
    353         } 
    354378    ], 
    355379    "guinier_porod": [ 
    356         "GuinierPorodModel", 
     380        "GuinierPorod", 
    357381        { 
    358382            "s": "dim", 
     
    361385            "scale": "scale", 
    362386            "background": "background" 
    363         } 
     387        }, 
     388        "GuinierPorodModel", 
    364389    ], 
    365390    "hardsphere": [ 
     
    454479            "d_spacing": "spacing", 
    455480            "Caille_parameter": "caille", 
    456             "Nlayers": "N_plates", 
     481            "Nlayers": "n_plates", 
    457482        } 
    458483    ], 
     
    486511    ], 
    487512    "lorentz": [ 
     513        "Lorentz", 
     514        { 
     515            "cor_length": "length" 
     516        }, 
    488517        "LorentzModel", 
    489         { 
    490             "cor_length": "length" 
    491         } 
    492518    ], 
    493519    "mass_fractal": [ 
     
    510536    ], 
    511537    "mono_gauss_coil": [ 
    512         "DebyeModel", 
     538        "Debye", 
    513539        { 
    514540            "rg": "rg", 
    515541            "i_zero": "scale", 
    516542            "background": "background", 
    517         } 
     543        }, 
     544        "DebyeModel", 
    518545    ], 
    519546    "multilayer_vesicle": [ 
     
    564591    ], 
    565592    "peak_lorentz": [ 
    566         "PeakLorentzModel", 
     593        "Peak Lorentz Model", 
    567594        { 
    568595            "peak_pos": "q0", 
    569596            "peak_hwhm": "B" 
    570         } 
     597        }, 
     598        "PeakLorentzModel", 
    571599    ], 
    572600    "pearl_necklace": [ 
     
    802830    ], 
    803831    "two_lorentzian": [ 
    804         "TwoLorentzianModel", 
     832        "TwoLorentzian", 
    805833        { 
    806834            "lorentz_scale_1": "scale_1", 
     
    811839            "lorentz_length_1": "length_1", 
    812840            "background": "background" 
    813         } 
     841        }, 
     842        "TwoLorentzianModel", 
    814843    ], 
    815844    "two_power_law": [ 
    816         "TwoPowerLawModel", 
     845        "TwoPowerLaw", 
    817846        { 
    818847            "coefficent_1": "coef_A", 
     
    821850            "background": "background", 
    822851            "crossover": "qc" 
    823         } 
     852        }, 
     853        "TwoPowerLawModel", 
    824854    ], 
    825855    "unified_power_Rg": [ 
     856        "UnifiedPowerRg", 
     857        dict(((field_new+str(index), field_old+str(index)) 
     858              for field_new, field_old in [("rg", "Rg"), 
     859                                           ("power", "power"), 
     860                                           ("G", "G"), 
     861                                           ("B", "B"),] 
     862              for index in range(11)), 
     863             **{ 
     864                   "background": "background", 
     865                   "scale": "scale", 
     866               }), 
    826867        "UnifiedPowerRgModel", 
    827         { 
    828         } 
    829868    ], 
    830869    "vesicle": [ 
     
    835874        } 
    836875    ] 
     876    } 
    837877} 
  • sasmodels/convert.py

    rf80f334 r07c8d46  
    5353    ("_pd_nsigma", ".nsigmas"), 
    5454    ("_pd_type", ".type"), 
     55    (".lower", ".lower"), 
     56    (".upper", ".upper"), 
     57    (".fittable", ".fittable"), 
     58    (".std", ".std"), 
     59    (".units", ".units"), 
     60    ("", "") 
    5561    ] 
    5662 
     
    6470    if id.startswith('M0:'): 
    6571        return True 
    66     if id.startswith('volfraction') or id.startswith('radius_effective'): 
    67         return False 
    6872    if '_pd' in id or '.' in id: 
    6973        return False 
     
    7579        if p.id == id: 
    7680            return p.type == 'sld' 
    77     raise ValueError("unknown parameter %r in conversion"%id) 
     81    return False 
    7882 
    7983def _rescale_sld(model_info, pars, scale): 
     
    8892 
    8993 
    90 def _get_translation_table(model_info): 
    91     _, translation = CONVERSION_TABLE.get(model_info.id, [None, {}]) 
    92     translation = translation.copy() 
     94def _get_translation_table(model_info, version=(3,1,2)): 
     95    conv_param = CONVERSION_TABLE.get(version, {}).get(model_info.id, [None, {}]) 
     96    translation = conv_param[1].copy() 
    9397    for p in model_info.parameters.kernel_parameters: 
    9498        if p.length > 1: 
     
    119123def _pd_to_underscores(pars): 
    120124    return dict((_dot_pd_to_underscore_pd(k), v) for k, v in pars.items()) 
    121  
    122 def _convert_name(conv_dict, pars): 
    123     """ 
    124     Renames parameter values (upper, lower, etc) to v4.0 names 
    125     :param conv_dict: conversion dictionary mapping new name : old name 
    126     :param pars: parameters to convert 
    127     :return: 
    128     """ 
    129     new_pars = {} 
    130     i = 0 
    131     j = 0 
    132     for key_par, value_par in pars.iteritems(): 
    133         j += 1 
    134         for key_conv, value_conv in conv_dict.iteritems(): 
    135             if re.search(value_conv, key_par): 
    136                 new_pars[key_par.replace(value_conv, key_conv)] = value_par 
    137                 i += 1 
    138                 break 
    139             elif re.search("background", key_par) or re.search("scale", key_par): 
    140                 new_pars[key_par] = value_par 
    141                 i += 1 
    142                 break 
    143         if i != j: 
    144             new_pars[key_par] = value_par 
    145             i += 1 
    146     return new_pars 
    147125 
    148126def _convert_pars(pars, mapping): 
     
    167145    return newpars 
    168146 
    169  
    170 def _conversion_target(model_name): 
     147def _conversion_target(model_name, version=(3,1,2)): 
    171148    """ 
    172149    Find the sasmodel name which translates into the sasview name. 
     
    176153    two variants in sasview. 
    177154    """ 
    178     for sasmodels_name, [sasview_name, _] in CONVERSION_TABLE.items(): 
    179         if sasview_name == model_name: 
     155    for sasmodels_name, sasview_dict in \ 
     156            CONVERSION_TABLE.get(version, {}).items(): 
     157        if sasview_dict[0] == model_name: 
    180158            return sasmodels_name 
    181159    return None 
    182160 
    183  
    184 def _hand_convert(name, oldpars): 
     161def _hand_convert(name, oldpars, version=(3,1,2)): 
     162    if version == (3,1,2): 
     163        oldpars = _hand_convert_3_1_2_to_4_1(name, oldpars) 
     164    return oldpars 
     165 
     166def _hand_convert_3_1_2_to_4_1(name, oldpars): 
    185167    if name == 'core_shell_parallelepiped': 
    186168        # Make sure pd on rim parameters defaults to zero 
     
    215197            pd = oldpars['radius.width']*oldpars['radius']/thickness 
    216198            oldpars['radius.width'] = pd 
     199    elif name == 'multilayer_vesicle': 
     200        if 'scale' in oldpars: 
     201            oldpars['volfraction'] = oldpars['scale'] 
     202            oldpars['scale'] = 1.0 
     203        if 'scale.lower' in oldpars: 
     204            oldpars['volfraction.lower'] = oldpars['scale.lower'] 
     205        if 'scale.upper' in oldpars: 
     206            oldpars['volfraction.upper'] = oldpars['scale.upper'] 
     207        if 'scale.fittable' in oldpars: 
     208            oldpars['volfraction.fittable'] = oldpars['scale.fittable'] 
     209        if 'scale.std' in oldpars: 
     210            oldpars['volfraction.std'] = oldpars['scale.std'] 
     211        if 'scale.units' in oldpars: 
     212            oldpars['volfraction.units'] = oldpars['scale.units'] 
    217213    elif name == 'pearl_necklace': 
    218214        pass 
     
    236232                oldpars[p + ".upper"] /= 1e-13 
    237233    elif name == 'spherical_sld': 
    238         oldpars["CONTROL"] += 1 
     234        j = 0 
     235        while "func_inter" + str(j) in oldpars: 
     236            name = "func_inter" + str(j) 
     237            new_name = "shape" + str(j + 1) 
     238            if oldpars[name] == 'Erf(|nu|*z)': 
     239                oldpars[new_name] = int(0) 
     240            elif oldpars[name] == 'RPower(z^|nu|)': 
     241                oldpars[new_name] = int(1) 
     242            elif oldpars[name] == 'LPower(z^|nu|)': 
     243                oldpars[new_name] = int(2) 
     244            elif oldpars[name] == 'RExp(-|nu|*z)': 
     245                oldpars[new_name] = int(3) 
     246            elif oldpars[name] == 'LExp(-|nu|*z)': 
     247                oldpars[new_name] = int(4) 
     248            else: 
     249                oldpars[new_name] = int(0) 
     250            oldpars.pop(name) 
     251            oldpars['n_shells'] = str(j + 1) 
     252            j += 1 
    239253    elif name == 'teubner_strey': 
    240254        # basically undoing the entire Teubner-Strey calculations here. 
     
    281295    return oldpars 
    282296 
    283 def convert_model(name, pars, use_underscore=False): 
     297def convert_model(name, pars, use_underscore=False, model_version=(3,1,2)): 
    284298    """ 
    285299    Convert model from old style parameter names to new style. 
    286300    """ 
    287     newname = _conversion_target(name) 
    288     if newname is None: 
    289         return name, pars 
    290     if ':' in newname:   # core_shell_ellipsoid:1 
    291         model_info = load_model_info(newname[:-2]) 
    292         # Know that the table exists and isn't multiplicity so grab it directly 
    293         # Can't use _get_translation_table since that will return the 'bare' 
    294         # version. 
    295         translation = CONVERSION_TABLE[newname][1] 
    296     else: 
    297         model_info = load_model_info(newname) 
    298         translation = _get_translation_table(model_info) 
    299     newpars = _hand_convert(newname, pars.copy()) 
    300     newpars = _convert_name(translation, newpars) 
    301     newpars = _convert_pars(newpars, translation) 
    302     if not model_info.structure_factor: 
    303         newpars = _rescale_sld(model_info, newpars, 1e6) 
    304     newpars.setdefault('scale', 1.0) 
    305     newpars.setdefault('background', 0.0) 
    306     if use_underscore: 
    307         newpars = _pd_to_underscores(newpars) 
     301    newpars = pars 
     302    keys = sorted(CONVERSION_TABLE.keys()) 
     303    for i, version in enumerate(keys): 
     304        # Don't allow indices outside list 
     305        next_i = i + 1 
     306        if next_i == len(keys): 
     307            next_i = i 
     308        # If the save state is from a later version, skip the check 
     309        if model_version <= keys[next_i]: 
     310            newname = _conversion_target(name, version) 
     311        else: 
     312            newname = None 
     313        # If no conversion is found, move on 
     314        if newname is None: 
     315            newname = name 
     316            continue 
     317        if ':' in newname:   # core_shell_ellipsoid:1 
     318            model_info = load_model_info(newname[:-2]) 
     319            # Know the table exists and isn't multiplicity so grab it directly 
     320            # Can't use _get_translation_table since that will return the 'bare' 
     321            # version. 
     322            translation = CONVERSION_TABLE.get(version, {})[newname][1] 
     323        else: 
     324            model_info = load_model_info(newname) 
     325            translation = _get_translation_table(model_info, version) 
     326        newpars = _hand_convert(newname, newpars, version) 
     327        newpars = _convert_pars(newpars, translation) 
     328        # TODO: Still not convinced this is the best check 
     329        if not model_info.structure_factor and version == (3,1,2): 
     330            newpars = _rescale_sld(model_info, newpars, 1e6) 
     331        newpars.setdefault('scale', 1.0) 
     332        newpars.setdefault('background', 0.0) 
     333        if use_underscore: 
     334            newpars = _pd_to_underscores(newpars) 
     335        name = newname 
    308336    return newname, newpars 
    309  
    310337 
    311338# ========= BACKWARD CONVERSION sasmodels => sasview 3.x =========== 
  • sasmodels/kernelcl.py

    r7fcdc9f rd2b939c  
    465465        # architectures tested so far. 
    466466        if self.is_2d: 
    467             # Note: 17 rather than 15 because results is 2 elements 
    468             # longer than input. 
    469             width = ((self.nq+17)//16)*16 
     467            # Note: 16 rather than 15 because result is 1 longer than input. 
     468            width = ((self.nq+16)//16)*16 
    470469            self.q = np.empty((width, 2), dtype=dtype) 
    471470            self.q[:self.nq, 0] = q_vectors[0] 
    472471            self.q[:self.nq, 1] = q_vectors[1] 
    473472        else: 
    474             # Note: 33 rather than 31 because results is 2 elements 
    475             # longer than input. 
    476             width = ((self.nq+33)//32)*32 
     473            # Note: 32 rather than 31 because result is 1 longer than input. 
     474            width = ((self.nq+32)//32)*32 
    477475            self.q = np.empty(width, dtype=dtype) 
    478476            self.q[:self.nq] = q_vectors[0] 
     
    524522        self.dim = '2d' if q_input.is_2d else '1d' 
    525523        # plus three for the normalization values 
    526         self.result = np.empty(q_input.nq+3, dtype) 
     524        self.result = np.empty(q_input.nq+1, dtype) 
    527525 
    528526        # Inputs and outputs for each kernel call 
  • sasmodels/sasview_model.py

    r64614ad rfe8ff99  
    5757    import sas.models 
    5858    from sasmodels.conversion_table import CONVERSION_TABLE 
    59     for new_name, conversion in CONVERSION_TABLE.items(): 
     59    for new_name, conversion in CONVERSION_TABLE.get((3,1,2), {}).items(): 
    6060        # CoreShellEllipsoidModel => core_shell_ellipsoid:1 
    6161        new_name = new_name.split(':')[0] 
    62         old_name = conversion[0] 
     62        old_name = conversion[0] if len(conversion) < 3 else conversion[2] 
    6363        module_attrs = {old_name: find_model(new_name)} 
    6464        ConstructedModule = type(old_name, (), module_attrs) 
  • doc/ref/gpu/gpu_computations.rst

    r3f5a566 r7e74ed5  
    3131from available OpenCL platforms. 
    3232 
     33OpenCL devices can be set from OpenCL options dialog in Fitting menu or as 
     34enviromental variables. 
     35 
     36**If you don't want to use OpenCL, you can select "No OpenCL" option from** 
     37**GUI dialog or set *SAS_OPENCL=None* in your environment settings** 
     38**This will only use normal programs.** 
     39 
    3340SasView prefers AMD or NVIDIA drivers for GPU, and prefers Intel or 
    3441Apple drivers for CPU. Both GPU and CPU are included on the assumption that CPU  
     
    3946chose to run the model. 
    4047 
    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.** 
    43  
    44 If you want to use one of the other devices, you can run the following 
    45 from the python console in SasView:: 
     48If you want to use one of the other devices, you can select it from OpenCL 
     49options dialog (accessible from Fitting menu) or run the following from 
     50the python console in SasView:: 
    4651 
    4752    import pyopencl as cl 
Note: See TracChangeset for help on using the changeset viewer.