Skip to content

Make lal errors more user friendly

James Kennington requested to merge feature-error-classifier into main


Errors raised by lal c libs were less-than-illuminating in many cases and often not handled explicitly. For example, the following was common:

except RuntimeError as e:

Error Classification

This adds a new context manager capable of capturing and reclassifying errors specifically. A simple example mirroring the above would be:

from manifold.utilities import error

    with error.classify():
except error.LalSimInputDomainError:
except error.LalSimError:

Classification Rules

The errors are classified using a sequence of rules, each of which defines whether or not it "applies" to a given exception, e.g.:

e = Exception(...)

class MyRule(error.ClassificationRule):
    def applies_to_exception(e):

One of the more common cases is using regex to match error messages, which is defined using a error.RegexClassificationRule

Capturing StdErr from c Library

The Classifier object makes use of the library wurlitzer to capture c-level stdout and stderr from lalsuite. This information is logged if present before the newly classified error is raised, but may also be accessed afterwards (assuming the error is caught), for example:

    with error.classify(rules=[error.LAL_RULE_SIM_INPUT_DOMAIN]) as c:
        _ = lalsim.SimInspiralFD(**parameters)
except error.LalSimInputDomainError:
    # Do something with the stderr from c
Edited by James Kennington

Merge request reports