Skip to content

bimatrix.runLH / runtrace never detect runlemke failure (result is None check is dead since LcpResult) #23

Closed

Description

@rahulsavani

Problem

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)
if result is None:
    raise RuntimeError("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

  1. In runLH and runtrace, replace if result is None: with if not result.success:.
  2. 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, ...).
  3. 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

  1. rahulsavani commented on Oct 20, 2026

    @rahulsavani
    MemberAuthor

    Fixed via PR #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions