Add tutorial: Sagemath interoperability - #1070
Open
ameliekleber wants to merge 3 commits into
Open
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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.
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 gamesRound-trips a game between the two libraries (
NormalFormGame(game)andgame._gambit_()). Then walks the interface:.nfgsave/load, reaching Gambit's gamecatalog from Sage,
obtain_nashacross 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:
form (
p* = v/c, valid for allvandc), then substitutes numbers and checks theresult against Gambit's
enummixed.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 gamesBuilds trees with
append_move/append_infoset/append_chance_move, contrastingsequential and simultaneous Battle of the Sexes to show how the information structure
changes the equilibria. Covers a small poker game whose equilibrium involves bluffing,
.efgsave/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
QQand optimises it with calculus.Supporting changes
doc/pygambit.rst: registers both notebooks in the interoperability toctree."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 nowskipped rather than failed, and a new
test_prerendered_notebooks_keep_outputscatchesa 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 forF821on the Sage notebooks, since the Sagekernel injects its globals (
NormalFormGame,matrix,QQ, ...) into every cell.Running the notebooks needs a SageMath build containing sagemath/sage#42367, the optional
pygambitpackage, and the SageMath kernel. The gtdraw section additionally needsgtdrawpluspdflatexandpdftocairo; it skips the rendering with a message if thosearen't on the kernel's
PATH.