Skip to content

Commit e6579f5

Browse files
update extensive form notebook to save tree image to file with draw_tree
1 parent 49ca9f7 commit e6579f5

2 files changed

Lines changed: 51 additions & 75 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Gambit.app/*
4343
*.so
4444
doc/tutorials/games/*.nfg
4545
doc/tutorials/games/*.efg
46+
doc/tutorials/*.png
4647
*.dmg
4748
Gambit.app/*
4849
*.ipynb_checkpoints

doc/tutorials/02_extensive_form.ipynb

Lines changed: 50 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
{
3333
"cell_type": "code",
34-
"execution_count": null,
34+
"execution_count": 1,
3535
"id": "5946289b",
3636
"metadata": {},
3737
"outputs": [],
@@ -51,7 +51,7 @@
5151
},
5252
{
5353
"cell_type": "code",
54-
"execution_count": 10,
54+
"execution_count": 2,
5555
"id": "91ed4dfb",
5656
"metadata": {},
5757
"outputs": [],
@@ -72,17 +72,10 @@
7272
},
7373
{
7474
"cell_type": "code",
75-
"execution_count": 11,
75+
"execution_count": 3,
7676
"id": "3cd94917",
7777
"metadata": {},
7878
"outputs": [
79-
{
80-
"name": "stdout",
81-
"output_type": "stream",
82-
"text": [
83-
"Writing .ef file to: One-shot trust game, after Kreps (1990).ef\n"
84-
]
85-
},
8679
{
8780
"data": {
8881
"image/svg+xml": [
@@ -107,7 +100,7 @@
107100
"<IPython.core.display.SVG object>"
108101
]
109102
},
110-
"execution_count": 11,
103+
"execution_count": 3,
111104
"metadata": {},
112105
"output_type": "execute_result"
113106
}
@@ -128,7 +121,7 @@
128121
},
129122
{
130123
"cell_type": "code",
131-
"execution_count": 12,
124+
"execution_count": 4,
132125
"id": "5d27a07a",
133126
"metadata": {},
134127
"outputs": [],
@@ -142,17 +135,10 @@
142135
},
143136
{
144137
"cell_type": "code",
145-
"execution_count": 13,
138+
"execution_count": 5,
146139
"id": "45638fda-7e25-4c8e-b709-24b05780581b",
147140
"metadata": {},
148141
"outputs": [
149-
{
150-
"name": "stdout",
151-
"output_type": "stream",
152-
"text": [
153-
"Writing .ef file to: One-shot trust game, after Kreps (1990).ef\n"
154-
]
155-
},
156142
{
157143
"data": {
158144
"image/svg+xml": [
@@ -267,7 +253,7 @@
267253
"<IPython.core.display.SVG object>"
268254
]
269255
},
270-
"execution_count": 13,
256+
"execution_count": 5,
271257
"metadata": {},
272258
"output_type": "execute_result"
273259
}
@@ -286,7 +272,7 @@
286272
},
287273
{
288274
"cell_type": "code",
289-
"execution_count": 14,
275+
"execution_count": 6,
290276
"id": "47c4a31b",
291277
"metadata": {},
292278
"outputs": [],
@@ -300,17 +286,10 @@
300286
},
301287
{
302288
"cell_type": "code",
303-
"execution_count": 15,
289+
"execution_count": 7,
304290
"id": "ce41e9fe-cca4-46fb-8e9d-b2c27342e5ef",
305291
"metadata": {},
306292
"outputs": [
307-
{
308-
"name": "stdout",
309-
"output_type": "stream",
310-
"text": [
311-
"Writing .ef file to: One-shot trust game, after Kreps (1990).ef\n"
312-
]
313-
},
314293
{
315294
"data": {
316295
"image/svg+xml": [
@@ -476,7 +455,7 @@
476455
"<IPython.core.display.SVG object>"
477456
]
478457
},
479-
"execution_count": 15,
458+
"execution_count": 7,
480459
"metadata": {},
481460
"output_type": "execute_result"
482461
}
@@ -499,7 +478,7 @@
499478
},
500479
{
501480
"cell_type": "code",
502-
"execution_count": 16,
481+
"execution_count": 8,
503482
"id": "716e9b9a",
504483
"metadata": {},
505484
"outputs": [],
@@ -515,17 +494,10 @@
515494
},
516495
{
517496
"cell_type": "code",
518-
"execution_count": 17,
497+
"execution_count": 9,
519498
"id": "b3408c55-714e-4a6f-b598-e338839442e4",
520499
"metadata": {},
521500
"outputs": [
522-
{
523-
"name": "stdout",
524-
"output_type": "stream",
525-
"text": [
526-
"Writing .ef file to: One-shot trust game, after Kreps (1990).ef\n"
527-
]
528-
},
529501
{
530502
"data": {
531503
"image/svg+xml": [
@@ -677,7 +649,7 @@
677649
"<IPython.core.display.SVG object>"
678650
]
679651
},
680-
"execution_count": 17,
652+
"execution_count": 9,
681653
"metadata": {},
682654
"output_type": "execute_result"
683655
}
@@ -696,7 +668,7 @@
696668
},
697669
{
698670
"cell_type": "code",
699-
"execution_count": 18,
671+
"execution_count": 10,
700672
"id": "695b1aad",
701673
"metadata": {},
702674
"outputs": [],
@@ -712,17 +684,10 @@
712684
},
713685
{
714686
"cell_type": "code",
715-
"execution_count": 19,
687+
"execution_count": 11,
716688
"id": "09bedb3a-aac7-46e6-ae93-c47932c746d4",
717689
"metadata": {},
718690
"outputs": [
719-
{
720-
"name": "stdout",
721-
"output_type": "stream",
722-
"text": [
723-
"Writing .ef file to: One-shot trust game, after Kreps (1990).ef\n"
724-
]
725-
},
726691
{
727692
"data": {
728693
"image/svg+xml": [
@@ -888,7 +853,7 @@
888853
"<IPython.core.display.SVG object>"
889854
]
890855
},
891-
"execution_count": 19,
856+
"execution_count": 11,
892857
"metadata": {},
893858
"output_type": "execute_result"
894859
}
@@ -907,7 +872,7 @@
907872
},
908873
{
909874
"cell_type": "code",
910-
"execution_count": 20,
875+
"execution_count": 12,
911876
"id": "0704ef86",
912877
"metadata": {},
913878
"outputs": [],
@@ -923,17 +888,10 @@
923888
},
924889
{
925890
"cell_type": "code",
926-
"execution_count": 21,
891+
"execution_count": 13,
927892
"id": "cba0e562-2989-4dae-a0f0-b121635ba032",
928893
"metadata": {},
929894
"outputs": [
930-
{
931-
"name": "stdout",
932-
"output_type": "stream",
933-
"text": [
934-
"Writing .ef file to: One-shot trust game, after Kreps (1990).ef\n"
935-
]
936-
},
937895
{
938896
"data": {
939897
"image/svg+xml": [
@@ -1095,7 +1053,7 @@
10951053
"<IPython.core.display.SVG object>"
10961054
]
10971055
},
1098-
"execution_count": 21,
1056+
"execution_count": 13,
10991057
"metadata": {},
11001058
"output_type": "execute_result"
11011059
}
@@ -1125,12 +1083,13 @@
11251083
"You can use Gambit to save games to, and read from files.\n",
11261084
"The specific format depends on whether the game is normal or extensive-form.\n",
11271085
"\n",
1128-
"Here we'll save the Trust game (extensive-form) to the `.efg` format."
1086+
"Here we'll save the Trust game (extensive-form) to the `.efg` format.\n",
1087+
"Uncomment these lines of code if you're running the tutorial locally:"
11291088
]
11301089
},
11311090
{
11321091
"cell_type": "code",
1133-
"execution_count": 22,
1092+
"execution_count": 14,
11341093
"id": "37c51152",
11351094
"metadata": {},
11361095
"outputs": [],
@@ -1148,21 +1107,45 @@
11481107
},
11491108
{
11501109
"cell_type": "code",
1151-
"execution_count": 23,
1110+
"execution_count": 15,
11521111
"id": "0d86a750",
11531112
"metadata": {},
11541113
"outputs": [],
11551114
"source": [
11561115
"# gbt.read_efg(\"trust_game.efg\")"
11571116
]
11581117
},
1118+
{
1119+
"cell_type": "markdown",
1120+
"id": "182f2424-274e-4044-84ff-3323cd70ec68",
1121+
"metadata": {},
1122+
"source": [
1123+
"You can also use the `draw_tree` package to save the game in the `.ef` format which encodes layout information.\n",
1124+
"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)):"
1125+
]
1126+
},
11591127
{
11601128
"cell_type": "code",
1161-
"execution_count": null,
1129+
"execution_count": 18,
11621130
"id": "1bab777f-8a0b-4f1e-9c0c-270690288243",
11631131
"metadata": {},
11641132
"outputs": [],
1165-
"source": []
1133+
"source": [
1134+
"# from draw_tree import generate_png\n",
1135+
"# draw_tree(g, save_to=\"trust_game.ef\")\n",
1136+
"# trust_game_png = generate_png(\"trust_game.ef\")"
1137+
]
1138+
},
1139+
{
1140+
"cell_type": "code",
1141+
"execution_count": 19,
1142+
"id": "2b715221-e427-4092-ad2f-9f4f2b548fa4",
1143+
"metadata": {},
1144+
"outputs": [],
1145+
"source": [
1146+
"# from IPython.display import Image\n",
1147+
"# Image(trust_game_png)"
1148+
]
11661149
},
11671150
{
11681151
"cell_type": "markdown",
@@ -1173,19 +1156,11 @@
11731156
"\n",
11741157
"Kreps, D. (1990) \"Corporate Culture and Economic Theory.\" In J. Alt and K. Shepsle, eds., *Perspectives on Positive Political Economy*, Cambridge University Press."
11751158
]
1176-
},
1177-
{
1178-
"cell_type": "code",
1179-
"execution_count": null,
1180-
"id": "ddf390ee-5d99-41a9-bfd9-7df86e372d5b",
1181-
"metadata": {},
1182-
"outputs": [],
1183-
"source": []
11841159
}
11851160
],
11861161
"metadata": {
11871162
"kernelspec": {
1188-
"display_name": "gambitvenv313",
1163+
"display_name": "Python 3 (ipykernel)",
11891164
"language": "python",
11901165
"name": "python3"
11911166
},

0 commit comments

Comments
 (0)