Skip to content

Add tutorial: Sagemath interoperability - #1070

Open
ameliekleber wants to merge 3 commits into
gambitproject:masterfrom
ameliekleber:sagemath-interoperability-tutorials
Open

Add tutorial: Sagemath interoperability#1070
ameliekleber wants to merge 3 commits into
gambitproject:masterfrom
ameliekleber:sagemath-interoperability-tutorials

Conversation

@ameliekleber

Copy link
Copy Markdown
Contributor

Issues closed by this PR

Add any issues that are being closed by this PR to the list. Use "Closes" or another keyword followed by the issue number.

Description of the changes in this PR

Adds two tutorials covering the SageMath ↔ Gambit interface introduced in
sagemath/sage#42367, under doc/tutorials/interoperability_tutorials/.

sagemath_normal_form.ipynb — strategic form games

Round-trips a game between the two libraries (NormalFormGame(game) and
game._gambit_()). Then walks the interface: .nfg save/load, reaching Gambit's game
catalog from Sage, obtain_nash across both Sage's exact solvers and Gambit's,
degeneracy checking, games with more than two players via NumPy arrays, and plotting the
payoff bimatrix.

Closes with two case studies that need both libraries:

  • Hawk–Dove with symbolic payoffs. Sage solves the indifference condition in closed
    form (p* = v/c, valid for all v and c), then substitutes numbers and checks the
    result against Gambit's enummixed.
  • Max cut as a game. A Sage graph becomes a five-player game; Gambit enumerates the
    pure equilibria, and Sage computes the true maximum cut to certify which of them are
    globally optimal and which are only locally stable.

sagemath_extensive_form.ipynb — extensive form games

Builds trees with append_move / append_infoset / append_chance_move, contrasting
sequential and simultaneous Battle of the Sexes to show how the information structure
changes the equilibria. Covers a small poker game whose equilibrium involves bluffing,
.efg save/load, wrapping an existing pygambit tree,
Selten's horse from the catalog, and both plotting backends with Sage graphics and gtdraw's
TikZ output.

Closes with the absent-minded driver: perfect recall fails, so no Gambit solver applies.
Gambit evaluates individual plans instead, and Sage interpolates the exact value
polynomial over QQ and optimises it with calculus.

Supporting changes

  • doc/pygambit.rst: registers both notebooks in the interoperability toctree.
  • Both notebooks are committed with outputs and set "nbsphinx": {"execute": "never"},
    since the Read the Docs build has no SageMath.
  • tests/test_tutorials.py: notebooks declaring a kernel that isn't installed are now
    skipped rather than failed, and a new test_prerendered_notebooks_keep_outputs catches
    a pre-rendered notebook whose outputs get stripped (which would otherwise render as
    bare code in the docs, easy to miss in review).
  • pyproject.toml: per-file ruff ignore for F821 on the Sage notebooks, since the Sage
    kernel injects its globals (NormalFormGame, matrix, QQ, ...) into every cell.

Running the notebooks needs a SageMath build containing sagemath/sage#42367, the optional
pygambit package, and the SageMath kernel. The gtdraw section additionally needs
gtdraw plus pdflatex and pdftocairo; it skips the rendering with a message if those
aren't on the kernel's PATH.

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant