You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bimatrix.runLH / runtrace never detect runlemke failure (result is None check is dead since LcpResult) #23
Since #18 introduced LcpResult, lemke.runlemke always returns an LcpResult and never returns None: on secondary-ray termination it returns a result with success=False (lemke.py#L601-L609).
But bimatrix.runLH and bimatrix.runtrace still check for the old failure value:
result=lemke.runlemke(lcp=lcp)
ifresultisNone:
raiseRuntimeError("runlemke() failed to find a solution unexpectedly.")
So this RuntimeError can never be raised. If Lemke's algorithm ever fails, both methods silently return result.z[:-2] taken from a basis that is not an equilibrium, instead of reporting the failure. The docstrings added in #19 already document the RuntimeError, so the code should be brought in line with them.
Suggested fix
In runLH and runtrace, replace if result is None: with if not result.success:.
Add a unit test in tests/test_bimatrix_units.py for each method that makes runlemke return an unsuccessful LcpResult and checks that RuntimeError is raised. Ray termination shouldn't happen for well-formed bimatrix games, so the easiest way is to monkeypatch lemke.runlemke (pytest's monkeypatch fixture) to return e.g. LcpResult(success=False, ...).
Run pytest, ruff check and flake8 locally before pushing.
Best done on a fresh branch off main after #19 is merged, since #19 edits the docstrings right above these lines.
Activity
rahulsavani commentedon Oct 20, 2026
Fixed via PR #27