- Timestamp:
- Nov 9, 2018 3:25:10 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 7126c04
- Parents:
- 599993b9 (diff), cf3d0ce (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. - Location:
- doc/guide
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/gpu_setup.rst
r63602b1 r8b31efa 94 94 Device Selection 95 95 ================ 96 **OpenCL drivers** 97 96 98 If you have multiple GPU devices you can tell the program which device to use. 97 99 By default, the program looks for one GPU and one CPU device from available … … 104 106 was used to run the model. 105 107 106 **If you don't want to use OpenCL, you can set** *SAS_OPENCL=None* 107 **in your environment settings, and it will only use normal programs.** 108 109 If you want to use one of the other devices, you can run the following 108 If you want to use a specific driver and devices, you can run the following 110 109 from the python console:: 111 110 … … 115 114 This will provide a menu of different OpenCL drivers available. 116 115 When one is selected, it will say "set PYOPENCL_CTX=..." 117 Use that value as the value of *SAS_OPENCL*. 116 Use that value as the value of *SAS_OPENCL=driver:device*. 117 118 To use the default OpenCL device (rather than CUDA or None), 119 set *SAS_OPENCL=opencl*. 120 121 In batch queues, you may need to set *XDG_CACHE_HOME=~/.cache* 122 (Linux only) to a different directory, depending on how the filesystem 123 is configured. You should also set *SAS_DLL_PATH* for CPU-only modules. 124 125 -DSAS_MODELPATH=path sets directory containing custom models 126 -DSAS_OPENCL=vendor:device|cuda:device|none sets the target GPU device 127 -DXDG_CACHE_HOME=~/.cache sets the pyopencl cache root (linux only) 128 -DSAS_COMPILER=tinycc|msvc|mingw|unix sets the DLL compiler 129 -DSAS_OPENMP=1 turns on OpenMP for the DLLs 130 -DSAS_DLL_PATH=path sets the path to the compiled modules 131 132 133 **CUDA drivers** 134 135 If OpenCL drivers are not available on your system, but NVidia CUDA 136 drivers are available, then set *SAS_OPENCL=cuda* or 137 *SAS_OPENCL=cuda:n* for a particular device number *n*. If no device 138 number is specified, then the CUDA drivers looks for look for 139 *CUDA_DEVICE=n* or a file ~/.cuda-device containing n for the device number. 140 141 In batch queues, the SLURM command *sbatch --gres=gpu:1 ...* will set 142 *CUDA_VISIBLE_DEVICES=n*, which ought to set the correct device 143 number for *SAS_OPENCL=cuda*. If not, then set 144 *CUDA_DEVICE=$CUDA_VISIBLE_DEVICES* within the batch script. You may 145 need to set the CUDA cache directory to a folder accessible across the 146 cluster with *PYCUDA_CACHE_DIR* (or *PYCUDA_DISABLE_CACHE* to disable 147 caching), and you may need to set environment specific compiler flags 148 with *PYCUDA_DEFAULT_NVCC_FLAGS*. You should also set *SAS_DLL_PATH* 149 for CPU-only modules. 150 151 **No GPU support** 152 153 If you don't want to use OpenCL or CUDA, you can set *SAS_OPENCL=None* 154 in your environment settings, and it will only use normal programs. 155 156 In batch queues, you may need to set *SAS_DLL_PATH* to a directory 157 accessible on the compute node. 158 118 159 119 160 Device Testing … … 154 195 *Document History* 155 196 156 | 201 7-09-27Paul Kienzle197 | 2018-10-15 Paul Kienzle -
doc/guide/plugin.rst
r57c609b raa8c6e0 291 291 292 292 **Note: The order of the parameters in the definition will be the order of the 293 parameters in the user interface and the order of the parameters in Iq(),294 Iqac(), Iqabc() and form_volume(). And** *scale* **and** *background*295 **parameters are implicit to all models, so they do not need to be included 296 in the parameter table.**293 parameters in the user interface and the order of the parameters in Fq(), Iq(), 294 Iqac(), Iqabc(), form_volume() and shell_volume(). 295 And** *scale* **and** *background* **parameters are implicit to all models, 296 so they do not need to be included in the parameter table.** 297 297 298 298 - **"name"** is the name of the parameter shown on the FitPage. … … 363 363 scattered intensity. 364 364 365 - "volume" parameters are passed to Iq(), Iqac(), Iqabc() and form_volume(),366 and have polydispersity loops generated automatically.365 - "volume" parameters are passed to Fq(), Iq(), Iqac(), Iqabc(), form_volume() 366 and shell_volume(), and have polydispersity loops generated automatically. 367 367 368 368 - "orientation" parameters are not passed, but instead are combined with … … 492 492 used. 493 493 494 Hollow shapes, where the volume fraction of particle corresponds to the 495 material in the shell rather than the volume enclosed by the shape, must 496 also define a *shell_volume(par1, par2, ...)* function. The parameters 497 are the same as for *form_volume*. The *I(q)* calculation should use 498 *shell_volume* squared as its scale factor for the volume normalization. 499 The structure factor calculation needs *form_volume* in order to properly 500 scale the volume fraction parameter, so both functions are required for 501 hollow shapes. 502 503 Note: Pure python models do not yet support direct computation of the 504 average of $F(q)$ and $F^2(q)$. 505 494 506 Embedded C Models 495 507 ................. … … 503 515 This expands into the equivalent C code:: 504 516 505 #include <math.h>506 517 double Iq(double q, double par1, double par2, ...); 507 518 double Iq(double q, double par1, double par2, ...) … … 512 523 *form_volume* defines the volume of the shape. As in python models, it 513 524 includes only the volume parameters. 525 526 *form_volume* defines the volume of the shell for hollow shapes. As in 527 python models, it includes only the volume parameters. 514 528 515 529 **source=['fn.c', ...]** includes the listed C source files in the … … 548 562 The INVALID define can go into *Iq*, or *c_code*, or an external C file 549 563 listed in *source*. 564 565 Structure Factors 566 ................. 567 568 Structure factor calculations may need the underlying $<F(q)>$ and $<F^2(q)>$ 569 rather than $I(q)$. This is used to compute $\beta = <F(q)>^2/<F^2(q)>$ in 570 the decoupling approximation to the structure factor. 571 572 Instead of defining the *Iq* function, models can define *Fq* as 573 something like:: 574 575 double Fq(double q, double *F1, double *F2, double par1, double par2, ...); 576 double Fq(double q, double *F1, double *F2, double par1, double par2, ...) 577 { 578 // Polar integration loop over all orientations. 579 ... 580 *F1 = 1e-2 * total_F1 * contrast * volume; 581 *F2 = 1e-4 * total_F2 * square(contrast * volume); 582 return I(q, par1, par2, ...); 583 } 584 585 If the volume fraction scale factor is built into the model (as occurs for 586 the vesicle model, for example), then scale *F1* by $\surd V_f$ so that 587 $\beta$ is computed correctly. 588 589 Structure factor calculations are not yet supported for oriented shapes. 590 591 Note: only available as a separate C file listed in *source*, or within 592 a *c_code* block within the python model definition file. 550 593 551 594 Oriented Shapes … … 1012 1055 "radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 1013 1056 0.2, 0.228843], 1014 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "ER", 120.], 1015 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "VR", 1.], 1057 [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 1058 0.1, None, None, 120., None, 1.], # q, F, F^2, R_eff, V, form:shell 1059 [{"@S": "hardsphere"}, 0.1, None], 1016 1060 ] 1017 1061 1018 1062 1019 **tests=[[{parameters}, q, result], ...]** is a list of lists.1063 **tests=[[{parameters}, q, Iq], ...]** is a list of lists. 1020 1064 Each list is one test and contains, in order: 1021 1065 … … 1029 1073 - input and output values can themselves be lists if you have several 1030 1074 $q$ values to test for the same model parameters. 1031 - for testing *ER* and *VR*, give the inputs as "ER" and "VR" respectively; 1032 the output for *VR* should be the sphere/shell ratio, not the individual 1033 sphere and shell values. 1075 - for testing effective radius, volume and form:shell volume ratio, use the 1076 extended form of the tests results, with *None, None, R_eff, V, V_r* 1077 instead of *Iq*. This calls the kernel *Fq* function instead of *Iq*. 1078 - for testing F and F^2 (used for beta approximation) do the same as the 1079 effective radius test, but include values for the first two elements, 1080 $<F(q)>$ and $<F^2(q)>$. 1081 - for testing interaction between form factor and structure factor, specify 1082 the structure factor name in the parameters as *{"@S": "name", ...}* with 1083 the remaining list of parameters defined by the *P@S* product model. 1034 1084 1035 1085 .. _Test_Your_New_Model: -
doc/guide/scripting.rst
rbd7630d r23df833 188 188 python kernel. Once the kernel is in hand, we can then marshal a set of 189 189 parameters into a :class:`sasmodels.details.CallDetails` object and ship it to 190 the kernel using the :func:`sansmodels.direct_model.call_kernel` function. An 191 example should help, *example/cylinder_eval.py*:: 192 193 from numpy import logspace 190 the kernel using the :func:`sansmodels.direct_model.call_kernel` function. To 191 accesses the underlying $<F(q)>$ and $<F^2(q)>$, use 192 :func:`sasmodels.direct_model.call_Fq` instead. 193 194 The following example should 195 help, *example/cylinder_eval.py*:: 196 197 from numpy import logspace, sqrt 194 198 from matplotlib import pyplot as plt 195 199 from sasmodels.core import load_model 196 from sasmodels.direct_model import call_kernel 200 from sasmodels.direct_model import call_kernel, call_Fq 197 201 198 202 model = load_model('cylinder') 199 203 q = logspace(-3, -1, 200) 200 204 kernel = model.make_kernel([q]) 201 Iq = call_kernel(kernel, dict(radius=200.)) 202 plt.loglog(q, Iq) 205 pars = {'radius': 200, 'radius_pd': 0.1, 'scale': 2} 206 Iq = call_kernel(kernel, pars) 207 F, Fsq, Reff, V, Vratio = call_Fq(kernel, pars) 208 209 plt.loglog(q, Iq, label='2 I(q)') 210 plt.loglog(q, F**2/V, label='<F(q)>^2/V') 211 plt.loglog(q, Fsq/V, label='<F^2(q)>/V') 212 plt.xlabel('q (1/A)') 213 plt.ylabel('I(q) (1/cm)') 214 plt.title('Cylinder with radius 200.') 215 plt.legend() 203 216 plt.show() 204 217 205 On windows, this can be called from the cmd prompt using sasview as:: 218 .. figure:: direct_call.png 219 220 Comparison between $I(q)$, $<F(q)>$ and $<F^2(q)>$ for cylinder model. 221 222 This compares $I(q)$ with $<F(q)>$ and $<F^2(q)>$ for a cylinder 223 with *radius=200 +/- 20* and *scale=2*. Note that *call_Fq* does not 224 include scale and background, nor does it normalize by the average volume. 225 The definition of $F = \rho V \hat F$ scaled by the contrast and 226 volume, compared to the canonical cylinder $\hat F$, with $\hat F(0) = 1$. 227 Integrating over polydispersity and orientation, the returned values are 228 $\sum_{r,w\in N(r_o, r_o/10)} \sum_\theta w F(q,r_o,\theta)\sin\theta$ and 229 $\sum_{r,w\in N(r_o, r_o/10)} \sum_\theta w F^2(q,r_o,\theta)\sin\theta$. 230 231 On windows, this example can be called from the cmd prompt using sasview as 232 as the python interpreter:: 206 233 207 234 SasViewCom example/cylinder_eval.py
Note: See TracChangeset
for help on using the changeset viewer.