From: Michael Orlitzky Date: Thu, 6 Oct 2016 18:18:29 +0000 (-0400) Subject: Fix dict sorting in and add another big example to errors.py. X-Git-Tag: 0.1.0~199 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=e5b29b4c2e4dabb438d77f7f623c8b098353f5b0;p=dunshire.git Fix dict sorting in and add another big example to errors.py. --- diff --git a/src/dunshire/errors.py b/src/dunshire/errors.py index 3a5b601..322479f 100644 --- a/src/dunshire/errors.py +++ b/src/dunshire/errors.py @@ -10,6 +10,8 @@ def _pretty_format_dict(dictionary): Return a pretty-formatted string representation of a dictionary containing CVXOPT matrices. + The dictionary is also sorted so that it can be tested repeatably. + EXAMPLES: >>> d = {'foo': 1.234, 'bar': matrix([1,2,3])} @@ -22,7 +24,7 @@ def _pretty_format_dict(dictionary): """ result = '' - for (key, value) in dictionary.items(): + for (key, value) in sorted(dictionary.items()): if isinstance(value, matrix): # Display matrices on their own lines, indented. result += '{:s}:'.format(key) @@ -41,6 +43,50 @@ class GameUnsolvableException(Exception): 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. + + EXAMPLES: + + >>> d = {'residual as dual infeasibility certificate': None, + ... 'y': matrix([1,1]), + ... 'dual slack': 8.779496368228267e-10, + ... 'z': matrix([1,1,0,0]), + ... 's': None, + ... 'primal infeasibility': None, + ... 'status': 'primal infeasible', + ... 'dual infeasibility': None, + ... 'relative gap': None, + ... 'iterations': 5, + ... 'primal slack': None, + ... 'x': None, + ... 'dual objective': 1.0, + ... 'primal objective': None, + ... 'gap': None, + ... 'residual as primal infeasibility certificate': 3.986246886102996e-09} + >>> print(GameUnsolvableException(d)) + Solution failed with result "primal infeasible." + CVXOPT returned: + dual infeasibility: None + dual objective: 1.0 + dual slack: 8.779496368228267e-10 + gap: None + iterations: 5 + primal infeasibility: None + primal objective: None + primal slack: None + relative gap: None + residual as dual infeasibility certificate: None + residual as primal infeasibility certificate: 3.986246886102996e-09 + s: None + status: primal infeasible + x: None + y: + [ 1] + [ 1] + z: + [ 1] + [ 1] + [ 0] + [ 0] """ def __init__(self, solution_dict): """