Skip to content

[WIP] Integrate drawtree#576

Closed
edwardchalstrey1 wants to merge 251 commits intomasterfrom
integrate-drawtree
Closed

[WIP] Integrate drawtree#576
edwardchalstrey1 wants to merge 251 commits intomasterfrom
integrate-drawtree

Conversation

@edwardchalstrey1
Copy link
Copy Markdown
Member

@edwardchalstrey1 edwardchalstrey1 commented Oct 27, 2025

…e server when doing local development to docs
@tturocy
Copy link
Copy Markdown
Member

tturocy commented Nov 19, 2025

In PR #631 I have now provisionally refactored the 'classic Gambit' tree layout algorithm and made it available provisionally in Python.

There's a new function pygambit.layout_tree(Game) -> dict[Node, LayoutCoordinates], where LayoutCoordinates is a dataclass with fields level, sublevel, and offset.

This function isn't yet documented as it's probably premature to commit to anything more specific as far as what layout might look like!

If this looks like it would be good for what you need @edwardchalstrey1 I can squash and merge so you can experiment with getting it integrated into this work.

@edwardchalstrey1
Copy link
Copy Markdown
Member Author

In PR #631 I have now provisionally refactored the 'classic Gambit' tree layout algorithm and made it available provisionally in Python.

There's a new function pygambit.layout_tree(Game) -> dict[Node, LayoutCoordinates], where LayoutCoordinates is a dataclass with fields level, sublevel, and offset.

This function isn't yet documented as it's probably premature to commit to anything more specific as far as what layout might look like!

If this looks like it would be good for what you need @edwardchalstrey1 I can squash and merge so you can experiment with getting it integrated into this work.

Thanks @tturocy - if you prefer not to merge #631 into master yet I can merge that branch into this one in order to get the changes here anyway. Need to update this branch with the changes on master anyway

@edwardchalstrey1
Copy link
Copy Markdown
Member Author

edwardchalstrey1 commented Nov 20, 2025

draw tree todos

Best approach would be to pass a game object from pygambit to draw_tree and whilst pygambit is not a requirement of draw_tree (since we don't need it to draw .ef files that already have layout encoded), using the gambit layout functionality does require it and throws an error if pygambit is not installed.

  • Move DefaultLayout to a separate .py file from core
  • Rename efg_to_ef to reflect that this uses the "default layout" not Gambit layout
    • Later on, might be better to remove this completely and if an EFG is passed in, use the gambit layout, via first reading the game with gambit

Idea 1: interoperability handled by draw_tree. Resulting notebook code:

draw_tree(g)
  • Add gambit_to_ef function that accepts a pygambit.gambit.Game object and creates the layout tree dict with gbt.layout_tree(g) and uses these to create an ef representation (we need label, payoff etc info from the game as well as the layout). The import pygambit as gbt will need to happen within this function as we cannot expect all users of draw_tree to have it installed.
  • Update generate_tikz, draw_tree and generate_X functions to accept a gambit game object as an alternative to ef file. Within generate_tikz it should check the object type and if a gambit game object is passed in, use the new gambit_to_ef function.
  • Do the above on a new branch in draw_tree and increment the version number

Idea 2: interoperability handled by pygambit. Resulting notebook code:

g.to_ef("game.ef")
draw_tree("game.ef")
  • Add a function in Gambit that can generate .ef
    • To render in the tutorials we'd need to save the ef files generated in the notebook before loading them with draw_tree, which could break the test that runs all notebooks

Edit: sticking with idea 1 above

@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

@edwardchalstrey1
Copy link
Copy Markdown
Member Author

Closing this PR, will open a new one

@github-project-automation github-project-automation bot moved this from In progress to Done in Ed Chalstrey Gambit priorities Dec 3, 2025
@edwardchalstrey1 edwardchalstrey1 deleted the integrate-drawtree branch December 3, 2025 14:23
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.

3 participants