Skip to content

Commit 86fda9f

Browse files
Add tutorial for creating publication-ready images with draw_tree (#765)
* update pyproject.toml with optional dependencies for test suite and docs * update GitHub actions to install optional dependencies when installing pygambit instead of using requirements.txt * add doc dependencies: Cython, numpy, scipy * try GH actions without testing docs * Revert "try GH actions without testing docs" This reverts commit 4d54262. * remove pip install that is already covered by build-system in pyproject.toml * fix typo mistake in doc dependencies list * remove Cython, numpy and scipy from doc dependency list as these are already included in build-system or dependencies * restore installation of build on linux job * remove requirements.txt files * update docs for new installation method * update documentation instructions * update readthedocs config * try fixing linux build * try again to fix linux job: let bash expand the filename first, then append extras * Create catalog dir and move one EFG and one NFG into it from contrib/games * ignore catalog files copied into pygambit * add failing tests * improve tests * add pandas to pyproject.toml * add test_catalog_load_invalid_slug * create load function * add catalog to __init__ * add games() function * refactor to define READERS once * Big refactor to get catalog files from catalog dir external to pygambit * update Makefile.am for the 2 examples we moved into the catalog so far * update Game.comment to be Game.description in Python code * Revert "update Game.comment to be Game.description in Python code" This reverts commit 7490ae6. * Add initial update catalog script and RST page * rename table headers on output df from game() func * add generating the catalog csv for docs into GH actions * Revert "add generating the catalog csv for docs into GH actions" This reverts commit bd3c1f3. * refactor update script so its run from repo root * update readthedocs to build the catalog csv before docs build * add function which updates Makefile.am * use a proper path for CATALOG_CSV * tidy update script * use explicit python executable from the virtualenv to create CSV for catalog docs table in readthedocs yml * add developer doc for updating the catalog * Don't update Makefile.am by default * consistency in notebook comment * demo loading from catalog in tutorial 1 * load from catalog for game examples in advanced tutorials * Try using pip instead of setuptools to ensure pyproject.toml deps installed for readthedocs build * remove deleted contrib games from Makefile.am * add a warning about moving games from contrib * check if pandas duplications error exists if we dont save outputs on notebooks * fix problem with print function * resave notebook outputs * Update writer.cc * move catalog update script into build support * rename script * rename var * update path to catalog update script in readthedocs yml and docs page * move myserson fig into subfolder * clarify script usage * add test_catalog_load_subdir_slug * update makefile * update agent nb * add test for slug in subdir of catalog * update games func to list slugs correctly * update test to avoid duplicates * fix code for handling slugs that duplicates of those in subfolders * tidy the games() refactor * resave notebook * strip nb outputs * remove modification to games() that was fixing a local issue * fix the update script to get correct paths * remove unused var * Add Windows handling * fix incorrect var name and make consistent * use as_posix for slugs * add new notebook * upgrade draw_tree version to 0.4.0 * 2smp game looks good * add sections on saving images and further adjustments * update headers * update header further * add comment * clear saved outputs from all tutorials * typo * tidy read and save sections * renumber and reorder tutorials * update image to use sublevel_scaling * clear outputs * revert makefile changes * move games back to contrib * Move 2smp back again since it's used by tutorial 4 * tidy saving sections of tutorials 1 and 2 --------- Co-authored-by: Ted Turocy <ted.turocy@gmail.com>
1 parent ff22925 commit 86fda9f

10 files changed

Lines changed: 618 additions & 4223 deletions

File tree

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ EXTRA_DIST = \
101101
src/gui/bitmaps/zoom1.xpm \
102102
src/gui/bitmaps/gambitrc.rc \
103103
contrib/games/2s2x2x2.efg \
104-
contrib/games/2smp.efg \
105104
contrib/games/2x2x2.efg \
106105
contrib/games/4cards.efg \
107106
contrib/games/artist1.efg \
@@ -236,6 +235,7 @@ EXTRA_DIST = \
236235
contrib/games/yamamoto.nfg \
237236
contrib/games/zero.nfg \
238237
src/README.rst \
238+
catalog/2smp.efg \
239239
catalog/myerson1991/fig4_2.efg \
240240
catalog/selten1975/fig1.efg \
241241
catalog/selten1975/fig2.efg \
File renamed without changes.

doc/pygambit.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ See installation instructions in the :ref:`install` section.
88

99

1010
For newcomers to Gambit, we recommend reading through the PyGambit tutorials, which demonstrate the API's key capabilities for analyzing and solving games.
11-
These tutorials are available to be run interactively as Jupyter notebooks, see :ref:`local_tutorials`.
12-
All of the tutorials assume a basic knowledge of programming in Python.
11+
All of these tutorials assume a basic knowledge of programming in Python.
12+
13+
You can run the tutorials interactively as Jupyter notebooks, see :ref:`local_tutorials`.
1314

1415
New user tutorials
1516
------------------
@@ -20,10 +21,10 @@ They are numbered in the order they should be read.
2021
.. toctree::
2122
:maxdepth: 2
2223

23-
tutorials/running_locally
2424
tutorials/01_quickstart
2525
tutorials/02_extensive_form
2626
tutorials/03_stripped_down_poker
27+
tutorials/04_creating_images
2728

2829
Advanced user tutorials
2930
-----------------------

doc/tutorials/01_quickstart.ipynb

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@
311311
},
312312
{
313313
"cell_type": "markdown",
314-
"id": "24f36b0d",
314+
"id": "3dfbf327",
315315
"metadata": {},
316316
"source": [
317317
"Saving and reading strategic form games to and from file\n",
@@ -320,35 +320,18 @@
320320
"You can use Gambit to save games to, and read from files.\n",
321321
"The specific format depends on whether the game is normal or extensive-form.\n",
322322
"\n",
323-
"Here we'll save the Prisoner's Dilemma (Normal-form) to the `.nfg` format."
324-
]
325-
},
326-
{
327-
"cell_type": "code",
328-
"execution_count": null,
329-
"id": "f58eaa77",
330-
"metadata": {},
331-
"outputs": [],
332-
"source": [
333-
"# g.to_nfg(\"prisoners_dilemma.nfg\")"
334-
]
335-
},
336-
{
337-
"cell_type": "markdown",
338-
"id": "e373be1e",
339-
"metadata": {},
340-
"source": [
341-
"You can easily restore the game object from file like so:"
342-
]
343-
},
344-
{
345-
"cell_type": "code",
346-
"execution_count": null,
347-
"id": "4119a2ac",
348-
"metadata": {},
349-
"outputs": [],
350-
"source": [
351-
"# gbt.read_nfg(\"prisoners_dilemma.nfg\")"
323+
"Here we'll save the Prisoner's Dilemma (Normal-form) to the `.nfg` format.\n",
324+
"Run these lines of code in new code cells if you're running the tutorial locally:\n",
325+
"\n",
326+
"```python\n",
327+
"g.to_nfg(\"prisoners_dilemma.nfg\")\n",
328+
"```\n",
329+
"\n",
330+
"You can easily restore the game object from file like so:\n",
331+
"\n",
332+
"```python\n",
333+
"gbt.read_nfg(\"prisoners_dilemma.nfg\")\n",
334+
"```"
352335
]
353336
}
354337
],

doc/tutorials/02_extensive_form.ipynb

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -314,67 +314,17 @@
314314
"The specific format depends on whether the game is normal or extensive-form.\n",
315315
"\n",
316316
"Here we'll save the Trust game (extensive-form) to the `.efg` format.\n",
317-
"Uncomment these lines of code if you're running the tutorial locally:"
318-
]
319-
},
320-
{
321-
"cell_type": "code",
322-
"execution_count": null,
323-
"id": "37c51152",
324-
"metadata": {},
325-
"outputs": [],
326-
"source": [
327-
"# g.to_efg(\"trust_game.efg\")"
328-
]
329-
},
330-
{
331-
"cell_type": "markdown",
332-
"id": "0eb31525",
333-
"metadata": {},
334-
"source": [
335-
"You can easily restore the game object from file like so:"
336-
]
337-
},
338-
{
339-
"cell_type": "code",
340-
"execution_count": null,
341-
"id": "0d86a750",
342-
"metadata": {},
343-
"outputs": [],
344-
"source": [
345-
"# gbt.read_efg(\"trust_game.efg\")"
346-
]
347-
},
348-
{
349-
"cell_type": "markdown",
350-
"id": "182f2424-274e-4044-84ff-3323cd70ec68",
351-
"metadata": {},
352-
"source": [
353-
"You can also use the `draw_tree` package to save the game in the `.ef` format which encodes layout information.\n",
354-
"This can in turn be used to render the image for use in publications, for example as a `.png` (there are also `.pdf` and `.tex` options, see [draw_tree](https://github.com/gambitproject/draw_tree)):"
355-
]
356-
},
357-
{
358-
"cell_type": "code",
359-
"execution_count": null,
360-
"id": "1bab777f-8a0b-4f1e-9c0c-270690288243",
361-
"metadata": {},
362-
"outputs": [],
363-
"source": [
364-
"# from draw_tree import generate_png\n",
365-
"# draw_tree(g, save_to=\"trust_game.ef\")\n",
366-
"# trust_game_png = generate_png(\"trust_game.ef\")"
367-
]
368-
},
369-
{
370-
"cell_type": "code",
371-
"execution_count": null,
372-
"id": "2b715221-e427-4092-ad2f-9f4f2b548fa4",
373-
"metadata": {},
374-
"outputs": [],
375-
"source": [
376-
"# from IPython.display import Image\n",
377-
"# Image(trust_game_png)"
317+
"Run these lines of code in new code cells if you're running the tutorial locally:\n",
318+
"\n",
319+
"```python\n",
320+
"g.to_efg(\"trust_game.efg\")\n",
321+
"```\n",
322+
"\n",
323+
"You can easily restore the game object from file like so:\n",
324+
"\n",
325+
"```python\n",
326+
"gbt.read_efg(\"trust_game.efg\")\n",
327+
"```"
378328
]
379329
},
380330
{

0 commit comments

Comments
 (0)