Skip to content

Commit a9e3cbf

Browse files
refactor: rename drawing package from draw_tree to gtdraw and update tutorials accordingly
1 parent 5fa7fb0 commit a9e3cbf

10 files changed

Lines changed: 122 additions & 393 deletions

File tree

File renamed without changes.

build_support/catalog/test_update.py

Lines changed: 62 additions & 62 deletions
Large diffs are not rendered by default.

build_support/catalog/update.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55

66
import pandas as pd
77
import yaml
8-
from draw_tree import generate_pdf, generate_png, generate_svg, generate_tex
8+
from gtdraw import pdf, png, svg, tex
99

1010
import pygambit as gbt
1111

1212
CATALOG_RST_TABLE = Path(__file__).parent.parent.parent / "doc" / "catalog_table.rst"
1313
CATALOG_DIR = Path(__file__).parent.parent.parent / "catalog"
1414
MAKEFILE_AM = Path(__file__).parent.parent.parent / "Makefile.am"
15-
DRAW_TREE_SETTINGS_CONFIG = Path(__file__).parent / "draw_tree_settings.yaml"
15+
GTDRAW_SETTINGS_CONFIG = Path(__file__).parent / "gtdraw_settings.yaml"
1616
CATALOG_HIERARCHY_CONFIG = Path(__file__).parent / "catalog_hierarchy.yaml"
1717
SUPPORTED_GAME_FORMATS = {"efg", "nfg"}
1818

1919

20-
def catalog_draw_tree_settings(slug: str) -> dict:
21-
"""Return the draw_tree settings for a given catalog slug."""
22-
with open(DRAW_TREE_SETTINGS_CONFIG, encoding="utf-8") as f:
20+
def catalog_gtdraw_settings(slug: str) -> dict:
21+
"""Return the gtdraw settings for a given catalog slug."""
22+
with open(GTDRAW_SETTINGS_CONFIG, encoding="utf-8") as f:
2323
config = yaml.safe_load(f)
2424
settings = dict(config["defaults"])
2525
overrides = config.get("overrides", {})
@@ -166,8 +166,8 @@ def _write_game_entry(
166166
if variant["ef_path"].exists()
167167
else gbt.catalog.load(slug)
168168
)
169-
for func in [generate_tex, generate_png, generate_pdf, generate_svg]:
170-
func(source, save_to=str(viz_path), **catalog_draw_tree_settings(vkey))
169+
for func in [tex, png, pdf, svg]:
170+
func(source, save_to=str(viz_path), **catalog_gtdraw_settings(vkey))
171171
img_ef = catalog_dir / "img" / f"{vkey}.ef"
172172
if not img_ef.exists() and variant["ef_path"].exists():
173173
shutil.copy2(variant["ef_path"], img_ef)
@@ -185,8 +185,8 @@ def _write_game_entry(
185185
viz_path.parent.mkdir(parents=True, exist_ok=True)
186186
curated_ef = catalog_dir / f"{slug}.ef"
187187
source = str(curated_ef) if curated_ef.exists() else gbt.catalog.load(slug)
188-
for func in [generate_tex, generate_png, generate_pdf, generate_svg]:
189-
func(source, save_to=str(viz_path), **catalog_draw_tree_settings(slug))
188+
for func in [tex, png, pdf, svg]:
189+
func(source, save_to=str(viz_path), **catalog_gtdraw_settings(slug))
190190
img_ef = catalog_dir / "img" / f"{slug}.ef"
191191
if not img_ef.exists() and curated_ef.exists():
192192
shutil.copy2(curated_ef, img_ef)
@@ -228,39 +228,39 @@ def _write_game_entry(
228228
label = variant["label"]
229229
vkey = variant["variant_key"]
230230
settings_str = ", ".join(
231-
f"{k}={v!r}" for k, v in catalog_draw_tree_settings(vkey).items()
231+
f"{k}={v!r}" for k, v in catalog_gtdraw_settings(vkey).items()
232232
)
233233
f.write(f"{i2}.. tab-item:: {label}\n")
234234
f.write(f"{i2}\n")
235235
f.write(f"{i3}.. jupyter-execute::\n")
236236
f.write(f"{i3} :hide-code:\n")
237237
f.write(f"{i3} \n")
238238
f.write(f"{i4}import pygambit\n")
239-
f.write(f"{i4}from draw_tree import draw_tree\n")
239+
f.write(f"{i4}from gtdraw import draw\n")
240240
if variant["ef_path"].exists():
241-
f.write(f'{i4}draw_tree("../catalog/{vkey}.ef", {settings_str})\n')
241+
f.write(f'{i4}draw("../catalog/{vkey}.ef", {settings_str})\n')
242242
else:
243-
f.write(f'{i4}draw_tree(pygambit.catalog.load("{slug}"), {settings_str})\n')
243+
f.write(f'{i4}draw(pygambit.catalog.load("{slug}"), {settings_str})\n')
244244
f.write(f"{i2}\n")
245245
f.write(f"{i1}\n")
246246
else:
247247
f.write(f"{i1}.. jupyter-execute::\n")
248248
f.write(f"{i1} :hide-code:\n")
249249
f.write(f"{i1} \n")
250250
f.write(f"{i2}import pygambit\n")
251-
f.write(f"{i2}from draw_tree import draw_tree\n")
251+
f.write(f"{i2}from gtdraw import draw\n")
252252
if row["Format"] == "efg":
253253
settings_str = ", ".join(
254-
f"{k}={v!r}" for k, v in catalog_draw_tree_settings(slug).items()
254+
f"{k}={v!r}" for k, v in catalog_gtdraw_settings(slug).items()
255255
)
256256
curated_ef = catalog_dir / f"{slug}.ef"
257257
if curated_ef.exists():
258-
f.write(f'{i2}draw_tree("../catalog/{slug}.ef", {settings_str})\n')
258+
f.write(f'{i2}draw("../catalog/{slug}.ef", {settings_str})\n')
259259
else:
260-
f.write(f'{i2}draw_tree(pygambit.catalog.load("{slug}"), {settings_str})\n')
260+
f.write(f'{i2}draw(pygambit.catalog.load("{slug}"), {settings_str})\n')
261261
elif row["Format"] == "nfg":
262262
f.write(
263-
f'{i2}draw_tree(pygambit.catalog.load("{slug}"), '
263+
f'{i2}draw(pygambit.catalog.load("{slug}"), '
264264
f'save_to="../catalog/img/{slug}.png")\n'
265265
)
266266
f.write(f"{i1}\n")
@@ -403,7 +403,7 @@ def update_makefile(
403403
help=(
404404
"Force regeneration of all game visualisation images (PNG, PDF, SVG, TeX), "
405405
"even if they already exist. Use this to pick up changes to game files or "
406-
"draw_tree_settings.yaml."
406+
"gtdraw_settings.yaml."
407407
),
408408
)
409409
args = parser.parse_args()

doc/developer.catalog.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Currently supported representations are:
7575
(e.g. ``catalog/source/game.ef``).
7676
When present, ``update.py`` will use this file directly as input to DrawTree instead of
7777
auto-generating the layout from the ``.efg``, preserving any hand-tuned layout.
78-
Consult the `DrawTree docs <https://www.gambit-project.org/draw_tree/>`_ for the ``.ef`` format.
78+
Consult the `DrawTree docs <https://www.gambit-project.org/gtdraw/>`_ for the ``.ef`` format.
7979

8080
In general, ``.ef`` files should only be added when the layout they provide differs significantly
8181
from what DrawTree produces automatically; if the auto-generated layout is reasonable, there is
@@ -101,10 +101,10 @@ Currently supported representations are:
101101

102102
Ensure you have installed the package in editable mode to automatically pick up the new game file(s) in the ``pygambit.catalog`` module without reinstalling each time.
103103
Then use the ``update.py`` script to update Gambit's documentation & build files, as well as generating images for the new game(s).
104-
If you want to customise the visualisation parameters for your game(s), edit ``build_support/catalog/draw_tree_settings.yaml``.
104+
If you want to customise the visualisation parameters for your game(s), edit ``build_support/catalog/gtdraw_settings.yaml``.
105105
Add an entry under ``overrides`` keyed by your game's exact slug, or by a shared prefix (e.g. the author-year folder name) to apply settings to all games from that source.
106106
More specific entries (longer keys) take precedence over shorter ones.
107-
Consult the `DrawTree docs <https://www.gambit-project.org/draw_tree/>`_ for available settings.
107+
Consult the `DrawTree docs <https://www.gambit-project.org/gtdraw/>`_ for available settings.
108108

109109
.. code-block:: bash
110110
@@ -129,8 +129,8 @@ Currently supported representations are:
129129
130130
.. tip::
131131

132-
If the game visuals for extensive form games need some work and you aren't sure which settings to change in ``build_support/catalog/draw_tree_settings.yaml``, try loading the EFG in the DrawTree GUI and adjusting the layout there.
133-
There is an option to `download settings <https://www.gambit-project.org/draw_tree/gui/#exporting-and-reusing-settings>`_ which can be used in the Gambit catalog.
132+
If the game visuals for extensive form games need some work and you aren't sure which settings to change in ``build_support/catalog/gtdraw_settings.yaml``, try loading the EFG in the DrawTree GUI and adjusting the layout there.
133+
There is an option to `download settings <https://www.gambit-project.org/gtdraw/gui/#exporting-and-reusing-settings>`_ which can be used in the Gambit catalog.
134134

135135
5. **[Optional] Test your updates to the documentation locally:**
136136

@@ -142,7 +142,7 @@ Currently supported representations are:
142142
6. **Submit a pull request to GitHub with all changes.**
143143

144144
Submit a PR according to the :ref:`usual workflow <submit-contribution>`.
145-
Ensure that any additions and changes to game files, ``build_support/catalog/draw_tree_settings.yaml``, ``build_support/catalog/update.py`` and ``build_support/catalog/catalog.am`` are included.
145+
Ensure that any additions and changes to game files, ``build_support/catalog/gtdraw_settings.yaml``, ``build_support/catalog/update.py`` and ``build_support/catalog/catalog.am`` are included.
146146

147147
.. important::
148148

doc/tutorials/02_extensive_form.ipynb

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,15 @@
44
"cell_type": "markdown",
55
"id": "96019084",
66
"metadata": {},
7-
"source": [
8-
"# 2) Extensive-form games\n",
9-
"\n",
10-
"In the first tutorial, we used Gambit to set up the Prisoner's Dilemma, an example of a normal (strategic) form game.\n",
11-
"\n",
12-
"Gambit can also be used to set up extensive-form games; the game is represented as a tree, where each node represents a decision point for a player, and the branches represent the possible actions they can take.\n",
13-
"\n",
14-
"**Example: One-shot trust game with binary actions**\n",
15-
"\n",
16-
"[Kreps (1990)](#references) introduced a game commonly referred to as the **trust game**.\n",
17-
"We will build a one-shot version of this game using Gambit's game transformation operations.\n",
18-
"\n",
19-
"The game can be defined as follows:\n",
20-
"- There are two players, a **Buyer** and a **Seller**.\n",
21-
"- The Buyer moves first and has two actions, **Trust** or **Not trust**.\n",
22-
"- If the Buyer chooses **Not trust**, then the game ends, and both players receive payoffs of `0`.\n",
23-
"- If the Buyer chooses **Trust**, then the Seller has a choice with two actions, **Honor** or **Abuse**.\n",
24-
"- If the Seller chooses **Honor**, both players receive payoffs of `1`;\n",
25-
"- If the Seller chooses **Abuse**, the Buyer receives a payoff of `-1` and the Seller receives a payoff of `2`.\n",
26-
"\n",
27-
"In addition to `pygambit`, this tutorial introduces the `draw_tree` package, which can be used to draw extensive form games in Python.\n",
28-
"If you're running this tutorial on your local machine, you'll need to install the requirements for [draw_tree](https://github.com/gambitproject/draw_tree), which include LaTeX, in order to run the `draw_tree` cells.\n",
29-
"Another option for visualising extensive form games is to install the Gambit GUI and use it to load the EFG file generated at the end of this tutorial."
30-
]
7+
"source": "# 2) Extensive-form games\n\nIn the first tutorial, we used Gambit to set up the Prisoner's Dilemma, an example of a normal (strategic) form game.\n\nGambit can also be used to set up extensive-form games; the game is represented as a tree, where each node represents a decision point for a player, and the branches represent the possible actions they can take.\n\n**Example: One-shot trust game with binary actions**\n\n[Kreps (1990)](#references) introduced a game commonly referred to as the **trust game**.\nWe will build a one-shot version of this game using Gambit's game transformation operations.\n\nThe game can be defined as follows:\n- There are two players, a **Buyer** and a **Seller**.\n- The Buyer moves first and has two actions, **Trust** or **Not trust**.\n- If the Buyer chooses **Not trust**, then the game ends, and both players receive payoffs of `0`.\n- If the Buyer chooses **Trust**, then the Seller has a choice with two actions, **Honor** or **Abuse**.\n- If the Seller chooses **Honor**, both players receive payoffs of `1`;\n- If the Seller chooses **Abuse**, the Buyer receives a payoff of `-1` and the Seller receives a payoff of `2`.\n\nIn addition to `pygambit`, this tutorial introduces the `gtdraw` package, which can be used to draw extensive form games in Python.\nIf you're running this tutorial on your local machine, you'll need to install the requirements for [gtdraw](https://www.gambit-project.org/gtdraw/), which include LaTeX, in order to run the `gtdraw` cells.\nAnother option for visualising extensive form games is to install the Gambit GUI and use it to load the EFG file generated at the end of this tutorial."
318
},
329
{
3310
"cell_type": "code",
3411
"execution_count": null,
3512
"id": "5946289b",
3613
"metadata": {},
3714
"outputs": [],
38-
"source": [
39-
"from draw_tree import draw_tree\n",
40-
"\n",
41-
"import pygambit as gbt"
42-
]
15+
"source": "from gtdraw import draw\n\nimport pygambit as gbt"
4316
},
4417
{
4518
"cell_type": "markdown",
@@ -76,9 +49,7 @@
7649
"id": "3cd94917",
7750
"metadata": {},
7851
"outputs": [],
79-
"source": [
80-
"draw_tree(g)"
81-
]
52+
"source": "draw(g)"
8253
},
8354
{
8455
"cell_type": "markdown",
@@ -110,9 +81,7 @@
11081
"id": "45638fda-7e25-4c8e-b709-24b05780581b",
11182
"metadata": {},
11283
"outputs": [],
113-
"source": [
114-
"draw_tree(g)"
115-
]
84+
"source": "draw(g)"
11685
},
11786
{
11887
"cell_type": "markdown",
@@ -142,9 +111,7 @@
142111
"id": "ce41e9fe-cca4-46fb-8e9d-b2c27342e5ef",
143112
"metadata": {},
144113
"outputs": [],
145-
"source": [
146-
"draw_tree(g)"
147-
]
114+
"source": "draw(g)"
148115
},
149116
{
150117
"cell_type": "markdown",
@@ -180,9 +147,7 @@
180147
"id": "b3408c55-714e-4a6f-b598-e338839442e4",
181148
"metadata": {},
182149
"outputs": [],
183-
"source": [
184-
"draw_tree(g)"
185-
]
150+
"source": "draw(g)"
186151
},
187152
{
188153
"cell_type": "markdown",
@@ -214,9 +179,7 @@
214179
"id": "09bedb3a-aac7-46e6-ae93-c47932c746d4",
215180
"metadata": {},
216181
"outputs": [],
217-
"source": [
218-
"draw_tree(g)"
219-
]
182+
"source": "draw(g)"
220183
},
221184
{
222185
"cell_type": "markdown",
@@ -248,9 +211,7 @@
248211
"id": "cba0e562-2989-4dae-a0f0-b121635ba032",
249212
"metadata": {},
250213
"outputs": [],
251-
"source": [
252-
"draw_tree(g)"
253-
]
214+
"source": "draw(g)"
254215
},
255216
{
256217
"cell_type": "markdown",
@@ -297,10 +258,7 @@
297258
"id": "56899a29-cc53-48db-9eb4-ed2295517400",
298259
"metadata": {},
299260
"outputs": [],
300-
"source": [
301-
"g = gbt.catalog.load(\"journals/ijgt/selten1975/fig2\")\n",
302-
"draw_tree(g)"
303-
]
261+
"source": "g = gbt.catalog.load(\"journals/ijgt/selten1975/fig2\")\ndraw(g)"
304262
},
305263
{
306264
"cell_type": "markdown",

doc/tutorials/03_stripped_down_poker.ipynb

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,15 @@
44
"cell_type": "markdown",
55
"id": "98eb65d8",
66
"metadata": {},
7-
"source": [
8-
"# 3) Stripped-down poker\n",
9-
"\n",
10-
"In this tutorial, we'll create an extensive-form representation of a one-card poker game from [Reiley et al (2008)](#references), a classroom game under the name \"stripped-down poker\".\n",
11-
"This is perhaps the simplest interesting game with imperfect information.\n",
12-
"\n",
13-
"We'll use \"stripped-down poker\" to demonstrate and explain the following with Gambit:\n",
14-
"\n",
15-
"1. Setting up an extensive-form game with imperfect information using [information sets](#information-sets)\n",
16-
"2. [Computing and interpreting Nash equilibria](#computing-and-interpreting-nash-equilibria) and understanding mixed behaviour and mixed strategy profiles\n",
17-
"3. [Acceptance criteria for Nash equilibria](#acceptance-criteria-for-nash-equilibria)\n",
18-
"\n",
19-
"In our version of the game, there are two players, **Alice** and **Bob**, and a deck of cards, with equal numbers of **King** and **Queen** cards.\n",
20-
"\n",
21-
"- The game begins with each player putting \\$1 in the pot.\n",
22-
" - A card is dealt at random to Alice.\n",
23-
" - Alice observes her card.\n",
24-
" - Bob does not observe the card.\n",
25-
"- Alice then chooses either to **Bet** or to **Fold**.\n",
26-
" - If she chooses to Fold, Bob wins the pot and the game ends.\n",
27-
" - If she chooses to Bet, she adds another \\$1 to the pot.\n",
28-
"- Bob then chooses either to **Call** or **Fold**.\n",
29-
" - If he chooses to Fold, Alice wins the pot and the game ends.\n",
30-
" - If he chooses to Call, he adds another $1 to the pot.\n",
31-
"- There is then a showdown, in which Alice reveals her card.\n",
32-
" - If she has a King, then she wins the pot.\n",
33-
" - If she has a Queen, then Bob wins the pot.\n",
34-
"\n",
35-
"In addition to `pygambit`, this tutorial uses the `draw_tree` package, which can be used to draw extensive form games in Python.\n",
36-
"If you're running this tutorial on your local machine, you'll need to install the requirements for [draw_tree](https://github.com/gambitproject/draw_tree), which include LaTeX, in order to run the `draw_tree` cells.\n",
37-
"Another option for visualising extensive form games is to install the Gambit GUI and use it to load a saved EFG file."
38-
]
7+
"source": "# 3) Stripped-down poker\n\nIn this tutorial, we'll create an extensive-form representation of a one-card poker game from [Reiley et al (2008)](#references), a classroom game under the name \"stripped-down poker\".\nThis is perhaps the simplest interesting game with imperfect information.\n\nWe'll use \"stripped-down poker\" to demonstrate and explain the following with Gambit:\n\n1. Setting up an extensive-form game with imperfect information using [information sets](#information-sets)\n2. [Computing and interpreting Nash equilibria](#computing-and-interpreting-nash-equilibria) and understanding mixed behaviour and mixed strategy profiles\n3. [Acceptance criteria for Nash equilibria](#acceptance-criteria-for-nash-equilibria)\n\nIn our version of the game, there are two players, **Alice** and **Bob**, and a deck of cards, with equal numbers of **King** and **Queen** cards.\n\n- The game begins with each player putting \\$1 in the pot.\n - A card is dealt at random to Alice.\n - Alice observes her card.\n - Bob does not observe the card.\n- Alice then chooses either to **Bet** or to **Fold**.\n - If she chooses to Fold, Bob wins the pot and the game ends.\n - If she chooses to Bet, she adds another \\$1 to the pot.\n- Bob then chooses either to **Call** or **Fold**.\n - If he chooses to Fold, Alice wins the pot and the game ends.\n - If he chooses to Call, he adds another $1 to the pot.\n- There is then a showdown, in which Alice reveals her card.\n - If she has a King, then she wins the pot.\n - If she has a Queen, then Bob wins the pot.\n\nIn addition to `pygambit`, this tutorial uses the `gtdraw` package, which can be used to draw extensive form games in Python.\nIf you're running this tutorial on your local machine, you'll need to install the requirements for [gtdraw](https://www.gambit-project.org/gtdraw/), which include LaTeX, in order to run the `gtdraw` cells.\nAnother option for visualising extensive form games is to install the Gambit GUI and use it to load a saved EFG file."
398
},
409
{
4110
"cell_type": "code",
4211
"execution_count": null,
4312
"id": "69cbfe81",
4413
"metadata": {},
4514
"outputs": [],
46-
"source": [
47-
"from draw_tree import draw_tree\n",
48-
"\n",
49-
"import pygambit as gbt"
50-
]
15+
"source": "from gtdraw import draw\n\nimport pygambit as gbt"
5116
},
5217
{
5318
"cell_type": "markdown",
@@ -124,9 +89,7 @@
12489
"id": "867cb1d8-7a5d-45d1-9349-9bbc2a4e2344",
12590
"metadata": {},
12691
"outputs": [],
127-
"source": [
128-
"draw_tree(g, color_scheme=\"gambit\")"
129-
]
92+
"source": "draw(g, color_scheme=\"gambit\")"
13093
},
13194
{
13295
"cell_type": "markdown",
@@ -163,9 +126,7 @@
163126
"id": "0c522c2d-992e-48b6-a1f8-0696d33cdbe0",
164127
"metadata": {},
165128
"outputs": [],
166-
"source": [
167-
"draw_tree(g, color_scheme=\"gambit\")"
168-
]
129+
"source": "draw(g, color_scheme=\"gambit\")"
169130
},
170131
{
171132
"cell_type": "markdown",
@@ -205,9 +166,7 @@
205166
"id": "e85b3346-2fea-4a73-aa72-9efb436c68c1",
206167
"metadata": {},
207168
"outputs": [],
208-
"source": [
209-
"draw_tree(g, color_scheme=\"gambit\")"
210-
]
169+
"source": "draw(g, color_scheme=\"gambit\")"
211170
},
212171
{
213172
"cell_type": "markdown",
@@ -271,9 +230,7 @@
271230
"id": "fdee7b53-7820-44df-9d17-d15d0b9667aa",
272231
"metadata": {},
273232
"outputs": [],
274-
"source": [
275-
"draw_tree(g, color_scheme=\"gambit\")"
276-
]
233+
"source": "draw(g, color_scheme=\"gambit\")"
277234
},
278235
{
279236
"cell_type": "markdown",

0 commit comments

Comments
 (0)