Changeset 5442c77 in sasmodels


Ignore:
Timestamp:
Nov 25, 2015 9:55:17 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
2bebe2b
Parents:
402c351 (diff), e1ace4d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of github.com:sasview/sasmodels

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r5753e4e re1ace4d  
    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) 
    132141 
    133142    # These constraints are only needed for comparison to sasview 
     
    224233    model_definition = core.load_model_definition(name) 
    225234 
    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') 
    227239 
    228240    opt_values = dict(split 
     
    230242                      if len(split) == 2) 
    231243    # 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) 
    233248    Nq = int(opt_values.get('-Nq', '128')) 
    234249    res = float(opt_values.get('-res', '0')) 
     
    239254 
    240255    # 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') 
    242259    cutoff = float(opt_values.get('-cutoff','1e-5')) 
    243260 
     
    247264        seed = int(opt_values['-random']) if '-random' in opt_values else None 
    248265        pars, seed = randomize_model(pars, seed=seed) 
    249         constrain_pars(model_definition, pars) 
    250266        print "Randomize using -random=%i"%seed 
    251267    pars.update(set_pars)  # set value after random to control value 
     268    constrain_pars(model_definition, pars) 
    252269 
    253270    # parameter selection 
     
    362379 
    363380    -plot*/-noplot plots or suppress the plot of the model 
    364     -single*/-double uses double precision for comparison 
     381    -single*/-double/-quad use single/double/quad precision for comparison 
    365382    -lowq*/-midq/-highq/-exq use q values up to 0.05, 0.2, 1.0, 10.0 
    366383    -Nq=128 sets the number of Q points in the data set 
     
    386403NAME_OPTIONS = set([ 
    387404    'plot','noplot', 
    388     'single','double', 
     405    'single','double','longdouble', 
    389406    'lowq','midq','highq','exq', 
    390407    '2d','1d', 
  • sasmodels/compare_many.py

    rcd3dba0 rb514adf  
    5757    num_good = 0 
    5858    first = True 
     59    max_diff = 0 
    5960    for k in range(N): 
    6061        print >>sys.stderr, name, k 
     
    7374            columns.extend(stats) 
    7475            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) 
    7678        if 0 and environment().has_double: 
    7779            gpu_double_value = trymodel(eval_opencl, dtype='double', cutoff=cutoff) 
     
    7981            columns.extend(stats) 
    8082            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) 
    8285        if 1: 
    8386            cpu_double_value = trymodel(eval_ctypes, dtype='double', cutoff=cutoff) 
     
    8588            columns.extend(stats) 
    8689            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) 
    8892        if 0: 
    8993            stats = get_stats(cpu_double_value, gpu_single_value, index) 
    9094            columns.extend(stats) 
    9195            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) 
    9398 
    9499        columns += [v for _,v in sorted(pars_i.items())] 
     
    100105        else: 
    101106            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) 
    103108 
    104109 
  • sasmodels/generate.py

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

    r6ee9d39 r062c56d  
    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

    r0763009 r92da231  
    2222devices, where it can be combined with other structure factors and form 
    2323factors and have instrumental resolution effects applied. 
     24 
     25In order to use OpenCL for your models, you will need OpenCL drivers for 
     26your machine.  These should be available from your graphics card vendor. 
     27Intel provides OpenCL drivers for CPUs as well as their integrated HD 
     28graphics chipsets.  AMD also provides drivers for Intel CPUs, but as of 
     29this writing the performance is lacking compared to the Intel drivers. 
     30NVidia combines drivers for CUDA and OpenCL in one package.  The result 
     31is a bit messy if you have multiple drivers installed.  You can see which 
     32drivers are available by starting python and running: 
     33 
     34    import pyopencl as cl 
     35    cl.create_some_context(interactive=True) 
     36 
     37Once you have done that, it will show the available drivers which you 
     38can select.  It will then tell you that you can use these drivers 
     39automatically by setting the PYOPENCL_CTX environment variable. 
     40 
     41Some graphics cards have multiple devices on the same card.  You cannot 
     42yet use both of them concurrently to evaluate models, but you can run 
     43the program twice using a different device for each session. 
     44 
     45OpenCL kernels are compiled when needed by the device driver.  Some 
     46drivers produce compiler output even when there is no error.  You 
     47can see the output by setting PYOPENCL_COMPILER_OUTPUT=1.  It should be 
     48harmless, albeit annoying. 
    2449""" 
    2550import os 
  • sasmodels/kerneldll.py

    ra30cdd5 r5edfe12  
    1 """ 
     1r""" 
    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 
     8The compiler command line is stored in the attribute *COMPILE*, with string 
     9substitutions for %(source)s and %(output)s indicating what to compile and 
     10where to store it.  The actual command is system dependent. 
     11 
     12On windows systems, you have a choice of compilers.  *MinGW* is the GNU 
     13compiler toolchain, available in packages such as anaconda and PythonXY, 
     14or available stand alone. This toolchain has had difficulties on some 
     15systems, and may or may not work for you.  In order to build DLLs, *gcc* 
     16must be on your path.  If the environment variable *SAS_OPENMP* is given 
     17then -fopenmp is added to the compiler flags.  This requires a version 
     18of MinGW compiled with OpenMP support. 
     19 
     20An alternative toolchain uses the Microsoft Visual C++ compiler, available 
     21free from microsoft: 
     22 
     23    `http://www.microsoft.com/en-us/download/details.aspx?id=44266`_ 
     24 
     25Again, this requires that the compiler is available on your path.  This is 
     26done by running vcvarsall.bat in a windows terminal.  Install locations are 
     27system dependent, such as: 
     28 
     29    C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
     30 
     31or maybe 
     32 
     33    C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
     34 
     35And again, the environment variable *SAS_OPENMP* controls whether OpenMP is 
     36used to compile the C code.  This requires the Microsoft vcomp90.dll library, 
     37which doesn't seem to be included with the compiler, nor does there appear 
     38to be a public download location.  There may be one on your machine already 
     39in a location such as: 
     40 
     41    C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll 
     42 
     43If you copy this onto your path, such as the python directory or the install 
     44directory for this application, then OpenMP should be supported. 
    745""" 
    846 
     
    1149import tempfile 
    1250import ctypes as ct 
    13 from ctypes import c_void_p, c_int, c_double, c_float 
     51from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float 
    1452 
    1553import numpy as np 
     
    5896    if np.dtype(dtype) == generate.F32: 
    5997        basename += "32" 
     98    elif np.dtype(dtype) == generate.F64: 
     99        basename += "64" 
     100    else: 
     101        basename += "128" 
    60102    return joinpath(DLL_PATH, basename+'.so') 
    61103 
     
    80122    models are allowed as DLLs. 
    81123    """ 
    82     if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double"   # Force 64-bit dll 
    83124    dtype = np.dtype(dtype) 
     125    if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS: 
     126        dtype = generate.F64  # Force 64-bit dll 
    84127 
    85128    if callable(info.get('Iq',None)): 
     
    89132        source = generate.use_single(source) 
    90133        tempfile_prefix = 'sas_'+info['name']+'32_' 
     134    elif dtype == generate.F64: 
     135        tempfile_prefix = 'sas_'+info['name']+'64_' 
    91136    else: 
    92         tempfile_prefix = 'sas_'+info['name']+'_' 
     137        source = generate.use_long_double(source) 
     138        tempfile_prefix = 'sas_'+info['name']+'128_' 
    93139 
    94140    source_files = generate.sources(info) + [info['filename']] 
     
    158204            raise 
    159205 
    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) 
    161209        pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 
    162210        pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] 
     
    227275 
    228276    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) 
    230280 
    231281        nq = c_int(self.q_input.nq) 
  • sasmodels/kernelpy.py

    r750ffa5 r062c56d  
    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

    reb588ef r7f7f99f  
    10741074 
    10751075if __name__ == "__main__": 
    1076     demo() 
    1077     #main() 
     1076    #demo() 
     1077    main() 
  • doc/Makefile

    r34375ea r402c351  
    99BUILDDIR      = _build 
    1010ifdef ComSpec 
    11     RMDIR   = del /s/q/f 
     11    RMDIR   = rmdir /s/q 
    1212    CPDIR   = xcopy /q/e/i 
    1313    MKDIR   = mkdir 
     
    6161 
    6262api: genapi.py 
    63         $(RMDIR) api 
     63        -$(RMDIR) api 
    6464        $(PYTHON) genapi.py 
    6565 
Note: See TracChangeset for help on using the changeset viewer.