Changes in / [402c351:5442c77] in sasmodels
- Location:
- sasmodels
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r5753e4e re1ace4d 130 130 if name == 'capped_cylinder' and pars['cap_radius'] < pars['radius']: 131 131 pars['radius'],pars['cap_radius'] = pars['cap_radius'],pars['radius'] 132 if name == 'barbell' and pars['bell_radius'] < pars['radius']: 133 pars['radius'],pars['bell_radius'] = pars['bell_radius'],pars['radius'] 134 135 # Limit guinier to an Rg such that Iq > 1e-30 (single precision cutoff) 136 if name == 'guinier': 137 #q_max = 0.2 # mid q maximum 138 q_max = 1.0 # high q maximum 139 rg_max = np.sqrt(90*np.log(10) + 3*np.log(pars['scale']))/q_max 140 pars['rg'] = min(pars['rg'],rg_max) 132 141 133 142 # These constraints are only needed for comparison to sasview … … 224 233 model_definition = core.load_model_definition(name) 225 234 226 view = 'linear' if '-linear' in opts else 'log' if '-log' in opts else 'q4' if '-q4' in opts else 'log' 235 view = ('linear' if '-linear' in opts 236 else 'log' if '-log' in opts 237 else 'q4' if '-q4' in opts 238 else 'log') 227 239 228 240 opt_values = dict(split … … 230 242 if len(split) == 2) 231 243 # Sort out data 232 qmax = 10.0 if '-exq' in opts else 1.0 if '-highq' in opts else 0.2 if '-midq' in opts else 0.05 244 qmax = (10.0 if '-exq' in opts 245 else 1.0 if '-highq' in opts 246 else 0.2 if '-midq' in opts 247 else 0.05) 233 248 Nq = int(opt_values.get('-Nq', '128')) 234 249 res = float(opt_values.get('-res', '0')) … … 239 254 240 255 # modelling accuracy is determined by dtype and cutoff 241 dtype = 'double' if '-double' in opts else 'single' 256 dtype = ('longdouble' if '-quad' in opts 257 else 'double' if '-double' in opts 258 else 'single') 242 259 cutoff = float(opt_values.get('-cutoff','1e-5')) 243 260 … … 247 264 seed = int(opt_values['-random']) if '-random' in opt_values else None 248 265 pars, seed = randomize_model(pars, seed=seed) 249 constrain_pars(model_definition, pars)250 266 print "Randomize using -random=%i"%seed 251 267 pars.update(set_pars) # set value after random to control value 268 constrain_pars(model_definition, pars) 252 269 253 270 # parameter selection … … 362 379 363 380 -plot*/-noplot plots or suppress the plot of the model 364 -single*/-double uses doubleprecision for comparison381 -single*/-double/-quad use single/double/quad precision for comparison 365 382 -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 366 383 -Nq=128 sets the number of Q points in the data set … … 386 403 NAME_OPTIONS = set([ 387 404 'plot','noplot', 388 'single','double', 405 'single','double','longdouble', 389 406 'lowq','midq','highq','exq', 390 407 '2d','1d', -
sasmodels/compare_many.py
rcd3dba0 rb514adf 57 57 num_good = 0 58 58 first = True 59 max_diff = 0 59 60 for k in range(N): 60 61 print >>sys.stderr, name, k … … 73 74 columns.extend(stats) 74 75 labels.append('GPU single') 75 good = good and (stats[0] < 1e-14) 76 max_diff = max(max_diff, stats[0]) 77 good = good and (stats[0] < 5e-5) 76 78 if 0 and environment().has_double: 77 79 gpu_double_value = trymodel(eval_opencl, dtype='double', cutoff=cutoff) … … 79 81 columns.extend(stats) 80 82 labels.append('GPU double') 81 good = good and (stats[0] < 1e-14) 83 max_diff = max(max_diff, stats[0]) 84 good = good and (stats[0] < 1e-12) 82 85 if 1: 83 86 cpu_double_value = trymodel(eval_ctypes, dtype='double', cutoff=cutoff) … … 85 88 columns.extend(stats) 86 89 labels.append('CPU double') 87 good = good and (stats[0] < 1e-14) 90 max_diff = max(max_diff, stats[0]) 91 good = good and (stats[0] < 1e-12) 88 92 if 0: 89 93 stats = get_stats(cpu_double_value, gpu_single_value, index) 90 94 columns.extend(stats) 91 95 labels.append('single/double') 92 good = good and (stats[0] < 1e-14) 96 max_diff = max(max_diff, stats[0]) 97 good = good and (stats[0] < 5e-5) 93 98 94 99 columns += [v for _,v in sorted(pars_i.items())] … … 100 105 else: 101 106 print(("%d,"%seed)+','.join("%g"%v for v in columns)) 102 print '" %d/%d good"'%(num_good, N)107 print '"good","%d/%d","max diff",%g'%(num_good, N, max_diff) 103 108 104 109 -
sasmodels/generate.py
rcd3dba0 re1ace4d 197 197 # TODO: identify model files which have changed since loading and reload them. 198 198 199 __all__ = ["make", "doc", "sources", "use_single" ]199 __all__ = ["make", "doc", "sources", "use_single", "use_long_double"] 200 200 201 201 import sys … … 206 206 C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c') 207 207 208 F32 = np.dtype('float32') 208 209 F64 = np.dtype('float64') 209 F32 = np.dtype('float32') 210 try: # CRUFT: older numpy does not support float128 211 F128 = np.dtype('float128') 212 except TypeError: 213 F128 = None 214 210 215 211 216 # Scale and background, which are parameters common to every form factor … … 322 327 source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 323 328 r'\g<0>f', source) 329 return source 330 331 def use_long_double(source): 332 """ 333 Convert code from double precision to long double precision. 334 """ 335 # Convert double keyword to float. Accept an 'n' parameter for vector 336 # values, where n is 2, 4, 8 or 16. Assume complex numbers are represented 337 # as cdouble which is typedef'd to double2. 338 source = re.sub(r'(^|[^a-zA-Z0-9_]c?)double(([248]|16)?($|[^a-zA-Z0-9_]))', 339 r'\1long double\2', source) 340 # Convert floating point constants to single by adding 'f' to the end. 341 # OS/X driver complains if you don't do this. 342 source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 343 r'\g<0>L', source) 324 344 return source 325 345 -
sasmodels/kernel_template.c
r6ee9d39 r062c56d 125 125 if (weight > cutoff) { 126 126 const double scattering = Iq(qi, IQ_PARAMETERS); 127 if (scattering >= 0.0) { // scattering cannot be negative127 //if (scattering >= 0.0) { // scattering cannot be negative 128 128 ret += weight*scattering; 129 129 norm += weight; … … 133 133 norm_vol += vol_weight; 134 134 #endif 135 }135 //} 136 136 //else { printf("exclude qx,qy,I:%%g,%%g,%%g\n",qi,scattering); } 137 137 } … … 198 198 199 199 const double scattering = Iqxy(qxi, qyi, IQXY_PARAMETERS); 200 if (scattering >= 0.0) { // scattering cannot be negative200 //if (scattering >= 0.0) { // scattering cannot be negative 201 201 // TODO: use correct angle for spherical correction 202 202 // Definition of theta and phi are probably reversed relative to the … … 219 219 #endif 220 220 norm_vol += vol_weight; 221 }221 //} 222 222 //else { printf("exclude qx,qy,I:%%g,%%g,%%g\n",qi,scattering); } 223 223 } -
sasmodels/kernelcl.py
r0763009 r92da231 22 22 devices, where it can be combined with other structure factors and form 23 23 factors and have instrumental resolution effects applied. 24 25 In order to use OpenCL for your models, you will need OpenCL drivers for 26 your machine. These should be available from your graphics card vendor. 27 Intel provides OpenCL drivers for CPUs as well as their integrated HD 28 graphics chipsets. AMD also provides drivers for Intel CPUs, but as of 29 this writing the performance is lacking compared to the Intel drivers. 30 NVidia combines drivers for CUDA and OpenCL in one package. The result 31 is a bit messy if you have multiple drivers installed. You can see which 32 drivers are available by starting python and running: 33 34 import pyopencl as cl 35 cl.create_some_context(interactive=True) 36 37 Once you have done that, it will show the available drivers which you 38 can select. It will then tell you that you can use these drivers 39 automatically by setting the PYOPENCL_CTX environment variable. 40 41 Some graphics cards have multiple devices on the same card. You cannot 42 yet use both of them concurrently to evaluate models, but you can run 43 the program twice using a different device for each session. 44 45 OpenCL kernels are compiled when needed by the device driver. Some 46 drivers produce compiler output even when there is no error. You 47 can see the output by setting PYOPENCL_COMPILER_OUTPUT=1. It should be 48 harmless, albeit annoying. 24 49 """ 25 50 import os -
sasmodels/kerneldll.py
ra30cdd5 r5edfe12 1 """1 r""" 2 2 C types wrapper for sasview models. 3 3 … … 5 5 you wish to allow single precision floating point evaluation for the compiled 6 6 models, otherwise it defaults to *False*. 7 8 The compiler command line is stored in the attribute *COMPILE*, with string 9 substitutions for %(source)s and %(output)s indicating what to compile and 10 where to store it. The actual command is system dependent. 11 12 On windows systems, you have a choice of compilers. *MinGW* is the GNU 13 compiler toolchain, available in packages such as anaconda and PythonXY, 14 or available stand alone. This toolchain has had difficulties on some 15 systems, and may or may not work for you. In order to build DLLs, *gcc* 16 must be on your path. If the environment variable *SAS_OPENMP* is given 17 then -fopenmp is added to the compiler flags. This requires a version 18 of MinGW compiled with OpenMP support. 19 20 An alternative toolchain uses the Microsoft Visual C++ compiler, available 21 free from microsoft: 22 23 `http://www.microsoft.com/en-us/download/details.aspx?id=44266`_ 24 25 Again, this requires that the compiler is available on your path. This is 26 done by running vcvarsall.bat in a windows terminal. Install locations are 27 system dependent, such as: 28 29 C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 30 31 or maybe 32 33 C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 34 35 And again, the environment variable *SAS_OPENMP* controls whether OpenMP is 36 used to compile the C code. This requires the Microsoft vcomp90.dll library, 37 which doesn't seem to be included with the compiler, nor does there appear 38 to be a public download location. There may be one on your machine already 39 in a location such as: 40 41 C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll 42 43 If you copy this onto your path, such as the python directory or the install 44 directory for this application, then OpenMP should be supported. 7 45 """ 8 46 … … 11 49 import tempfile 12 50 import ctypes as ct 13 from ctypes import c_void_p, c_int, c_ double, c_float51 from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float 14 52 15 53 import numpy as np … … 58 96 if np.dtype(dtype) == generate.F32: 59 97 basename += "32" 98 elif np.dtype(dtype) == generate.F64: 99 basename += "64" 100 else: 101 basename += "128" 60 102 return joinpath(DLL_PATH, basename+'.so') 61 103 … … 80 122 models are allowed as DLLs. 81 123 """ 82 if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double" # Force 64-bit dll83 124 dtype = np.dtype(dtype) 125 if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS: 126 dtype = generate.F64 # Force 64-bit dll 84 127 85 128 if callable(info.get('Iq',None)): … … 89 132 source = generate.use_single(source) 90 133 tempfile_prefix = 'sas_'+info['name']+'32_' 134 elif dtype == generate.F64: 135 tempfile_prefix = 'sas_'+info['name']+'64_' 91 136 else: 92 tempfile_prefix = 'sas_'+info['name']+'_' 137 source = generate.use_long_double(source) 138 tempfile_prefix = 'sas_'+info['name']+'128_' 93 139 94 140 source_files = generate.sources(info) + [info['filename']] … … 158 204 raise 159 205 160 fp = c_float if self.dtype == generate.F32 else c_double 206 fp = (c_float if self.dtype == generate.F32 207 else c_double if self.dtype == generate.F64 208 else c_longdouble) 161 209 pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 162 210 pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] … … 227 275 228 276 def __call__(self, fixed_pars, pd_pars, cutoff): 229 real = np.float32 if self.q_input.dtype == generate.F32 else np.float64 277 real = (np.float32 if self.q_input.dtype == generate.F32 278 else np.float64 if self.q_input.dtype == generate.F64 279 else np.float128) 230 280 231 281 nq = c_int(self.q_input.nq) -
sasmodels/kernelpy.py
r750ffa5 r062c56d 211 211 if w > cutoff: 212 212 I = form(*args) 213 positive = (I >= 0.0)213 #positive = (I >= 0.0) 214 214 215 215 # Note: can precompute spherical correction if theta_index is not … … 219 219 if theta_index >= 0 else 1.0) 220 220 #spherical_correction = 1.0 221 ret += w * I * spherical_correction * positive222 norm += w * positive221 ret += w * I * spherical_correction #* positive 222 norm += w #* positive 223 223 224 224 # Volume normalization. … … 230 230 vol_args = [args[index] for index in vol_index] 231 231 vol_weight = np.prod(weight[vol_weight_index]) 232 vol += vol_weight * form_volume(*vol_args) * positive233 vol_norm += vol_weight * positive232 vol += vol_weight * form_volume(*vol_args) #* positive 233 vol_norm += vol_weight #* positive 234 234 235 235 positive = (vol * vol_norm != 0.0) -
sasmodels/resolution.py
reb588ef r7f7f99f 1074 1074 1075 1075 if __name__ == "__main__": 1076 demo()1077 #main()1076 #demo() 1077 main()
Note: See TracChangeset
for help on using the changeset viewer.