]> gitweb.michael.orlitzky.com - dunshire.git/blobdiff - dunshire/games.py
Add a PoorScalingException for the "math domain errors" that haunt me.
[dunshire.git] / dunshire / games.py
index 80f5f8ae2a46d09f15e34546c511edeca286f4fa..9610802e4ffd4108d2c244b2c36a9e44084427cd 100644 (file)
@@ -7,7 +7,7 @@ knows how to solve a linear game.
 
 from cvxopt import matrix, printing, solvers
 from .cones import CartesianProduct
-from .errors import GameUnsolvableException
+from .errors import GameUnsolvableException, PoorScalingException
 from .matrices import append_col, append_row, identity
 from . import options
 
@@ -351,6 +351,10 @@ class SymmetricLinearGame:
             If the game could not be solved (if an optimal solution to its
             associated cone program was not found).
 
+        PoorScalingException
+            If the game could not be solved because CVXOPT crashed while
+            trying to take the square root of a negative number.
+
         Examples
         --------
 
@@ -425,7 +429,16 @@ class SymmetricLinearGame:
 
         # Actually solve the thing and obtain a dictionary describing
         # what happened.
-        soln_dict = solvers.conelp(c, G, h, C.cvxopt_dims(), A, b)
+        try:
+            soln_dict = solvers.conelp(c, G, h, C.cvxopt_dims(), A, b)
+        except ValueError as e:
+            if str(e) == 'math domain error':
+                # Oops, CVXOPT tried to take the square root of a
+                # negative number. Report some details about the game
+                # rather than just the underlying CVXOPT crash.
+                raise PoorScalingException(self)
+            else:
+                raise e
 
         # The optimal strategies are named ``p`` and ``q`` in the
         # background documentation, and we need to extract them from