Changeset a503bfd in sasmodels
- Timestamp:
- Feb 16, 2015 7:41:55 PM (10 years ago)
- 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
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
compare.py
rd547f16 ra503bfd 156 156 return data, index 157 157 158 def compare(name, pars, Ncpu, N gpu, opts, set_pars):158 def compare(name, pars, Ncpu, Nocl, opts, set_pars): 159 159 opt_values = dict(split 160 160 for s in opts for split in ((s.split('='),)) … … 185 185 186 186 # OpenCl calculation 187 if N gpu> 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) 191 191 192 192 # ctypes/sasview calculation … … 201 201 202 202 # Compare, but only if computing both forms 203 if N gpu> 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] 209 209 relerr[index] = resid[index]/cpu[index] 210 210 #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] 212 212 print "max(|ocl-%s|)"%comp, max(abs(resid[index])) 213 213 print "max(|(ocl-%s)/%s|)"%(comp,comp), max(abs(relerr[index])) … … 220 220 import matplotlib.pyplot as plt 221 221 if Ncpu > 0: 222 if N gpu> 0: plt.subplot(131)222 if Nocl > 0: plt.subplot(131) 223 223 plot_data(data, cpu, scale='log') 224 224 plt.title("%s t=%.1f ms"%(comp,cpu_time)) 225 if N gpu> 0:225 if Nocl > 0: 226 226 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 N gpu> 0:227 plot_data(data, ocl, scale='log') 228 plt.title("opencl t=%.1f ms"%ocl_time) 229 if Ncpu > 0 and Nocl > 0: 230 230 plt.subplot(133) 231 231 err = resid if '-abs' in opts else relerr 232 232 errstr = "abs err" if '-abs' in opts else "rel err" 233 #err,errstr = gpu/cpu,"ratio"233 #err,errstr = ocl/cpu,"ratio" 234 234 plot_data(data, err, scale='linear') 235 235 plt.title("max %s = %.3g"%(errstr, max(abs(err[index])))) 236 236 if is2D: plt.colorbar() 237 237 238 if Ncpu > 0 and N gpu> 0 and '-hist' in opts:238 if Ncpu > 0 and Nocl > 0 and '-hist' in opts: 239 239 plt.figure() 240 240 v = relerr[index] -
sasmodels/convert.py
rf4cf580 ra503bfd 2 2 Convert models to and from sasview. 3 3 """ 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 optional40 ),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_name49 retval[new_name] = new_map50 return retval51 REVERSE_MAP = _reverse_map()52 del _reverse_map53 54 4 55 5 def _rename_pars(pars, mapping): … … 85 35 Convert model from old style parameter names to new style. 86 36 """ 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 91 40 92 41 def _unscale_sld(pars): … … 103 52 Convert model from new style parameter names to old style. 104 53 """ 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 107 58 oldpars = _rename_pars(_unscale_sld(pars), mapping) 108 59 return oldname, oldpars -
sasmodels/generate.py
rb3f6bc3 ra503bfd 128 128 respectively. These can also be defined in the last source file. 129 129 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 130 136 An *info* dictionary is constructed from the kernel meta data and 131 returned to the caller. It includes the additional fields 132 137 returned to the caller. 138 139 Additional fields can be defined in the kernel definition file that 140 are 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. 133 151 134 152 The model evaluator, function call sequence consists of q inputs and the return vector, -
sasmodels/models/capped_cylinder.py
rd547f16 ra503bfd 173 173 phi_pd=15, phi_pd_n=1, 174 174 ) 175 175 oldname = 'CappedCylinderModel' 176 oldpars = 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 179 179 phi_pd=15, phi_pd_n=1, 180 180 ) 181 oldname = 'CoreShellCylinderModel' 182 oldpars = dict(theta='axis_theta', phi='axis_phi') -
sasmodels/models/cylinder.py
rd547f16 ra503bfd 151 151 return 0.5 * (ddd)**(1./3.) 152 152 153 # For testing against the old sasview models, include the converted parameter154 # 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 158 153 # parameters for demo 159 154 demo = dict( … … 169 164 ) 170 165 166 # For testing against the old sasview models, include the converted parameter 167 # names and the target sasview model name. 168 oldname='CylinderModel' 169 oldpars=dict(theta='cyl_theta', phi='cyl_phi', sld='sldCyl', solvent_sld='sldSolv') 170 -
sasmodels/models/ellipsoid.py
rd547f16 ra503bfd 189 189 phi_pd=15, phi_pd_n=1, 190 190 ) 191 oldname = 'EllipsoidModel' 192 oldpars = 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 101 101 thickness_pd= 0.2, thickness_pd_n=40, 102 102 ) 103 oldname = 'LamellarModel' 104 oldpars = dict(sld='sld_bi', solvent_sld='sld_sol', thickness='bi_thick') 105 -
sasmodels/models/sphere.py
rd547f16 ra503bfd 116 116 radius_pd=.2, radius_pd_n=45, 117 117 ) 118 oldname = "SphereModel" 119 oldpars = dict(sld='sldSph', solvent_sld='sldSolv', radius='radius') -
sasmodels/models/spherepy.py
rd547f16 ra503bfd 133 133 radius_pd=.2, radius_pd_n=45, 134 134 ) 135 oldname = "SphereModel" 136 oldpars = dict(sld='sldSph', solvent_sld='sldSolv', radius='radius') -
sasmodels/models/triaxial_ellipsoid.py
rd547f16 ra503bfd 141 141 psi_pd=15, psi_pd_n=1, 142 142 ) 143 oldname = 'TriaxialEllipsoidModel' 144 oldpars = 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.