source: sasmodels/sasmodels/convert.py @ 298621b

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 298621b was 298621b, checked in by krzywon, 7 years ago

Documented versioning and modified how it works for better future compatibility.

  • Property mode set to 100644
File size: 23.0 KB
Line 
1"""
2Convert models to and from sasview.
3"""
4from __future__ import print_function, division
5
6import re
7import math
8import warnings
9
10from .conversion_table import CONVERSION_TABLE
11from .core import load_model_info
12
13# List of models which SasView versions don't contain the explicit 'scale' argument.
14# When converting such a model, please update this list.
15MODELS_WITHOUT_SCALE = [
16    'teubner_strey',
17    'broad_peak',
18    'two_lorentzian',
19    "two_power_law",
20    'gauss_lorentz_gel',
21    'be_polyelectrolyte',
22    'correlation_length',
23    'fractal_core_shell',
24    'binary_hard_sphere',
25    'raspberry'
26]
27
28# List of models which SasView versions don't contain the explicit 'background' argument.
29# When converting such a model, please update this list.
30MODELS_WITHOUT_BACKGROUND = [
31    'guinier',
32]
33
34MODELS_WITHOUT_VOLFRACTION = [
35    'fractal',
36    'vesicle',
37    'multilayer_vesicle',
38]
39
40MAGNETIC_SASVIEW_MODELS = [
41    'core_shell',
42    'core_multi_shell',
43    'cylinder',
44    'parallelepiped',
45    'sphere',
46]
47
48
49# Convert new style names for polydispersity info to old style names
50PD_DOT = [
51    ("_pd", ".width"),
52    ("_pd_n", ".npts"),
53    ("_pd_nsigma", ".nsigmas"),
54    ("_pd_type", ".type"),
55    (".lower", ".lower"),
56    (".upper", ".upper"),
57    (".fittable", ".fittable"),
58    (".std", ".std"),
59    (".units", ".units"),
60    ("", "")
61    ]
62
63def _rescale(par, scale):
64    return [pk*scale for pk in par] if isinstance(par, list) else par*scale
65
66def _is_sld(model_info, id):
67    """
68    Return True if parameter is a magnetic magnitude or SLD parameter.
69    """
70    if id.startswith('M0:'):
71        return True
72    if '_pd' in id or '.' in id:
73        return False
74    for p in model_info.parameters.call_parameters:
75        if p.id == id:
76            return p.type == 'sld'
77    # check through kernel parameters in case it is a named as a vector
78    for p in model_info.parameters.kernel_parameters:
79        if p.id == id:
80            return p.type == 'sld'
81    return False
82
83def _rescale_sld(model_info, pars, scale):
84    """
85    rescale all sld parameters in the new model definition by *scale* so the
86    numbers are nicer.  Relies on the fact that all sld parameters in the
87    new model definition end with sld.  For backward conversion use
88    *scale=1e-6*.  For forward conversion use *scale=1e6*.
89    """
90    return dict((id, (_rescale(v, scale) if _is_sld(model_info, id) else v))
91                for id, v in pars.items())
92
93
94def _get_translation_table(model_info, version='4.0.1'):
95    _, translation = CONVERSION_TABLE.get(version).get(model_info.id, [None, {}])
96    translation = translation.copy()
97    for p in model_info.parameters.kernel_parameters:
98        if p.length > 1:
99            newid = p.id
100            oldid = translation.get(p.id, p.id)
101            translation.pop(newid, None)
102            for k in range(1, p.length+1):
103                if newid+str(k) not in translation:
104                    translation[newid+str(k)] = oldid+str(k)
105    # Remove control parameter from the result
106    if model_info.control:
107        translation[model_info.control] = "CONTROL"
108    return translation
109
110# ========= FORWARD CONVERSION sasview 3.x => sasmodels ===========
111def _dot_pd_to_underscore_pd(par):
112    if par.endswith(".width"):
113        return par[:-6]+"_pd"
114    elif par.endswith(".type"):
115        return par[:-5]+"_pd_type"
116    elif par.endswith(".nsigmas"):
117        return par[:-8]+"_pd_nsigma"
118    elif par.endswith(".npts"):
119        return par[:-5]+"_pd_n"
120    else:
121        return par
122
123def _pd_to_underscores(pars):
124    return dict((_dot_pd_to_underscore_pd(k), v) for k, v in pars.items())
125
126def _convert_pars(pars, mapping):
127    """
128    Rename the parameters and any associated polydispersity attributes.
129    """
130    newpars = pars.copy()
131    for new, old in mapping.items():
132        if old == new: continue
133        if old is None: continue
134        for underscore, dot in PD_DOT:
135            source = old+dot
136            if source in newpars:
137                if new is not None:
138                    target = new+dot
139                else:
140                    target = None
141                if source != target:
142                    if target:
143                        newpars[target] = pars[old+dot]
144                    del newpars[source]
145    return newpars
146
147def _conversion_target(model_name, version='4.0.1'):
148    """
149    Find the sasmodel name which translates into the sasview name.
150
151    Note: *CoreShellEllipsoidModel* translates into *core_shell_ellipsoid:1*.
152    This is necessary since there is only one variant in sasmodels for the
153    two variants in sasview.
154    """
155    for sasmodels_name, [sasview_name, _] in \
156            CONVERSION_TABLE.get(version).items():
157        if sasview_name == model_name:
158            return sasmodels_name
159    return None
160
161def _hand_convert(name, oldpars, version='3.1.2'):
162    base_version = '3.1.2'
163    if name == 'core_shell_parallelepiped' and version == base_version:
164        # Make sure pd on rim parameters defaults to zero
165        # ... probably not necessary.
166        oldpars['rimA.width'] = 0.0
167        oldpars['rimB.width'] = 0.0
168        oldpars['rimC.width'] = 0.0
169    elif name == 'core_shell_ellipsoid:1' and version == base_version:
170        # Reverse translation (from new to old), from core_shell_ellipsoid.c
171        #    equat_shell = equat_core + thick_shell
172        #    polar_core = equat_core * x_core
173        #    polar_shell = equat_core * x_core + thick_shell*x_polar_shell
174        # Forward translation (from old to new), inverting reverse translation:
175        #    thick_shell = equat_shell - equat_core
176        #    x_core = polar_core / equat_core
177        #    x_polar_shell = (polar_shell - polar_core)/(equat_shell - equat_core)
178        # Auto translation (old <=> new) happens after hand_convert
179        #    equat_shell <=> thick_shell
180        #    polar_core <=> x_core
181        #    polar_shell <=> x_polar_shell
182        # So...
183        equat_core, equat_shell = oldpars['equat_core'], oldpars['equat_shell']
184        polar_core, polar_shell = oldpars['polar_core'], oldpars['polar_shell']
185        oldpars['equat_shell'] = equat_shell - equat_core
186        oldpars['polar_core'] = polar_core / equat_core
187        oldpars['polar_shell'] = (polar_shell-polar_core)/(equat_shell-equat_core)
188    elif name == 'hollow_cylinder' and version == base_version:
189        # now uses radius and thickness
190        thickness = oldpars['radius'] - oldpars['core_radius']
191        oldpars['radius'] = thickness
192        if 'radius.width' in oldpars:
193            pd = oldpars['radius.width']*oldpars['radius']/thickness
194            oldpars['radius.width'] = pd
195    elif name == 'multilayer_vesicle' and version == base_version:
196        if 'scale' in oldpars:
197            oldpars['volfraction'] = oldpars['scale']
198            oldpars['scale'] = 1.0
199        if 'scale.lower' in oldpars:
200            oldpars['volfraction.lower'] = oldpars['scale.lower']
201        if 'scale.upper' in oldpars:
202            oldpars['volfraction.upper'] = oldpars['scale.upper']
203        if 'scale.fittable' in oldpars:
204            oldpars['volfraction.fittable'] = oldpars['scale.fittable']
205        if 'scale.std' in oldpars:
206            oldpars['volfraction.std'] = oldpars['scale.std']
207        if 'scale.units' in oldpars:
208            oldpars['volfraction.units'] = oldpars['scale.units']
209    elif name == 'pearl_necklace' and version == base_version:
210        pass
211        #_remove_pd(oldpars, 'num_pearls', name)
212        #_remove_pd(oldpars, 'thick_string', name)
213    elif name == 'polymer_micelle' and version == base_version:
214        if 'ndensity' in oldpars:
215            oldpars['ndensity'] /= 1e15
216        if 'ndensity.lower' in oldpars:
217            oldpars['ndensity.lower'] /= 1e15
218        if 'ndensity.upper' in oldpars:
219            oldpars['ndensity.upper'] /= 1e15
220    elif name == 'rpa' and version == '4.0.1':
221        # convert scattering lengths from femtometers to centimeters
222        for p in "L1", "L2", "L3", "L4":
223            if p in oldpars:
224                oldpars[p] /= 1e-13
225            if p + ".lower" in oldpars:
226                oldpars[p + ".lower"] /= 1e-13
227            if p + ".upper" in oldpars:
228                oldpars[p + ".upper"] /= 1e-13
229    elif name == 'spherical_sld' and version == base_version:
230        oldpars["CONTROL"] = 0
231        i = 0
232        while "nu_inter" + str(i) in oldpars:
233            oldpars["CONTROL"] += 1
234            i += 1
235    elif name == 'teubner_strey' and version == base_version:
236        # basically undoing the entire Teubner-Strey calculations here.
237        #    drho = (sld_a - sld_b)
238        #    k = 2.0*math.pi*xi/d
239        #    a2 = (1.0 + k**2)**2
240        #    c1 = 2.0 * xi**2 * (1.0 - k**2)
241        #    c2 = xi**4
242        #    prefactor = 8.0*math.pi*phi*(1.0-phi)*drho**2*c2/xi
243        #    scale = 1e-4*prefactor
244        #    oldpars['scale'] = a2/scale
245        #    oldpars['c1'] = c1/scale
246        #    oldpars['c2'] = c2/scale
247
248        # need xi, d, sld_a, sld_b, phi=volfraction_a
249        # assume contrast is 1.0e-6, scale=1, background=0
250        sld_a, sld_b = 1.0, 0.
251        drho = sld_a - sld_b
252
253        # find xi
254        p_scale = oldpars['scale']
255        p_c1 = oldpars['c1']
256        p_c2= oldpars['c2']
257        i_1 = 0.5*p_c1/p_c2
258        i_2 = math.sqrt(math.fabs(p_scale/p_c2))
259        i_3 = 2/(i_1 + i_2)
260        xi = math.sqrt(math.fabs(i_3))
261
262        # find d from xi
263        k = math.sqrt(math.fabs(1 - 0.5*p_c1/p_c2*xi**2))
264        d = 2*math.pi*xi/k
265
266        # solve quadratic phi (1-phi) = xi/(1e-4 8 pi drho^2 c2)
267        # favour volume fraction in [0, 0.5]
268        c = xi / (1e-4 * 8.0 * math.pi * drho**2 * p_c2)
269        phi = 0.5 - math.sqrt(0.25 - c)
270
271        # scale sld_a by 1e-6 because the translator will scale it back
272        oldpars.update(volfraction_a=phi, xi=xi, d=d, sld_a=sld_a*1e-6,
273                       sld_b=sld_b, scale=1.0)
274        oldpars.pop('c1')
275        oldpars.pop('c2')
276
277    return oldpars
278
279def convert_model(name, pars, use_underscore=False):
280    """
281    Convert model from old style parameter names to new style.
282    """
283    newpars = pars
284    for version, _ in sorted(CONVERSION_TABLE.iteritems()):
285        newname = _conversion_target(name, version)
286        if newname is None:
287            newname = name
288            continue
289        if ':' in newname:   # core_shell_ellipsoid:1
290            model_info = load_model_info(newname[:-2])
291            # Know the table exists and isn't multiplicity so grab it directly
292            # Can't use _get_translation_table since that will return the 'bare'
293            # version.
294            translation = CONVERSION_TABLE.get(version)[newname][1]
295        else:
296            model_info = load_model_info(newname)
297            translation = _get_translation_table(model_info, version)
298        newpars = _hand_convert(newname, newpars, version)
299        newpars = _convert_pars(newpars, translation)
300        if not model_info.structure_factor:
301            newpars = _rescale_sld(model_info, newpars, 1e6)
302        newpars.setdefault('scale', 1.0)
303        newpars.setdefault('background', 0.0)
304        if use_underscore:
305            newpars = _pd_to_underscores(newpars)
306        name = newname
307    return newname, newpars
308
309# ========= BACKWARD CONVERSION sasmodels => sasview 3.x ===========
310
311def _revert_pars(pars, mapping):
312    """
313    Rename the parameters and any associated polydispersity attributes.
314    """
315    newpars = pars.copy()
316
317    for new, old in mapping.items():
318        for underscore, dot in PD_DOT:
319            if old and old+underscore == new+dot:
320                continue
321            if new+underscore in newpars:
322                if old is not None:
323                    newpars[old+dot] = pars[new+underscore]
324                del newpars[new+underscore]
325    for k in list(newpars.keys()):
326        for underscore, dot in PD_DOT[1:]:  # skip "" => ""
327            if k.endswith(underscore):
328                newpars[k[:-len(underscore)]+dot] = newpars[k]
329                del newpars[k]
330    return newpars
331
332def revert_name(model_info):
333    oldname, _ = CONVERSION_TABLE.get(model_info.id, [None, {}])
334    return oldname
335
336def _remove_pd(pars, key, name):
337    """
338    Remove polydispersity from the parameter list.
339
340    Note: operates in place
341    """
342    # Bumps style parameter names
343    width = pars.pop(key+".width", 0.0)
344    n_points = pars.pop(key+".npts", 0)
345    if width != 0.0 and n_points != 0:
346        warnings.warn("parameter %s not polydisperse in sasview %s"%(key, name))
347    pars.pop(key+".nsigmas", None)
348    pars.pop(key+".type", None)
349    return pars
350
351def _trim_vectors(model_info, pars, oldpars):
352    _, translation = CONVERSION_TABLE.get(model_info.id, [None, {}])
353    for p in model_info.parameters.kernel_parameters:
354        if p.length_control is not None:
355            n = int(pars[p.length_control])
356            oldname = translation.get(p.id, p.id)
357            for k in range(n+1, p.length+1):
358                for _, old in PD_DOT:
359                    oldpars.pop(oldname+str(k)+old, None)
360    return oldpars
361
362def revert_pars(model_info, pars):
363    """
364    Convert model from new style parameter names to old style.
365    """
366    if model_info.composition is not None:
367        composition_type, parts = model_info.composition
368        if composition_type == 'product':
369            translation = _get_translation_table(parts[0])
370            # structure factor models include scale:scale_factor mapping
371            translation.update(_get_translation_table(parts[1]))
372        else:
373            raise NotImplementedError("cannot convert to sasview sum")
374    else:
375        translation = _get_translation_table(model_info)
376    oldpars = _revert_pars(_rescale_sld(model_info, pars, 1e-6), translation)
377    oldpars = _trim_vectors(model_info, pars, oldpars)
378
379    # Make sure the control parameter is an integer
380    if "CONTROL" in oldpars:
381        oldpars["CONTROL"] = int(oldpars["CONTROL"])
382
383    # Note: update compare.constrain_pars to match
384    name = model_info.id
385    if name in MODELS_WITHOUT_SCALE or model_info.structure_factor:
386        if oldpars.pop('scale', 1.0) != 1.0:
387            warnings.warn("parameter scale not used in sasview %s"%name)
388    if name in MODELS_WITHOUT_BACKGROUND or model_info.structure_factor:
389        if oldpars.pop('background', 0.0) != 0.0:
390            warnings.warn("parameter background not used in sasview %s"%name)
391
392    # Remove magnetic parameters from non-magnetic sasview models
393    if name not in MAGNETIC_SASVIEW_MODELS:
394        oldpars = dict((k, v) for k, v in oldpars.items() if ':' not in k)
395
396    # If it is a product model P*S, then check the individual forms for special
397    # cases.  Note: despite the structure factor alone not having scale or
398    # background, the product model does, so this is below the test for
399    # models without scale or background.
400    namelist = name.split('*') if '*' in name else [name]
401    for name in namelist:
402        if name in MODELS_WITHOUT_VOLFRACTION:
403            del oldpars['volfraction']
404        elif name == 'core_multi_shell':
405            # kill extra shells
406            for k in range(5, 11):
407                oldpars.pop('sld_shell'+str(k), 0)
408                oldpars.pop('thick_shell'+str(k), 0)
409                oldpars.pop('mtheta:sld'+str(k), 0)
410                oldpars.pop('mphi:sld'+str(k), 0)
411                oldpars.pop('M0:sld'+str(k), 0)
412                _remove_pd(oldpars, 'sld_shell'+str(k), 'sld')
413                _remove_pd(oldpars, 'thick_shell'+str(k), 'thickness')
414        elif name == 'core_shell_parallelepiped':
415            _remove_pd(oldpars, 'rimA', name)
416            _remove_pd(oldpars, 'rimB', name)
417            _remove_pd(oldpars, 'rimC', name)
418        elif name == 'hollow_cylinder':
419            # now uses radius and thickness
420            thickness = oldpars['core_radius']
421            oldpars['radius'] += thickness
422            oldpars['radius.width'] *= thickness/oldpars['radius']
423        #elif name in ['mono_gauss_coil', 'poly_gauss_coil']:
424        #    del oldpars['i_zero']
425        elif name == 'onion':
426            oldpars.pop('n_shells', None)
427        elif name == 'pearl_necklace':
428            _remove_pd(oldpars, 'num_pearls', name)
429            _remove_pd(oldpars, 'thick_string', name)
430        elif name == 'polymer_micelle':
431            if 'ndensity' in oldpars:
432                oldpars['ndensity'] *= 1e15
433        elif name == 'rpa':
434            # convert scattering lengths from femtometers to centimeters
435            for p in "L1", "L2", "L3", "L4":
436                if p in oldpars: oldpars[p] *= 1e-13
437            if pars['case_num'] < 2:
438                for k in ("a", "b"):
439                    for p in ("L", "N", "Phi", "b", "v"):
440                        oldpars.pop(p+k, None)
441                for k in "Kab,Kac,Kad,Kbc,Kbd".split(','):
442                    oldpars.pop(k, None)
443            elif pars['case_num'] < 5:
444                for k in ("a",):
445                    for p in ("L", "N", "Phi", "b", "v"):
446                        oldpars.pop(p+k, None)
447                for k in "Kab,Kac,Kad".split(','):
448                    oldpars.pop(k, None)
449        elif name == 'spherical_sld':
450            oldpars["CONTROL"] -= 1
451            # remove polydispersity from shells
452            for k in range(1, 11):
453                _remove_pd(oldpars, 'thick_flat'+str(k), 'thickness')
454                _remove_pd(oldpars, 'thick_inter'+str(k), 'interface')
455            # remove extra shells
456            for k in range(int(pars['n_shells']), 11):
457                oldpars.pop('sld_flat'+str(k), 0)
458                oldpars.pop('thick_flat'+str(k), 0)
459                oldpars.pop('thick_inter'+str(k), 0)
460                oldpars.pop('func_inter'+str(k), 0)
461                oldpars.pop('nu_inter'+str(k), 0)
462        elif name == 'stacked_disks':
463            _remove_pd(oldpars, 'n_stacking', name)
464        elif name == 'teubner_strey':
465            # basically redoing the entire Teubner-Strey calculations here.
466            volfraction = oldpars.pop('volfraction_a')
467            xi = oldpars.pop('xi')
468            d = oldpars.pop('d')
469            sld_a = oldpars.pop('sld_a')
470            sld_b = oldpars.pop('sld_b')
471            drho = 1e6*(sld_a - sld_b)  # conversion autoscaled these
472            k = 2.0*math.pi*xi/d
473            a2 = (1.0 + k**2)**2
474            c1 = 2.0 * xi**2 * (1.0 - k**2)
475            c2 = xi**4
476            prefactor = 8.0*math.pi*volfraction*(1.0-volfraction)*drho**2*c2/xi
477            scale = 1e-4*prefactor
478            oldpars['scale'] = a2/scale
479            oldpars['c1'] = c1/scale
480            oldpars['c2'] = c2/scale
481
482    #print("convert from",list(sorted(pars)))
483    #print("convert to",list(sorted(oldpars.items())))
484    return oldpars
485
486def constrain_new_to_old(model_info, pars):
487    """
488    Restrict parameter values to those that will match sasview.
489    """
490    name = model_info.id
491    # Note: update convert.revert_model to match
492    if name in MODELS_WITHOUT_SCALE or model_info.structure_factor:
493        pars['scale'] = 1
494    if name in MODELS_WITHOUT_BACKGROUND or model_info.structure_factor:
495        pars['background'] = 0
496    # sasview multiplies background by structure factor
497    if '*' in name:
498        pars['background'] = 0
499
500    # Shut off magnetism when comparing non-magnetic sasview models
501    if name not in MAGNETIC_SASVIEW_MODELS:
502        suppress_magnetism = False
503        for key in pars.keys():
504            if key.startswith("M0:"):
505                suppress_magnetism = suppress_magnetism or (pars[key] != 0)
506                pars[key] = 0
507        if suppress_magnetism:
508            warnings.warn("suppressing magnetism for comparison with sasview")
509
510    # Shut off theta polydispersity since algorithm has changed
511    if 'theta_pd_n' in pars:
512        if pars['theta_pd_n'] != 0:
513            warnings.warn("suppressing theta polydispersity for comparison with sasview")
514        pars['theta_pd_n'] = 0
515
516    # If it is a product model P*S, then check the individual forms for special
517    # cases.  Note: despite the structure factor alone not having scale or
518    # background, the product model does, so this is below the test for
519    # models without scale or background.
520    namelist = name.split('*') if '*' in name else [name]
521    for name in namelist:
522        if name in MODELS_WITHOUT_VOLFRACTION:
523            pars['volfraction'] = 1
524        if name == 'core_multi_shell':
525            pars['n'] = min(math.ceil(pars['n']), 4)
526        elif name == 'gel_fit':
527            pars['scale'] = 1
528        elif name == 'line':
529            pars['scale'] = 1
530            pars['background'] = 0
531        elif name == 'mono_gauss_coil':
532            pars['scale'] = 1
533        elif name == 'onion':
534            pars['n_shells'] = math.ceil(pars['n_shells'])
535        elif name == 'pearl_necklace':
536            pars['string_thickness_pd_n'] = 0
537            pars['number_of_pearls_pd_n'] = 0
538        elif name == 'poly_gauss_coil':
539            pars['scale'] = 1
540        elif name == 'rpa':
541            pars['case_num'] = int(pars['case_num'])
542        elif name == 'spherical_sld':
543            pars['n_shells'] = math.ceil(pars['n_shells'])
544            pars['n_steps'] = math.ceil(pars['n_steps'])
545            for k in range(1, 11):
546                pars['shape%d'%k] = math.trunc(pars['shape%d'%k]+0.5)
547            for k in range(2, 11):
548                pars['thickness%d_pd_n'%k] = 0
549                pars['interface%d_pd_n'%k] = 0
550        elif name == 'teubner_strey':
551            pars['scale'] = 1
552            if pars['volfraction_a'] > 0.5:
553                pars['volfraction_a'] = 1.0 - pars['volfraction_a']
554        elif name == 'unified_power_Rg':
555            pars['level'] = int(pars['level'])
556
557def _check_one(name, seed=None):
558    """
559    Generate a random set of parameters for *name*, and check that they can
560    be converted back to SasView 3.x and forward again to sasmodels.  Raises
561    an error if the parameters are changed.
562    """
563    from . import compare
564
565    model_info = load_model_info(name)
566
567    old_name = revert_name(model_info)
568    if old_name is None:
569        return
570
571    pars = compare.get_pars(model_info, use_demo=False)
572    pars = compare.randomize_pars(model_info, pars, seed=seed)
573    if name == "teubner_strey":
574        # T-S model is underconstrained, so fix the assumptions.
575        pars['sld_a'], pars['sld_b'] = 1.0, 0.0
576    compare.constrain_pars(model_info, pars)
577    constrain_new_to_old(model_info, pars)
578    old_pars = revert_pars(model_info, pars)
579    new_name, new_pars = convert_model(old_name, old_pars, use_underscore=True)
580    if 1:
581        print("==== %s in ====="%name)
582        print(str(compare.parlist(model_info, pars, True)))
583        print("==== %s ====="%old_name)
584        for k, v in sorted(old_pars.items()):
585            print(k, v)
586        print("==== %s out ====="%new_name)
587        print(str(compare.parlist(model_info, new_pars, True)))
588    assert name==new_name, "%r != %r"%(name, new_name)
589    for k, v in new_pars.items():
590        assert k in pars, "%s: %r appeared from conversion"%(name, k)
591        if isinstance(v, float):
592            assert abs(v-pars[k])<=abs(1e-12*v), "%s: %r  %s != %s"%(name, k, v, pars[k])
593        else:
594            assert v == pars[k], "%s: %r  %s != %s"%(name, k, v, pars[k])
595    for k, v in pars.items():
596        assert k in pars, "%s: %r not converted"%(name, k)
597
598def test_backward_forward():
599    from .core import list_models
600    for name in list_models('all'):
601        L = lambda: _check_one(name, seed=1)
602        L.description = name
603        yield L
Note: See TracBrowser for help on using the repository browser.