- Timestamp:
- Oct 30, 2018 10:59:40 AM (5 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- c1799d3
- Parents:
- 6da1d76 (diff), c6084f1 (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:
- sasmodels
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
rb6dab59 r17695aa 368 368 369 369 # Limit magnetic SLDs to a smaller range, from zero to iron=5/A^2 370 if par.name. startswith('M0:'):370 if par.name.endswith('_M0'): 371 371 return np.random.uniform(0, 5) 372 372 … … 538 538 magnetic_pars = [] 539 539 for p in parameters.user_parameters(pars, is2d): 540 if any(p.id. startswith(x) for x in ('M0:', 'mtheta:', 'mphi:')):540 if any(p.id.endswith(x) for x in ('_M0', '_mtheta', '_mphi')): 541 541 continue 542 542 if p.id.startswith('up:'): … … 550 550 pdtype=pars.get(p.id+"_pd_type", 'gaussian'), 551 551 relative_pd=p.relative_pd, 552 M0=pars.get( 'M0:'+p.id, 0.),553 mphi=pars.get( 'mphi:'+p.id, 0.),554 mtheta=pars.get( 'mtheta:'+p.id, 0.),552 M0=pars.get(p.id+'_M0', 0.), 553 mphi=pars.get(p.id+'_mphi', 0.), 554 mtheta=pars.get(p.id+'_mtheta', 0.), 555 555 ) 556 556 lines.append(_format_par(p.name, **fields)) … … 618 618 if suppress: 619 619 for p in pars: 620 if p. startswith("M0:"):620 if p.endswith("_M0"): 621 621 pars[p] = 0 622 622 else: … … 624 624 first_mag = None 625 625 for p in pars: 626 if p. startswith("M0:"):626 if p.endswith("_M0"): 627 627 any_mag |= (pars[p] != 0) 628 628 if first_mag is None: -
sasmodels/convert.py
ra69d8cd r610ef23 165 165 if version == (3, 1, 2): 166 166 oldpars = _hand_convert_3_1_2_to_4_1(name, oldpars) 167 if version < (4, 2, 0): 168 oldpars = _rename_magnetic_pars(oldpars) 167 169 return oldpars 170 171 def _rename_magnetic_pars(pars): 172 """ 173 Change from M0:par to par_M0, etc. 174 """ 175 keys = list(pars.items()) 176 for k in keys: 177 if k.startswith('M0:'): 178 pars[k[3:]+'_M0'] = pars.pop(k) 179 elif k.startswith('mtheta:'): 180 pars[k[7:]+'_mtheta'] = pars.pop(k) 181 elif k.startswith('mphi:'): 182 pars[k[5:]+'_mphi'] = pars.pop(k) 183 elif k.startswith('up:'): 184 pars['up_'+k[3:]] = pars.pop(k) 185 return pars 168 186 169 187 def _hand_convert_3_1_2_to_4_1(name, oldpars): -
sasmodels/kernelpy.py
r91bd550 r12eec1e 37 37 self.info = model_info 38 38 self.dtype = np.dtype('d') 39 logger.info("make python model " + self.info.name) 39 40 40 41 def make_kernel(self, q_vectors): -
sasmodels/model_test.py
r012cd34 r12eec1e 47 47 import sys 48 48 import unittest 49 import traceback 49 50 50 51 try: … … 74 75 # pylint: enable=unused-import 75 76 76 77 77 def make_suite(loaders, models): 78 78 # type: (List[str], List[str]) -> unittest.TestSuite … … 86 86 *models* is the list of models to test, or *["all"]* to test all models. 87 87 """ 88 ModelTestCase = _hide_model_case_from_nose()89 88 suite = unittest.TestSuite() 90 89 … … 95 94 skip = [] 96 95 for model_name in models: 97 if model_name in skip: 98 continue 99 model_info = load_model_info(model_name) 100 101 #print('------') 102 #print('found tests in', model_name) 103 #print('------') 104 105 # if ispy then use the dll loader to call pykernel 106 # don't try to call cl kernel since it will not be 107 # available in some environmentes. 108 is_py = callable(model_info.Iq) 109 110 # Some OpenCL drivers seem to be flaky, and are not producing the 111 # expected result. Since we don't have known test values yet for 112 # all of our models, we are instead going to compare the results 113 # for the 'smoke test' (that is, evaluation at q=0.1 for the default 114 # parameters just to see that the model runs to completion) between 115 # the OpenCL and the DLL. To do this, we define a 'stash' which is 116 # shared between OpenCL and DLL tests. This is just a list. If the 117 # list is empty (which it will be when DLL runs, if the DLL runs 118 # first), then the results are appended to the list. If the list 119 # is not empty (which it will be when OpenCL runs second), the results 120 # are compared to the results stored in the first element of the list. 121 # This is a horrible stateful hack which only makes sense because the 122 # test suite is thrown away after being run once. 123 stash = [] 124 125 if is_py: # kernel implemented in python 126 test_name = "%s-python"%model_name 127 test_method_name = "test_%s_python" % model_info.id 96 if model_name not in skip: 97 model_info = load_model_info(model_name) 98 _add_model_to_suite(loaders, suite, model_info) 99 100 return suite 101 102 def _add_model_to_suite(loaders, suite, model_info): 103 ModelTestCase = _hide_model_case_from_nose() 104 105 #print('------') 106 #print('found tests in', model_name) 107 #print('------') 108 109 # if ispy then use the dll loader to call pykernel 110 # don't try to call cl kernel since it will not be 111 # available in some environmentes. 112 is_py = callable(model_info.Iq) 113 114 # Some OpenCL drivers seem to be flaky, and are not producing the 115 # expected result. Since we don't have known test values yet for 116 # all of our models, we are instead going to compare the results 117 # for the 'smoke test' (that is, evaluation at q=0.1 for the default 118 # parameters just to see that the model runs to completion) between 119 # the OpenCL and the DLL. To do this, we define a 'stash' which is 120 # shared between OpenCL and DLL tests. This is just a list. If the 121 # list is empty (which it will be when DLL runs, if the DLL runs 122 # first), then the results are appended to the list. If the list 123 # is not empty (which it will be when OpenCL runs second), the results 124 # are compared to the results stored in the first element of the list. 125 # This is a horrible stateful hack which only makes sense because the 126 # test suite is thrown away after being run once. 127 stash = [] 128 129 if is_py: # kernel implemented in python 130 test_name = "%s-python"%model_info.name 131 test_method_name = "test_%s_python" % model_info.id 132 test = ModelTestCase(test_name, model_info, 133 test_method_name, 134 platform="dll", # so that 135 dtype="double", 136 stash=stash) 137 suite.addTest(test) 138 else: # kernel implemented in C 139 140 # test using dll if desired 141 if 'dll' in loaders or not use_opencl(): 142 test_name = "%s-dll"%model_info.name 143 test_method_name = "test_%s_dll" % model_info.id 128 144 test = ModelTestCase(test_name, model_info, 129 test_method_name,130 platform="dll", # so that131 dtype="double",132 stash=stash)145 test_method_name, 146 platform="dll", 147 dtype="double", 148 stash=stash) 133 149 suite.addTest(test) 134 else: # kernel implemented in C 135 136 # test using dll if desired 137 if 'dll' in loaders or not use_opencl(): 138 test_name = "%s-dll"%model_name 139 test_method_name = "test_%s_dll" % model_info.id 140 test = ModelTestCase(test_name, model_info, 141 test_method_name, 142 platform="dll", 143 dtype="double", 144 stash=stash) 145 suite.addTest(test) 146 147 # test using opencl if desired and available 148 if 'opencl' in loaders and use_opencl(): 149 test_name = "%s-opencl"%model_name 150 test_method_name = "test_%s_opencl" % model_info.id 151 # Using dtype=None so that the models that are only 152 # correct for double precision are not tested using 153 # single precision. The choice is determined by the 154 # presence of *single=False* in the model file. 155 test = ModelTestCase(test_name, model_info, 156 test_method_name, 157 platform="ocl", dtype=None, 158 stash=stash) 159 #print("defining", test_name) 160 suite.addTest(test) 161 162 return suite 150 151 # test using opencl if desired and available 152 if 'opencl' in loaders and use_opencl(): 153 test_name = "%s-opencl"%model_info.name 154 test_method_name = "test_%s_opencl" % model_info.id 155 # Using dtype=None so that the models that are only 156 # correct for double precision are not tested using 157 # single precision. The choice is determined by the 158 # presence of *single=False* in the model file. 159 test = ModelTestCase(test_name, model_info, 160 test_method_name, 161 platform="ocl", dtype=None, 162 stash=stash) 163 #print("defining", test_name) 164 suite.addTest(test) 165 163 166 164 167 def _hide_model_case_from_nose(): … … 348 351 return abs(target-actual)/shift < 1.5*10**-digits 349 352 350 def run_one(model): 351 # type: (str) -> str 352 """ 353 Run the tests for a single model, printing the results to stdout. 354 355 *model* can by a python file, which is handy for checking user defined 356 plugin models. 353 # CRUFT: old interface; should be deprecated and removed 354 def run_one(model_name): 355 # msg = "use check_model(model_info) rather than run_one(model_name)" 356 # warnings.warn(msg, category=DeprecationWarning, stacklevel=2) 357 try: 358 model_info = load_model_info(model_name) 359 except Exception: 360 output = traceback.format_exc() 361 return output 362 363 success, output = check_model(model_info) 364 return output 365 366 def check_model(model_info): 367 # type: (ModelInfo) -> str 368 """ 369 Run the tests for a single model, capturing the output. 370 371 Returns success status and the output string. 357 372 """ 358 373 # Note that running main() directly did not work from within the … … 369 384 # Build a test suite containing just the model 370 385 loaders = ['opencl'] if use_opencl() else ['dll'] 371 models = [model] 372 try: 373 suite = make_suite(loaders, models) 374 except Exception: 375 import traceback 376 stream.writeln(traceback.format_exc()) 377 return 386 suite = unittest.TestSuite() 387 _add_model_to_suite(loaders, suite, model_info) 378 388 379 389 # Warn if there are no user defined tests. … … 390 400 for test in suite: 391 401 if not test.info.tests: 392 stream.writeln("Note: %s has no user defined tests."%model )402 stream.writeln("Note: %s has no user defined tests."%model_info.name) 393 403 break 394 404 else: … … 406 416 output = stream.getvalue() 407 417 stream.close() 408 return output418 return result.wasSuccessful(), output 409 419 410 420 -
sasmodels/modelinfo.py
r6da1d76 r17695aa 473 473 self.is_asymmetric = any(p.name == 'psi' for p in self.kernel_parameters) 474 474 self.magnetism_index = [k for k, p in enumerate(self.call_parameters) 475 if p.id. startswith('M0:')]475 if p.id.endswith('_M0')] 476 476 477 477 self.pd_1d = set(p.name for p in self.call_parameters … … 604 604 if self.nmagnetic > 0: 605 605 full_list.extend([ 606 Parameter('up :frac_i', '', 0., [0., 1.],606 Parameter('up_frac_i', '', 0., [0., 1.], 607 607 'magnetic', 'fraction of spin up incident'), 608 Parameter('up :frac_f', '', 0., [0., 1.],608 Parameter('up_frac_f', '', 0., [0., 1.], 609 609 'magnetic', 'fraction of spin up final'), 610 Parameter('up :angle', 'degrees', 0., [0., 360.],610 Parameter('up_angle', 'degrees', 0., [0., 360.], 611 611 'magnetic', 'spin up angle'), 612 612 ]) … … 614 614 for p in slds: 615 615 full_list.extend([ 616 Parameter( 'M0:'+p.id, '1e-6/Ang^2', 0., [-np.inf, np.inf],616 Parameter(p.id+'_M0', '1e-6/Ang^2', 0., [-np.inf, np.inf], 617 617 'magnetic', 'magnetic amplitude for '+p.description), 618 Parameter( 'mtheta:'+p.id, 'degrees', 0., [-90., 90.],618 Parameter(p.id+'_mtheta', 'degrees', 0., [-90., 90.], 619 619 'magnetic', 'magnetic latitude for '+p.description), 620 Parameter( 'mphi:'+p.id, 'degrees', 0., [-180., 180.],620 Parameter(p.id+'_mphi', 'degrees', 0., [-180., 180.], 621 621 'magnetic', 'magnetic longitude for '+p.description), 622 622 ]) … … 658 658 659 659 Parameters marked as sld will automatically have a set of associated 660 magnetic parameters ( m0:p, mtheta:p, mphi:p), as well as polarization661 information (up :theta, up:frac_i, up:frac_f).660 magnetic parameters (p_M0, p_mtheta, p_mphi), as well as polarization 661 information (up_theta, up_frac_i, up_frac_f). 662 662 """ 663 663 # control parameters go first … … 686 686 result.append(expanded_pars[name]) 687 687 if is2d: 688 for tag in ' M0:', 'mtheta:', 'mphi:':689 if tag+namein expanded_pars:690 result.append(expanded_pars[ tag+name])688 for tag in '_M0', '_mtheta', '_mphi': 689 if name+tag in expanded_pars: 690 result.append(expanded_pars[name+tag]) 691 691 692 692 # Gather the user parameters in order … … 721 721 append_group(p.id) 722 722 723 if is2d and 'up :angle' in expanded_pars:723 if is2d and 'up_angle' in expanded_pars: 724 724 result.extend([ 725 expanded_pars['up :frac_i'],726 expanded_pars['up :frac_f'],727 expanded_pars['up :angle'],725 expanded_pars['up_frac_i'], 726 expanded_pars['up_frac_f'], 727 expanded_pars['up_angle'], 728 728 ]) 729 729 … … 1047 1047 for k in range(control+1, p.length+1) 1048 1048 if p.length > 1) 1049 for p in self.parameters.kernel_parameters: 1050 if p.length > 1 and p.type == "sld": 1051 for k in range(control+1, p.length+1): 1052 base = p.id+str(k) 1053 hidden.update((base+"_M0", base+"_mtheta", base+"_mphi")) 1049 1054 return hidden -
sasmodels/models/spinodal.py
r475ff58 r93fe8a1 12 12 where $x=q/q_0$, $q_0$ is the peak position, $I_{max}$ is the intensity 13 13 at $q_0$ (parameterised as the $scale$ parameter), and $B$ is a flat 14 background. The spinodal wavelength is given by $2\pi/q_0$. 14 background. The spinodal wavelength, $\Lambda$, is given by $2\pi/q_0$. 15 16 The definition of $I_{max}$ in the literature varies. Hashimoto *et al* (1991) 17 define it as 18 19 .. math:: 20 I_{max} = \Lambda^3\Delta\rho^2 21 22 whereas Meier & Strobl (1987) give 23 24 .. math:: 25 I_{max} = V_z\Delta\rho^2 26 27 where $V_z$ is the volume per monomer unit. 15 28 16 29 The exponent $\gamma$ is equal to $d+1$ for off-critical concentration … … 28 41 29 42 H. Furukawa. Dynamics-scaling theory for phase-separating unmixing mixtures: 30 Growth rates of droplets and scaling properties of autocorrelation functions. 31 Physica A 123,497 (1984). 43 Growth rates of droplets and scaling properties of autocorrelation functions. 44 Physica A 123, 497 (1984). 45 46 H. Meier & G. Strobl. Small-Angle X-ray Scattering Study of Spinodal 47 Decomposition in Polystyrene/Poly(styrene-co-bromostyrene) Blends. 48 Macromolecules 20, 649-654 (1987). 49 50 T. Hashimoto, M. Takenaka & H. Jinnai. Scattering Studies of Self-Assembling 51 Processes of Polymer Blends in Spinodal Decomposition. 52 J. Appl. Cryst. 24, 457-466 (1991). 32 53 33 54 Revision History … … 35 56 36 57 * **Author:** Dirk Honecker **Date:** Oct 7, 2016 37 * **Revised:** Steve King **Date:** Sep 7, 201858 * **Revised:** Steve King **Date:** Oct 25, 2018 38 59 """ 39 60 -
sasmodels/sasview_model.py
r6da1d76 r17695aa 382 382 hidden.add('scale') 383 383 hidden.add('background') 384 385 # Update the parameter lists to exclude any hidden parameters 386 self.magnetic_params = tuple(pname for pname in self.magnetic_params 387 if pname not in hidden) 388 self.orientation_params = tuple(pname for pname in self.orientation_params 389 if pname not in hidden) 384 390 385 391 self._persistency_dict = {} … … 796 802 return value, [value], [1.0] 797 803 804 @classmethod 805 def runTests(cls): 806 """ 807 Run any tests built into the model and captures the test output. 808 809 Returns success flag and output 810 """ 811 from .model_test import check_model 812 return check_model(cls._model_info) 813 798 814 def test_cylinder(): 799 815 # type: () -> float … … 911 927 Model = _make_standard_model('sphere') 912 928 model = Model() 913 model.setParam(' M0:sld', 8)929 model.setParam('sld_M0', 8) 914 930 q = np.linspace(-0.35, 0.35, 500) 915 931 qx, qy = np.meshgrid(q, q) -
sasmodels/special.py
rdf69efa rfba9ca0 113 113 The standard math function, tgamma(x) is unstable for $x < 1$ 114 114 on some platforms. 115 116 sas_gammaln(x): 117 log gamma function sas_gammaln\ $(x) = \log \Gamma(|x|)$. 118 119 The standard math function, lgamma(x), is incorrect for single 120 precision on some platforms. 121 122 sas_gammainc(a, x), sas_gammaincc(a, x): 123 Incomplete gamma function 124 sas_gammainc\ $(a, x) = \int_0^x t^{a-1}e^{-t}\,dt / \Gamma(a)$ 125 and complementary incomplete gamma function 126 sas_gammaincc\ $(a, x) = \int_x^\infty t^{a-1}e^{-t}\,dt / \Gamma(a)$ 115 127 116 128 sas_erf(x), sas_erfc(x): … … 207 219 from numpy import pi, nan, inf 208 220 from scipy.special import gamma as sas_gamma 221 from scipy.special import gammaln as sas_gammaln 222 from scipy.special import gammainc as sas_gammainc 223 from scipy.special import gammaincc as sas_gammaincc 209 224 from scipy.special import erf as sas_erf 210 225 from scipy.special import erfc as sas_erfc -
sasmodels/direct_model.py
r7b9e4dd rb6d1d52 31 31 from . import resolution2d 32 32 from .details import make_kernel_args, dispersion_mesh 33 from .modelinfo import DEFAULT_BACKGROUND34 33 35 34 # pylint: disable=unused-import … … 350 349 351 350 # Need to pull background out of resolution for multiple scattering 352 background = pars.get('background', DEFAULT_BACKGROUND) 351 default_background = self._model.info.parameters.common_parameters[1].default 352 background = pars.get('background', default_background) 353 353 pars = pars.copy() 354 354 pars['background'] = 0. -
sasmodels/generate.py
r6e45516 rb6dab59 968 968 pars = model_info.parameters.kernel_parameters 969 969 else: 970 pars = model_info.parameters.COMMON + model_info.parameters.kernel_parameters 970 pars = (model_info.parameters.common_parameters 971 + model_info.parameters.kernel_parameters) 971 972 partable = make_partable(pars) 972 973 subst = dict(id=model_info.id.replace('_', '-'), -
sasmodels/models/hardsphere.py
r2d81cfe rb6dab59 171 171 # VR defaults to 1.0 172 172 173 demo = dict(radius_effective=200, volfraction=0.2,174 radius_effective_pd=0.1, radius_effective_pd_n=40)175 173 # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, 176 174 # assuming double precision sasview is correct
Note: See TracChangeset
for help on using the changeset viewer.