Changeset 4b41184 in sasmodels
- Timestamp:
- Nov 25, 2015 4:10:43 PM (9 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:
- a5899c8
- Parents:
- 0fa687d
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r319ab14 r4b41184 233 233 return data, index 234 234 235 def compare(name, pars, Nc pu, Nocl, opts, set_pars):235 def compare(name, pars, Ncomp, Nbase, opts, set_pars): 236 236 model_definition = core.load_model_definition(name) 237 237 … … 277 277 print "pars",parlist(pars) 278 278 279 # OpenCl calculation 280 if Nocl > 0 and "-ctypes" in opts and "-sasview" in opts: 279 # Base calculation 280 if 0: 281 from sasmodels.models import sphere as target 282 base_name = target.name 283 base, base_time = eval_ctypes(target, pars, data, 284 dtype='longdouble', cutoff=0., Nevals=Ncomp) 285 elif Nbase > 0 and "-ctypes" in opts and "-sasview" in opts: 281 286 try: 282 ocl, ocl_time = eval_sasview(model_definition, pars, data, Ncpu)283 base = "sasview"284 #print " ocl/sasview", (ocl-pars['background'])/(cpu-pars['background'])285 print "sasview t=%.1f ms, intensity=%.0f"%( ocl_time, sum(ocl))286 #print "sasview",c pu287 base, base_time = eval_sasview(model_definition, pars, data, Ncomp) 288 base_name = "sasview" 289 #print "base/sasview", (base-pars['background'])/(comp-pars['background']) 290 print "sasview t=%.1f ms, intensity=%.0f"%(base_time, sum(base)) 291 #print "sasview",comp 287 292 except ImportError: 288 293 traceback.print_exc() 289 Nc pu= 0290 elif N ocl> 0:291 ocl, ocl_time = eval_opencl(model_definition, pars, data,292 dtype=dtype, cutoff=cutoff, Nevals=N ocl)293 base = "ocl"294 print "opencl t=%.1f ms, intensity=%.0f"%( ocl_time, sum(ocl))295 #print " ocl", ocl296 #print max( ocl), min(ocl)297 298 # ctypes/sasviewcalculation299 if Nc pu> 0 and "-ctypes" in opts:300 c pu, cpu_time = eval_ctypes(model_definition, pars, data,301 dtype=dtype, cutoff=cutoff, Nevals=Nc pu)302 comp = "ctypes"303 print "ctypes t=%.1f ms, intensity=%.0f"%(c pu_time, sum(cpu))304 elif Nc pu> 0:294 Ncomp = 0 295 elif Nbase > 0: 296 base, base_time = eval_opencl(model_definition, pars, data, 297 dtype=dtype, cutoff=cutoff, Nevals=Nbase) 298 base_name = "ocl" 299 print "opencl t=%.1f ms, intensity=%.0f"%(base_time, sum(base)) 300 #print "base", base 301 #print max(base), min(base) 302 303 # Comparison calculation 304 if Ncomp > 0 and "-ctypes" in opts: 305 comp, comp_time = eval_ctypes(model_definition, pars, data, 306 dtype=dtype, cutoff=cutoff, Nevals=Ncomp) 307 comp_name = "ctypes" 308 print "ctypes t=%.1f ms, intensity=%.0f"%(comp_time, sum(comp)) 309 elif Ncomp > 0: 305 310 try: 306 c pu, cpu_time = eval_sasview(model_definition, pars, data, Ncpu)307 comp = "sasview"308 #print " ocl/sasview", (ocl-pars['background'])/(cpu-pars['background'])309 print "sasview t=%.1f ms, intensity=%.0f"%(c pu_time, sum(cpu))310 #print "sasview",c pu311 comp, comp_time = eval_sasview(model_definition, pars, data, Ncomp) 312 comp_name = "sasview" 313 #print "base/sasview", (base-pars['background'])/(comp-pars['background']) 314 print "sasview t=%.1f ms, intensity=%.0f"%(comp_time, sum(comp)) 315 #print "sasview",comp 311 316 except ImportError: 312 317 traceback.print_exc() 313 Nc pu= 0318 Ncomp = 0 314 319 315 320 # Compare, but only if computing both forms 316 if N ocl > 0 and Ncpu> 0:317 #print "speedup %.2g"%(c pu_time/ocl_time)318 #print "max | ocl/cpu|", max(abs(ocl/cpu)), "%.15g"%max(abs(ocl)), "%.15g"%max(abs(cpu))319 #c pu *= max(ocl/cpu)320 resid = ( ocl - cpu)321 relerr = resid/c pu321 if Nbase > 0 and Ncomp > 0: 322 #print "speedup %.2g"%(comp_time/base_time) 323 #print "max |base/comp|", max(abs(base/comp)), "%.15g"%max(abs(base)), "%.15g"%max(abs(comp)) 324 #comp *= max(base/comp) 325 resid = (base - comp) 326 relerr = resid/comp 322 327 #bad = (relerr>1e-4) 323 #print relerr[bad],c pu[bad],ocl[bad],data.qx_data[bad],data.qy_data[bad]324 _print_stats("|%s-%s|"%(base ,comp)+(" "*(3+len(comp))), resid)325 _print_stats("|(%s-%s)/%s|"%(base ,comp,comp), relerr)328 #print relerr[bad],comp[bad],base[bad],data.qx_data[bad],data.qy_data[bad] 329 _print_stats("|%s-%s|"%(base_name,comp_name)+(" "*(3+len(comp_name))), resid) 330 _print_stats("|(%s-%s)/%s|"%(base_name,comp_name,comp_name), relerr) 326 331 327 332 # Plot if requested 328 333 if '-noplot' in opts: return 329 334 import matplotlib.pyplot as plt 330 if Nc pu> 0:331 if N ocl> 0: plt.subplot(131)332 plot_theory(data, c pu, view=view, plot_data=False)333 plt.title("%s t=%.1f ms"%(comp ,cpu_time))335 if Ncomp > 0: 336 if Nbase > 0: plt.subplot(131) 337 plot_theory(data, comp, view=view, plot_data=False) 338 plt.title("%s t=%.1f ms"%(comp_name,comp_time)) 334 339 #cbar_title = "log I" 335 if N ocl> 0:336 if Nc pu> 0: plt.subplot(132)337 plot_theory(data, ocl, view=view, plot_data=False)338 plt.title("%s t=%.1f ms"%(base ,ocl_time))340 if Nbase > 0: 341 if Ncomp > 0: plt.subplot(132) 342 plot_theory(data, base, view=view, plot_data=False) 343 plt.title("%s t=%.1f ms"%(base_name,base_time)) 339 344 #cbar_title = "log I" 340 if Nc pu > 0 and Nocl> 0:345 if Ncomp > 0 and Nbase > 0: 341 346 plt.subplot(133) 342 347 if '-abs' in opts: … … 344 349 else: 345 350 err,errstr,errview = abs(relerr), "rel err", "log" 346 #err,errstr = ocl/cpu,"ratio"351 #err,errstr = base/comp,"ratio" 347 352 plot_theory(data, None, resid=err, view=errview, plot_data=False) 348 353 plt.title("max %s = %.3g"%(errstr, max(abs(err)))) … … 352 357 # h.ax.set_title(cbar_title) 353 358 354 if Nc pu > 0 and Nocl> 0 and '-hist' in opts:359 if Ncomp > 0 and Nbase > 0 and '-hist' in opts: 355 360 plt.figure() 356 361 v = relerr … … 479 484 pars = get_demo_pars(model_definition) 480 485 481 N opencl= int(args[1]) if len(args) > 1 else 5482 N sasview= int(args[2]) if len(args) > 2 else 1486 Ncomp = int(args[1]) if len(args) > 1 else 5 487 Nbase = int(args[2]) if len(args) > 2 else 1 483 488 484 489 # Fill in default polydispersity parameters … … 499 504 set_pars[k] = float(v) if not v.endswith('type') else v 500 505 501 compare(name, pars, N sasview, Nopencl, opts, set_pars)506 compare(name, pars, Ncomp, Nbase, opts, set_pars) 502 507 503 508 if __name__ == "__main__": -
sasmodels/compare_many.py
r319ab14 r4b41184 79 79 labels = [] 80 80 columns = [] 81 #target = try_model(eval_sasview) 82 target = try_model(eval_opencl, dtype='longdouble', cutoff=cutoff) 81 target = try_model(eval_sasview) 82 #target = try_model(eval_ctypes, dtype='double', cutoff=0.) 83 #target = try_model(eval_ctypes, dtype='longdouble', cutoff=0.) 83 84 if precision == 'single': 84 85 value = try_model(eval_opencl, dtype='single', cutoff=cutoff)
Note: See TracChangeset
for help on using the changeset viewer.