Skip to content

docs: document canonical order in toposort for nodes of the same rank#280

Merged
aborgna-q merged 2 commits intoQuantinuum:mainfrom
PanieriLorenzo:doc-toposort_order
Feb 25, 2026
Merged

docs: document canonical order in toposort for nodes of the same rank#280
aborgna-q merged 2 commits intoQuantinuum:mainfrom
PanieriLorenzo:doc-toposort_order

Conversation

@PanieriLorenzo
Copy link
Contributor

Kahn's algorithm alone does not provide a canonical order for nodes of the same rank. The order depends on the data structure used to store "discovered" nodes that haven't been visited yet.

I've clarified this in the docs for toposort, toposort_filtered and Toposort, adding that we use a queue to determine the order within the same rank, resulting in ties being broken by visiting nodes in the same order they are discovered. I also updated the example given for toposort to exhibit this tie-breaking behavior.

All tests pass.

@PanieriLorenzo PanieriLorenzo changed the title Document canonical order in toposort for nodes of the same rank docs: document canonical order in toposort for nodes of the same rank Feb 24, 2026
@aborgna-q aborgna-q self-requested a review February 25, 2026 10:06
@aborgna-q aborgna-q added the documentation Improvements or additions to documentation label Feb 25, 2026
Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@aborgna-q aborgna-q added this pull request to the merge queue Feb 25, 2026
Merged via the queue into Quantinuum:main with commit b1c2ab5 Feb 25, 2026
18 of 20 checks passed
@hugrbot hugrbot mentioned this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants