Changeset a503bfd in sasmodels


Ignore:
Timestamp:
Feb 16, 2015 5:41:55 PM (9 years ago)
Author:
pkienzle
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:
a1542aae, 373d1b6
Parents:
d547f16
Message:

move sasview→sasmodels conversion info to model definition

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • compare.py

    rd547f16 ra503bfd  
    156156    return data, index 
    157157 
    158 def compare(name, pars, Ncpu, Ngpu, opts, set_pars): 
     158def compare(name, pars, Ncpu, Nocl, opts, set_pars): 
    159159    opt_values = dict(split 
    160160                      for s in opts for split in ((s.split('='),)) 
     
    185185 
    186186    # OpenCl calculation 
    187     if Ngpu > 0: 
    188         gpu, gpu_time = eval_opencl(name, pars, data, dtype, Ngpu) 
    189         print "opencl t=%.1f ms, intensity=%.0f"%(gpu_time, sum(gpu[index])) 
    190         #print max(gpu), min(gpu) 
     187    if Nocl > 0: 
     188        ocl, ocl_time = eval_opencl(name, pars, data, dtype, Nocl) 
     189        print "opencl t=%.1f ms, intensity=%.0f"%(ocl_time, sum(ocl[index])) 
     190        #print max(ocl), min(ocl) 
    191191 
    192192    # ctypes/sasview calculation 
     
    201201 
    202202    # Compare, but only if computing both forms 
    203     if Ngpu > 0 and Ncpu > 0: 
    204         #print "speedup %.2g"%(cpu_time/gpu_time) 
    205         #print "max |gpu/cpu|", max(abs(gpu/cpu)), "%.15g"%max(abs(gpu)), "%.15g"%max(abs(cpu)) 
    206         #cpu *= max(gpu/cpu) 
    207         resid, relerr = np.zeros_like(gpu), np.zeros_like(gpu) 
    208         resid[index] = (gpu - cpu)[index] 
     203    if Nocl > 0 and Ncpu > 0: 
     204        #print "speedup %.2g"%(cpu_time/ocl_time) 
     205        #print "max |ocl/cpu|", max(abs(ocl/cpu)), "%.15g"%max(abs(ocl)), "%.15g"%max(abs(cpu)) 
     206        #cpu *= max(ocl/cpu) 
     207        resid, relerr = np.zeros_like(ocl), np.zeros_like(ocl) 
     208        resid[index] = (ocl - cpu)[index] 
    209209        relerr[index] = resid[index]/cpu[index] 
    210210        #bad = (relerr>1e-4) 
    211         #print relerr[bad],cpu[bad],gpu[bad],data.qx_data[bad],data.qy_data[bad] 
     211        #print relerr[bad],cpu[bad],ocl[bad],data.qx_data[bad],data.qy_data[bad] 
    212212        print "max(|ocl-%s|)"%comp, max(abs(resid[index])) 
    213213        print "max(|(ocl-%s)/%s|)"%(comp,comp), max(abs(relerr[index])) 
     
    220220    import matplotlib.pyplot as plt 
    221221    if Ncpu > 0: 
    222         if Ngpu > 0: plt.subplot(131) 
     222        if Nocl > 0: plt.subplot(131) 
    223223        plot_data(data, cpu, scale='log') 
    224224        plt.title("%s t=%.1f ms"%(comp,cpu_time)) 
    225     if Ngpu > 0: 
     225    if Nocl > 0: 
    226226        if Ncpu > 0: plt.subplot(132) 
    227         plot_data(data, gpu, scale='log') 
    228         plt.title("opencl t=%.1f ms"%gpu_time) 
    229     if Ncpu > 0 and Ngpu > 0: 
     227        plot_data(data, ocl, scale='log') 
     228        plt.title("opencl t=%.1f ms"%ocl_time) 
     229    if Ncpu > 0 and Nocl > 0: 
    230230        plt.subplot(133) 
    231231        err = resid if '-abs' in opts else relerr 
    232232        errstr = "abs err" if '-abs' in opts else "rel err" 
    233         #err,errstr = gpu/cpu,"ratio" 
     233        #err,errstr = ocl/cpu,"ratio" 
    234234        plot_data(data, err, scale='linear') 
    235235        plt.title("max %s = %.3g"%(errstr, max(abs(err[index])))) 
    236236    if is2D: plt.colorbar() 
    237237 
    238     if Ncpu > 0 and Ngpu > 0 and '-hist' in opts: 
     238    if Ncpu > 0 and Nocl > 0 and '-hist' in opts: 
    239239        plt.figure() 
    240240        v = relerr[index] 
  • sasmodels/convert.py

    rf4cf580 ra503bfd  
    22Convert models to and from sasview. 
    33""" 
    4 PARAMETER_MAP = { 
    5     'CylinderModel': dict( 
    6         name='cylinder', 
    7         cyl_theta='theta', cyl_phi='phi', 
    8         sldCyl='sld', sldSolv='solvent_sld', 
    9         ), 
    10     'EllipsoidModel': dict( 
    11         name='ellipsoid', 
    12         axis_theta='theta', axis_phi='phi', 
    13         sldEll='sld', sldSolv='solvent_sld', 
    14         radius_a='rpolar', radius_b='requatorial', 
    15         ), 
    16     'CoreShellCylinderModel': dict( 
    17         name='core_shell_cylinder', 
    18         axis_theta='theta', axis_phi='phi', 
    19         ), 
    20     'TriaxialEllipsoidModel': dict( 
    21         name='triaxial_ellipsoid', 
    22         axis_theta='theta', axis_phi='phi', axis_psi='psi', 
    23         sldEll='sld', sldSolv='solvent_sld', 
    24         semi_axisA='req_minor', semi_axisB='req_major', semi_axisC='rpolar', 
    25         ), 
    26     'LamellarModel': dict( 
    27         name='lamellar', 
    28         sld_bi='sld', sld_sol='solvent_sld', 
    29         bi_thick='thickness', 
    30         ), 
    31     'CappedCylinderModel': dict( 
    32         name='capped_cylinder', 
    33         sld_capcyl='sld', sld_solv='solvent_sld', 
    34         len_cyl='length', rad_cyl='radius', rad_cap='cap_radius', 
    35         ), 
    36     'SphereModel': dict( 
    37         name='sphere', 
    38         sldSph='sld', sldSolv='solvent_sld', 
    39         radius='radius',  # listing identical parameters is optional 
    40         ), 
    41     } 
    42  
    43 def _reverse_map(): 
    44     retval = {} 
    45     for old_name,old_map in PARAMETER_MAP.items(): 
    46         new_name = old_map['name'] 
    47         new_map = dict((v,k) for k,v in old_map.items() if k != 'name') 
    48         new_map['name'] = old_name 
    49         retval[new_name] = new_map 
    50     return retval 
    51 REVERSE_MAP = _reverse_map() 
    52 del _reverse_map 
    53  
    544 
    555def _rename_pars(pars, mapping): 
     
    8535    Convert model from old style parameter names to new style. 
    8636    """ 
    87     mapping = PARAMETER_MAP[name] 
    88     newname = mapping['name'] 
    89     newpars = _rescale_sld(_rename_pars(pars, mapping)) 
    90     return newname, newpars 
     37    raise NotImplementedError 
     38    # need to load all new models in order to determine old=>new 
     39    # model name mapping 
    9140 
    9241def _unscale_sld(pars): 
     
    10352    Convert model from new style parameter names to old style. 
    10453    """ 
    105     mapping = REVERSE_MAP[name] 
    106     oldname = mapping['name'] 
     54    sasmodels = __import__('sasmodels.models.'+name) 
     55    newmodel = getattr(sasmodels.models, name, None) 
     56    mapping = newmodel.oldpars 
     57    oldname = newmodel.oldname 
    10758    oldpars = _rename_pars(_unscale_sld(pars), mapping) 
    10859    return oldname, oldpars 
  • sasmodels/generate.py

    rb3f6bc3 ra503bfd  
    128128    respectively.  These can also be defined in the last source file. 
    129129 
     130    *Iq* and *Iqxy* also be instead be python functions defining the 
     131    kernel.  If they are marked as *Iq.vectorized = True* then the 
     132    kernel is passed the entire *q* vector at once, otherwise it is 
     133    passed values one *q* at a time.  The performance improvement of 
     134    this step is significant. 
     135 
    130136An *info* dictionary is constructed from the kernel meta data and 
    131 returned to the caller.  It includes the additional fields 
    132  
     137returned to the caller. 
     138 
     139Additional fields can be defined in the kernel definition file that 
     140are not needed for sas modelling. 
     141 
     142    *demo* is a dictionary of parameter=value defining a set of 
     143    parameters to use by default when *compare* is called. 
     144 
     145    *oldname* is the name of the model in sasview before sasmodels 
     146    was split into its own package, and *oldpars* is a dictionary 
     147    of *parameter: old_parameter* pairs defining the new names for 
     148    the parameters.  This is used by *compare* to check the values 
     149    of the new model against the values of the old model before 
     150    you are ready to add the new model to sasmodels. 
    133151 
    134152The model evaluator, function call sequence consists of q inputs and the return vector, 
  • sasmodels/models/capped_cylinder.py

    rd547f16 ra503bfd  
    173173    phi_pd=15, phi_pd_n=1, 
    174174    ) 
    175  
     175oldname = 'CappedCylinderModel' 
     176oldpars = dict(sld='sld_capcyl', solvent_sld='sld_solv', 
     177               length='len_cyl', radius='rad_cyl', cap_radius='rad_cap') 
  • sasmodels/models/core_shell_cylinder.py

    rd547f16 ra503bfd  
    179179    phi_pd=15, phi_pd_n=1, 
    180180    ) 
     181oldname = 'CoreShellCylinderModel' 
     182oldpars = dict(theta='axis_theta', phi='axis_phi') 
  • sasmodels/models/cylinder.py

    rd547f16 ra503bfd  
    151151    return 0.5 * (ddd)**(1./3.) 
    152152 
    153 # For testing against the old sasview models, include the converted parameter 
    154 # names and the target sasview model name. 
    155 oldname='CylinderModel' 
    156 oldpars=dict(theta='cyl_theta', phi='cyl_phi', sld='sldCyl', solvent_sld='sldSolv') 
    157  
    158153# parameters for demo 
    159154demo = dict( 
     
    169164    ) 
    170165 
     166# For testing against the old sasview models, include the converted parameter 
     167# names and the target sasview model name. 
     168oldname='CylinderModel' 
     169oldpars=dict(theta='cyl_theta', phi='cyl_phi', sld='sldCyl', solvent_sld='sldSolv') 
     170 
  • sasmodels/models/ellipsoid.py

    rd547f16 ra503bfd  
    189189        phi_pd=15, phi_pd_n=1, 
    190190        ) 
     191oldname = 'EllipsoidModel' 
     192oldpars = dict(theta='axis_theta', phi='axis_phi', 
     193               sld='sldEll', solvent_sld='sldSolv', 
     194               rpolar='radius_a', requatorial='radius_b') 
  • sasmodels/models/lamellar.py

    rd547f16 ra503bfd  
    101101        thickness_pd= 0.2, thickness_pd_n=40, 
    102102        ) 
     103oldname = 'LamellarModel' 
     104oldpars = dict(sld='sld_bi', solvent_sld='sld_sol', thickness='bi_thick') 
     105 
  • sasmodels/models/sphere.py

    rd547f16 ra503bfd  
    116116        radius_pd=.2, radius_pd_n=45, 
    117117        ) 
     118oldname = "SphereModel" 
     119oldpars = dict(sld='sldSph', solvent_sld='sldSolv', radius='radius') 
  • sasmodels/models/spherepy.py

    rd547f16 ra503bfd  
    133133    radius_pd=.2, radius_pd_n=45, 
    134134    ) 
     135oldname = "SphereModel" 
     136oldpars = dict(sld='sldSph', solvent_sld='sldSolv', radius='radius') 
  • sasmodels/models/triaxial_ellipsoid.py

    rd547f16 ra503bfd  
    141141        psi_pd=15, psi_pd_n=1, 
    142142        ) 
     143oldname = 'TriaxialEllipsoidModel' 
     144oldpars = dict(theta='axis_theta', phi='axis_phi', psi='axis_psi', 
     145               sld='sldEll',  solvent_sld='sldSolv', 
     146               req_minor='semi_axisA', req_major='semi_axisB', 
     147               rpolar='semi_axisC') 
Note: See TracChangeset for help on using the changeset viewer.