Use Click to parse command-line arguments in bimatrix.py - #16
Merged
rahulsavani merged 10 commits intoJul 30, 2026
Conversation
rahulsavani
self-requested a review
July 24, 2026 04:52
nataliemes
force-pushed
the
refactor/click-cli-bimatrix
branch
from
July 24, 2026 06:03
b72f0ba to
50cf568
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors bimatrix.py’s command-line interface to use Click, aligning it with the project’s other CLIs and improving argument validation and subcommand structure.
Changes:
- Replaces manual
sys.argvparsing with a Click-based CLI entry point (bimatrix), including-hhelp alias and POSIX-style options. - Splits the CLI into
lhandtracesubcommands with shared “common options” and per-subcommand options. - Updates library entry points to accept explicit parameters (e.g.,
tracing(trace, seed=None, accuracy=1000)) and raises on invalid negative priors.
Comments suppressed due to low confidence (1)
src/lemke/bimatrix.py:173
LH("")currently results in an empty label list (becauserangesplit("")returns[]), so the method silently finds no equilibria. Since the CLI default uses "1-" to mean “all labels”, it’s safer to treat an empty string the same way (or raise a clear error).
def LH(self, LHstring):
m = self.A.numrows
n = self.A.numcolumns
lhset = {} # dict of equilibria and list by which label found
labels = rangesplit(LHstring, m + n)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+275
to
+279
| @click.group( | ||
| context_settings={"help_option_names": ["-?", "-h", "--help"]}, | ||
| ) | ||
| def main(): | ||
| processArguments() | ||
| printglobals() | ||
|
|
||
| G = bimatrix(gamefilename) | ||
| print(G) | ||
| G.LH(LHstring) | ||
| G.tracing(trace) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| """Find Nash equilibria of a bimatrix game.""" |
Member
|
@nataliemes Could you resolve the merge conflicts please. |
# Conflicts: # src/lemke/bimatrix.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes similar to
lemke.pymain()accepts arguments (populated by Click), which are then passed to solvers.-hwas added as a help option name.Other changes
Library usage:
When using
LH()as a library function, it is now mandatory to specify the labels string (it used to be empty by default).tracing()was replaced with 2 methods:trace_uniform_prior()with no arguments, andtrace_random_priors(trace, seed=None, accuracy=1000)(wheretraceis the number of random priors).game.tracing(trace=0)game.trace_uniform_prior()game.tracing(trace=0, seed=1)game.tracing(trace=20)game.trace_random_priors(trace=20)game.tracing(trace=20, seed=1)game.trace_random_priors(trace=20, seed=1)Instead of just returning when negative number of priors is passed to
tracing(),trace_random_priors()raises a ValueError.To indicate that a random seed shouldn't be used in
trace_random_priors(), seed is set toNone(instead of a negative number like before). Negative seed values are now accepted.CLI usage:
--decimalsand--accuracynow have range checks.bimatrixcommand is split into 2 subcommands:lhandtrace.tracealso has 2 subcommands:uniform(uses a uniform prior) andrandom(uses random priors, by default 1).bimatrix(default file name was used)bimatrix game_file(lh and tracing didn't run)bimatrix game_file -LH(uses all labels)bimatrix lh game_filebimatrix game_file -LH 1-2(labels 1, 2)bimatrix lh game_file --labels 1-2bimatrix game_file -LH -seed 1bimatrix game_file -tracebimatrix trace uniform game_filebimatrix game_file -trace -seed 1bimatrix game_file -trace 1bimatrix trace random game_file, orbimatrix trace random game_file --priors 1bimatrix game_file -trace 10 -seed 1bimatrix trace random game_file --priors 10 --seed 1bimatrix game_file -LH -traceTests:
bimatrix.py.