Changes in / [5442c77:402c351] in sasmodels


Ignore:
Location:
sasmodels
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    re1ace4d r5753e4e  
    130130    if name == 'capped_cylinder' and pars['cap_radius'] < pars['radius']: 
    131131        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) 
    141132 
    142133    # These constraints are only needed for comparison to sasview 
     
    233224    model_definition = core.load_model_definition(name) 
    234225 
    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' 
    239227 
    240228    opt_values = dict(split 
     
    242230                      if len(split) == 2) 
    243231    # 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 
    248233    Nq = int(opt_values.get('-Nq', '128')) 
    249234    res = float(opt_values.get('-res', '0')) 
     
    254239 
    255240    # 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' 
    259242    cutoff = float(opt_values.get('-cutoff','1e-5')) 
    260243 
     
    264247        seed = int(opt_values['-random']) if '-random' in opt_values else None 
    265248        pars, seed = randomize_model(pars, seed=seed) 
     249        constrain_pars(model_definition, pars) 
    266250        print "Randomize using -random=%i"%seed 
    267251    pars.update(set_pars)  # set value after random to control value 
    268     constrain_pars(model_definition, pars) 
    269252 
    270253    # parameter selection 
     
    379362 
    380363    -plot*/-noplot plots or suppress the plot of the model 
    381     -single*/-double/-quad use single/double/quad precision for comparison 
     364    -single*/-double uses double precision for comparison 
    382365    -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 
    383366    -Nq=128 sets the number of Q points in the data set 
     
    403386NAME_OPTIONS = set([ 
    404387    'plot','noplot', 
    405     'single','double','longdouble', 
     388    'single','double', 
    406389    'lowq','midq','highq','exq', 
    407390    '2d','1d', 
  • sasmodels/compare_many.py

    rb514adf rcd3dba0  
    5757    num_good = 0 
    5858    first = True 
    59     max_diff = 0 
    6059    for k in range(N): 
    6160        print >>sys.stderr, name, k 
     
    7473            columns.extend(stats) 
    7574            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) 
    7876        if 0 and environment().has_double: 
    7977            gpu_double_value = trymodel(eval_opencl, dtype='double', cutoff=cutoff) 
     
    8179            columns.extend(stats) 
    8280            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) 
    8582        if 1: 
    8683            cpu_double_value = trymodel(eval_ctypes, dtype='double', cutoff=cutoff) 
     
    8885            columns.extend(stats) 
    8986            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) 
    9288        if 0: 
    9389            stats = get_stats(cpu_double_value, gpu_single_value, index) 
    9490            columns.extend(stats) 
    9591            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) 
    9893 
    9994        columns += [v for _,v in sorted(pars_i.items())] 
     
    105100        else: 
    106101            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) 
    108103 
    109104 
  • sasmodels/generate.py

    re1ace4d rcd3dba0  
    197197# TODO: identify model files which have changed since loading and reload them. 
    198198 
    199 __all__ = ["make", "doc", "sources", "use_single", "use_long_double"] 
     199__all__ = ["make", "doc", "sources", "use_single"] 
    200200 
    201201import sys 
     
    206206C_KERNEL_TEMPLATE_PATH = joinpath(dirname(__file__), 'kernel_template.c') 
    207207 
     208F64 = np.dtype('float64') 
    208209F32 = np.dtype('float32') 
    209 F64 = np.dtype('float64') 
    210 try:  # CRUFT: older numpy does not support float128 
    211     F128 = np.dtype('float128') 
    212 except TypeError: 
    213     F128 = None 
    214  
    215210 
    216211# Scale and background, which are parameters common to every form factor 
     
    327322    source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 
    328323                    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) 
    344324    return source 
    345325 
  • sasmodels/kernel_template.c

    r062c56d r6ee9d39  
    125125    if (weight > cutoff) { 
    126126      const double scattering = Iq(qi, IQ_PARAMETERS); 
    127       //if (scattering >= 0.0) { // scattering cannot be negative 
     127      if (scattering >= 0.0) { // scattering cannot be negative 
    128128        ret += weight*scattering; 
    129129        norm += weight; 
     
    133133        norm_vol += vol_weight; 
    134134      #endif 
    135       //} 
     135      } 
    136136    //else { printf("exclude qx,qy,I:%%g,%%g,%%g\n",qi,scattering); } 
    137137    } 
     
    198198 
    199199      const double scattering = Iqxy(qxi, qyi, IQXY_PARAMETERS); 
    200       //if (scattering >= 0.0) { // scattering cannot be negative 
     200      if (scattering >= 0.0) { // scattering cannot be negative 
    201201        // TODO: use correct angle for spherical correction 
    202202        // Definition of theta and phi are probably reversed relative to the 
     
    219219      #endif 
    220220        norm_vol += vol_weight; 
    221       //} 
     221      } 
    222222      //else { printf("exclude qx,qy,I:%%g,%%g,%%g\n",qi,scattering); } 
    223223    } 
  • sasmodels/kernelcl.py

    r92da231 r0763009  
    2222devices, where it can be combined with other structure factors and form 
    2323factors 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. 
    4924""" 
    5025import os 
  • sasmodels/kerneldll.py

    r5edfe12 ra30cdd5  
    1 r""" 
     1""" 
    22C types wrapper for sasview models. 
    33 
     
    55you wish to allow single precision floating point evaluation for the compiled 
    66models, 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. 
    457""" 
    468 
     
    4911import tempfile 
    5012import ctypes as ct 
    51 from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float 
     13from ctypes import c_void_p, c_int, c_double, c_float 
    5214 
    5315import numpy as np 
     
    9658    if np.dtype(dtype) == generate.F32: 
    9759        basename += "32" 
    98     elif np.dtype(dtype) == generate.F64: 
    99         basename += "64" 
    100     else: 
    101         basename += "128" 
    10260    return joinpath(DLL_PATH, basename+'.so') 
    10361 
     
    12280    models are allowed as DLLs. 
    12381    """ 
     82    if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double"   # Force 64-bit dll 
    12483    dtype = np.dtype(dtype) 
    125     if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS: 
    126         dtype = generate.F64  # Force 64-bit dll 
    12784 
    12885    if callable(info.get('Iq',None)): 
     
    13289        source = generate.use_single(source) 
    13390        tempfile_prefix = 'sas_'+info['name']+'32_' 
    134     elif dtype == generate.F64: 
    135         tempfile_prefix = 'sas_'+info['name']+'64_' 
    13691    else: 
    137         source = generate.use_long_double(source) 
    138         tempfile_prefix = 'sas_'+info['name']+'128_' 
     92        tempfile_prefix = 'sas_'+info['name']+'_' 
    13993 
    14094    source_files = generate.sources(info) + [info['filename']] 
     
    204158            raise 
    205159 
    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 
    209161        pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 
    210162        pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] 
     
    275227 
    276228    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 
    280230 
    281231        nq = c_int(self.q_input.nq) 
  • sasmodels/kernelpy.py

    r062c56d r750ffa5  
    211211        if w > cutoff: 
    212212            I = form(*args) 
    213             #positive = (I >= 0.0) 
     213            positive = (I >= 0.0) 
    214214 
    215215            # Note: can precompute spherical correction if theta_index is not 
     
    219219                                    if theta_index >= 0 else 1.0) 
    220220            #spherical_correction = 1.0 
    221             ret += w * I * spherical_correction #* positive 
    222             norm += w #* positive 
     221            ret += w * I * spherical_correction * positive 
     222            norm += w * positive 
    223223 
    224224            # Volume normalization. 
     
    230230                vol_args = [args[index] for index in vol_index] 
    231231                vol_weight = np.prod(weight[vol_weight_index]) 
    232                 vol += vol_weight * form_volume(*vol_args) #* positive 
    233                 vol_norm += vol_weight #* positive 
     232                vol += vol_weight * form_volume(*vol_args) * positive 
     233                vol_norm += vol_weight * positive 
    234234 
    235235    positive = (vol * vol_norm != 0.0) 
  • sasmodels/resolution.py

    r7f7f99f reb588ef  
    10741074 
    10751075if __name__ == "__main__": 
    1076     #demo() 
    1077     main() 
     1076    demo() 
     1077    #main() 
Note: See TracChangeset for help on using the changeset viewer.