Closed neerajprad closed 4 years ago
So that this is always available, could we wrap this around the function immediately after we exec the generated code? If there's a reason why doing so isn't a good idea, perhaps we can still put it there, but do it conditionally?
This is done by default now, but if we see any issues with it, we can turn it on conditionally. I don't think it should have side-effects, but will keep an eye out.
It seems like this will be super useful, thanks @neerajprad.
Fixes #38 in a more general way.
This is used to augment information in the stack trace when the generated model throws any exception. A
traceback_generated
context-manager is provided, which can be used as follows:If the error originates from running the model code, this will augment the stack trace with the model code highlighting the line that throws the error, otherwise this will have no effect. I have only used this in one part of the code that was throwing an exception with Pyro's dev branch, but we can use this more widely if it turns out to be useful. Turns out the AssertionError was due to these lines which I recently fixed in dev 😆, so this wasn't anything alarming:
The end of the exception message shows the difference.
stack trace (before)
``` sample: 100%|██████████| 1/1 [00:00, 34.47it/s, step size=1.25e-01, acc. prob=1.000] tests/test_brm.py:415 (test_parameter_shapes[fitargs0-y ~ 1 + x-non_real_cols0-contrasts0-family0-priors0-expected0]) formula_str = 'y ~ 1 + x', non_real_cols = [], contrasts = {}, family = Normal() priors = [], expected = [('b_0', 'Cauchy', {}), ('sigma', 'HalfCauchy', {})] fitargs = {'backend': Backend(name='Pyro', gen=stack trace (after)
``` sample: 100%|██████████| 1/1 [00:00, 34.71it/s, step size=1.25e-01, acc. prob=1.000] tests/test_brm.py:415 (test_parameter_shapes[fitargs0-y ~ 1 + x-non_real_cols0-contrasts0-family0-priors0-expected0]) AssertionError The above exception was the direct cause of the following exception: formula_str = 'y ~ 1 + x', non_real_cols = [], contrasts = {}, family = Normal() priors = [], expected = [('b_0', 'Cauchy', {}), ('sigma', 'HalfCauchy', {})] fitargs = {'backend': Backend(name='Pyro', gen=