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

Add transitive_closure_dag function #707

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

mtreinish
Copy link
Member

This commit adds a new function transitive_closure_dag() which is an optimized method for computing the transitive closure for DAGs. In support of this a new function descendants_at_distance() for finding the nodes a fixed distance from a given source to both rustworkx and rustworkx-core.

Related to: #704

TODO:

  • Add tests for descendants_at_distance (both from python and rust)

This commit adds a new function transitive_closure_dag() which is an
optimized method for computing the transitive closure for DAGs. In
support of this a new function descendants_at_distance() for finding the
nodes a fixed distance from a given source to both rustworkx and
rustworkx-core.

Related to: Qiskit#704
@coveralls
Copy link

coveralls commented Oct 20, 2022

Pull Request Test Coverage Report for Build 3344180388

  • 66 of 95 (69.47%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 96.762%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rustworkx-core/src/traversal/transitive_closure.rs 20 21 95.24%
src/traversal/mod.rs 0 28 0.0%
Totals Coverage Status
Change from base Build 3342385398: -0.1%
Covered Lines: 13537
Relevant Lines: 13990

💛 - Coveralls

Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

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

This commit adds a new function transitive_closure_dag() which is an optimized method for computing the transitive closure for DAGs. In support of this a new function descendants_at_distance() for finding the nodes a fixed distance from a given source to both rustworkx and rustworkx-core.

Related to: #704

TODO:

  • Add tests for descendants_at_distance (both from python and rust)

Well, computing the transitive closure for a DAG is 80% of the problem for the general case because the full algorithm is:

  • Condense the graph into strongly connect components (which we already implement)
  • Apply the DAG algorithm and get the transitive closure for the intermediate graph
  • Map the answer from the intermediate graph to the original graph

src/dag_algo/mod.rs Show resolved Hide resolved
This commit adds a new function to rustworkx-core for building a
transitive closure inplace out of an input DAG. The function takes
ownership of the input graph and will mutate it to add edtges to make it
a transitive closure before returning it. This is then used internally
by the retworkx python function transitive_clsoure_dag().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants