Changes in / [5442c77:402c351] in sasmodels
- Location:
- sasmodels
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
re1ace4d r5753e4e 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 maximum138 q_max = 1.0 # high q maximum139 rg_max = np.sqrt(90*np.log(10) + 3*np.log(pars['scale']))/q_max140 pars['rg'] = min(pars['rg'],rg_max)141 132 142 133 # These constraints are only needed for comparison to sasview … … 233 224 model_definition = core.load_model_definition(name) 234 225 235 view = ('linear' if '-linear' in opts 236 else 'log' if '-log' in opts 237 else 'q4' if '-q4' in opts 238 else 'log') 226 view = 'linear' if '-linear' in opts else 'log' if '-log' in opts else 'q4' if '-q4' in opts else 'log' 239 227 240 228 opt_values = dict(split … … 242 230 if len(split) == 2) 243 231 # Sort out data 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) 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 248 233 Nq = int(opt_values.get('-Nq', '128')) 249 234 res = float(opt_values.get('-res', '0')) … … 254 239 255 240 # modelling accuracy is determined by dtype and cutoff 256 dtype = ('longdouble' if '-quad' in opts 257 else 'double' if '-double' in opts 258 else 'single') 241 dtype = 'double' if '-double' in opts else 'single' 259 242 cutoff = float(opt_values.get('-cutoff','1e-5')) 260 243 … … 264 247 seed = int(opt_values['-random']) if '-random' in opt_values else None 265 248 pars, seed = randomize_model(pars, seed=seed) 249 constrain_pars(model_definition, pars) 266 250 print "Randomize using -random=%i"%seed 267 251 pars.update(set_pars) # set value after random to control value 268 constrain_pars(model_definition, pars)269 252 270 253 # parameter selection … … 379 362 380 363 -plot*/-noplot plots or suppress the plot of the model 381 -single*/-double /-quad use single/double/quadprecision for comparison364 -single*/-double uses double precision for comparison 382 365 -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 383 366 -Nq=128 sets the number of Q points in the data set … … 403 386 NAME_OPTIONS = set([ 404 387 'plot','noplot', 405 'single','double', 'longdouble',388 'single','double', 406 389 'lowq','midq','highq','exq', 407 390 '2d','1d', -
sasmodels/compare_many.py
rb514adf rcd3dba0 57 57 num_good = 0 58 58 first = True 59 max_diff = 060 59 for k in range(N): 61 60 print >>sys.stderr, name, k … … 74 73 columns.extend(stats) 75 74 labels.append('GPU single') 76 max_diff = max(max_diff, stats[0]) 77 good = good and (stats[0] < 5e-5) 75 good = good and (stats[0] < 1e-14) 78 76 if 0 and environment().has_double: 79 77 gpu_double_value = trymodel(eval_opencl, dtype='double', cutoff=cutoff) … … 81 79 columns.extend(stats) 82 80 labels.append('GPU double') 83 max_diff = max(max_diff, stats[0]) 84 good = good and (stats[0] < 1e-12) 81 good = good and (stats[0] < 1e-14) 85 82 if 1: 86 83 cpu_double_value = trymodel(eval_ctypes, dtype='double', cutoff=cutoff) … … 88 85 columns.extend(stats) 89 86 labels.append('CPU double') 90 max_diff = max(max_diff, stats[0]) 91 good = good and (stats[0] < 1e-12) 87 good = good and (stats[0] < 1e-14) 92 88 if 0: 93 89 stats = get_stats(cpu_double_value, gpu_single_value, index) 94 90 columns.extend(stats) 95 91 labels.append('single/double') 96 max_diff = max(max_diff, stats[0]) 97 good = good and (stats[0] < 5e-5) 92 good = good and (stats[0] < 1e-14) 98 93 99 94 columns += [v for _,v in sorted(pars_i.items())] … … 105 100 else: 106 101 print(("%d,"%seed)+','.join("%g"%v for v in columns)) 107 print '" good","%d/%d","max diff",%g'%(num_good, N, max_diff)102 print '"%d/%d good"'%(num_good, N) 108 103 109 104 -
sasmodels/generate.py
re1ace4d rcd3dba0 197 197 # TODO: identify model files which have changed since loading and reload them. 198 198 199 __all__ = ["make", "doc", "sources", "use_single" , "use_long_double"]199 __all__ = ["make", "doc", "sources", "use_single"] 200 200 201 201 import sys … … 206 206 C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c') 207 207 208 F64 = np.dtype('float64') 208 209 F32 = np.dtype('float32') 209 F64 = np.dtype('float64')210 try: # CRUFT: older numpy does not support float128211 F128 = np.dtype('float128')212 except TypeError:213 F128 = None214 215 210 216 211 # Scale and background, which are parameters common to every form factor … … 327 322 source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 328 323 r'\g<0>f', source) 329 return source330 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 vector336 # values, where n is 2, 4, 8 or 16. Assume complex numbers are represented337 # 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)344 324 return source 345 325 -
sasmodels/kernel_template.c
r062c56d r6ee9d39 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
r92da231 r0763009 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 for26 your machine. These should be available from your graphics card vendor.27 Intel provides OpenCL drivers for CPUs as well as their integrated HD28 graphics chipsets. AMD also provides drivers for Intel CPUs, but as of29 this writing the performance is lacking compared to the Intel drivers.30 NVidia combines drivers for CUDA and OpenCL in one package. The result31 is a bit messy if you have multiple drivers installed. You can see which32 drivers are available by starting python and running:33 34 import pyopencl as cl35 cl.create_some_context(interactive=True)36 37 Once you have done that, it will show the available drivers which you38 can select. It will then tell you that you can use these drivers39 automatically by setting the PYOPENCL_CTX environment variable.40 41 Some graphics cards have multiple devices on the same card. You cannot42 yet use both of them concurrently to evaluate models, but you can run43 the program twice using a different device for each session.44 45 OpenCL kernels are compiled when needed by the device driver. Some46 drivers produce compiler output even when there is no error. You47 can see the output by setting PYOPENCL_COMPILER_OUTPUT=1. It should be48 harmless, albeit annoying.49 24 """ 50 25 import os -
sasmodels/kerneldll.py
r5edfe12 ra30cdd5 1 r"""1 """ 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 string9 substitutions for %(source)s and %(output)s indicating what to compile and10 where to store it. The actual command is system dependent.11 12 On windows systems, you have a choice of compilers. *MinGW* is the GNU13 compiler toolchain, available in packages such as anaconda and PythonXY,14 or available stand alone. This toolchain has had difficulties on some15 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 given17 then -fopenmp is added to the compiler flags. This requires a version18 of MinGW compiled with OpenMP support.19 20 An alternative toolchain uses the Microsoft Visual C++ compiler, available21 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 is26 done by running vcvarsall.bat in a windows terminal. Install locations are27 system dependent, such as:28 29 C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat30 31 or maybe32 33 C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat34 35 And again, the environment variable *SAS_OPENMP* controls whether OpenMP is36 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 appear38 to be a public download location. There may be one on your machine already39 in a location such as:40 41 C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll42 43 If you copy this onto your path, such as the python directory or the install44 directory for this application, then OpenMP should be supported.45 7 """ 46 8 … … 49 11 import tempfile 50 12 import ctypes as ct 51 from ctypes import c_void_p, c_int, c_ longdouble, c_double, c_float13 from ctypes import c_void_p, c_int, c_double, c_float 52 14 53 15 import numpy as np … … 96 58 if np.dtype(dtype) == generate.F32: 97 59 basename += "32" 98 elif np.dtype(dtype) == generate.F64:99 basename += "64"100 else:101 basename += "128"102 60 return joinpath(DLL_PATH, basename+'.so') 103 61 … … 122 80 models are allowed as DLLs. 123 81 """ 82 if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double" # Force 64-bit dll 124 83 dtype = np.dtype(dtype) 125 if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS:126 dtype = generate.F64 # Force 64-bit dll127 84 128 85 if callable(info.get('Iq',None)): … … 132 89 source = generate.use_single(source) 133 90 tempfile_prefix = 'sas_'+info['name']+'32_' 134 elif dtype == generate.F64:135 tempfile_prefix = 'sas_'+info['name']+'64_'136 91 else: 137 source = generate.use_long_double(source) 138 tempfile_prefix = 'sas_'+info['name']+'128_' 92 tempfile_prefix = 'sas_'+info['name']+'_' 139 93 140 94 source_files = generate.sources(info) + [info['filename']] … … 204 158 raise 205 159 206 fp = (c_float if self.dtype == generate.F32 207 else c_double if self.dtype == generate.F64 208 else c_longdouble) 160 fp = c_float if self.dtype == generate.F32 else c_double 209 161 pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 210 162 pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] … … 275 227 276 228 def __call__(self, fixed_pars, pd_pars, cutoff): 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) 229 real = np.float32 if self.q_input.dtype == generate.F32 else np.float64 280 230 281 231 nq = c_int(self.q_input.nq) -
sasmodels/kernelpy.py
r062c56d r750ffa5 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
r7f7f99f reb588ef 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.