Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix replace_node on nodes with indirect node refs #537

Merged
merged 3 commits into from
Sep 27, 2021

Conversation

danieldk
Copy link
Contributor

@danieldk danieldk commented Sep 21, 2021

Model.replace_node failed if a node n contained a reference to another node m, when m only occurs in one of the (grand)children of n. Since replace_node used the breadth-first Model.walk method, the reference to m would be replaced before m is replaced in the (grand)children of n. However, this fails because set_ref verifies that the a new node reference occurs in the graph.

This change resolves this issue by replacing nodes using a depth-first search.

@danieldk danieldk added the bug Bugs and behaviour differing from documentation label Sep 21, 2021
@danieldk danieldk marked this pull request as draft September 21, 2021 14:51
@danieldk danieldk marked this pull request as ready for review September 21, 2021 17:44
Model.replace_node failed if a node n contained a reference to another
node m, when m only occurs in one of the (grand)children of n.  Since
replace_node used the breadth-first Model.walk method, the reference to
m would be replaced before m is replaced in the (grand)children of n.
However, this fails because set_ref verifies that the a new node
reference occurs in the graph.

This change resolves this issue by replacing nodes using a depth-first
search in post-order. This amounts to doing a topological sort of the
transposed graph.
Update the existing walk method to support both breadth-first and
depth-first traversal by adding an `order` argument that supports
the following string values:

- bfs: breadth-first traversal
- dfs_pre: depth-first traversal in pre-order
- dfs_post: depth-first traversal in post-order
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it doesn't hurt to be specific

thinc/model.py Outdated Show resolved Hide resolved
thinc/model.py Outdated Show resolved Hide resolved
@svlandeg svlandeg merged commit 8ac9851 into explosion:master Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs and behaviour differing from documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants