1. Georg Brandl
  2. ufit

Commits

Georg Brandl  committed 783456a

models: better error message on unresolved parameter dependencies

  • Participants
  • Parent commits a88fb51
  • Branches default

Comments (0)

Files changed (2)

File ufit/models/base.py

View file
  • Ignore whitespace
 from numpy import concatenate
 
 from ufit import param, backends, UFitError, Param, Dataset, Result
-from ufit.utils import get_chisqr
+from ufit.utils import get_chisqr, cached_property
 from ufit.plotting import DataPlotter
 
 __all__ = ['Model', 'CombinedModel', 'Function', 'eval_model']
                 seen.add(p.name)
                 self.params.append(p)
 
+    @cached_property
+    def paramdict(self):
+        return dict((p.name, p) for p in self.params)
+
+    def __getitem__(self, key):
+        return self.paramdict[key]
+
     def __add__(self, other):
         if isinstance(other, (int, long, float)):
             other = Constant(other)

File ufit/param.py

View file
  • Ignore whitespace
     varynames = []
     for p in params:
         if p.expr:
-            dependent[p.name] = p.expr
+            dependent[p.name] = [p.expr, None]
         else:
             varying.append(p)
             varynames.append(p.name)
     while dependent:
         maxit -= 1
         if maxit == 0:
-            raise UFitError('detected unresolved parameter dependencies '
-                            'among %s' % dependent.keys())
-        for p, expr in dependent.items():  # dictionary will change
+            s = '\n'.join('   %s: %s' % (k, v[1]) for (k, v)
+                          in dependent.iteritems())
+            raise UFitError('detected unresolved parameter dependencies:\n' + s)
+        for p, (expr, _) in dependent.items():  # dictionary will change
             try:
                 pd[p] = param_eval(expr, pd)
-            except (NameError, AttributeError):
-                pass
+            except NameError, e:
+                dependent[p][1] = str(e)
+            except AttributeError, e:
+                dependent[p][1] = 'depends on data.' + str(e)
             else:
                 del dependent[p]
                 dep_order.append((p, expr))