X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fdunshire%2Ferrors.py;h=020186475b2a920f8425ffe0be76b3a27625de85;hb=769e1c7d09936a617f33d1496782fbbd4299851d;hp=322479f0d39320ede35977969d7e95577bdce79e;hpb=e5b29b4c2e4dabb438d77f7f623c8b098353f5b0;p=dunshire.git diff --git a/src/dunshire/errors.py b/src/dunshire/errors.py index 322479f..0201864 100644 --- a/src/dunshire/errors.py +++ b/src/dunshire/errors.py @@ -12,7 +12,8 @@ def _pretty_format_dict(dictionary): The dictionary is also sorted so that it can be tested repeatably. - EXAMPLES: + Examples + -------- >>> d = {'foo': 1.234, 'bar': matrix([1,2,3])} >>> print(_pretty_format_dict(d)) @@ -39,12 +40,20 @@ def _pretty_format_dict(dictionary): class GameUnsolvableException(Exception): """ - Every linear game has a solution (this follows from a general - min-max theorem). If we can't solve the conic program associated - with a linear game, then something is wrong with either the model of - the input. + An exception raised when a game cannot be solved. - EXAMPLES: + Every linear game has a solution. If we can't solve the conic + program associated with a linear game, then something is wrong with + either the model or the input, and this exception should be raised. + + Parameters + ---------- + + solution_dict : dict + The solution dictionary returned from the failed cone program. + + Examples + -------- >>> d = {'residual as dual infeasibility certificate': None, ... 'y': matrix([1,1]), @@ -61,7 +70,8 @@ class GameUnsolvableException(Exception): ... 'dual objective': 1.0, ... 'primal objective': None, ... 'gap': None, - ... 'residual as primal infeasibility certificate': 3.986246886102996e-09} + ... 'residual as primal infeasibility certificate': + ... 3.986246886102996e-09} >>> print(GameUnsolvableException(d)) Solution failed with result "primal infeasible." CVXOPT returned: @@ -91,12 +101,6 @@ class GameUnsolvableException(Exception): def __init__(self, solution_dict): """ Create a new GameUnsolvableException object. - - INPUT: - - - ``solution_dict`` -- the solution dictionary returned from the - cone program. - """ super().__init__() self._solution_dict = solution_dict @@ -114,5 +118,8 @@ class GameUnsolvableException(Exception): tpl = 'Solution failed with result "{:s}."\n' \ 'CVXOPT returned:\n {!s}' cvx_lines = _pretty_format_dict(self._solution_dict).splitlines() - cvx_str = '\n '.join(cvx_lines) # Indent the whole dict by two spaces. + + # Indent the whole dict by two spaces. + cvx_str = '\n '.join(cvx_lines) + return tpl.format(self._solution_dict['status'], cvx_str)