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

[ENH] Add the ability to find Proper Possibly Directed Paths #112

Merged
merged 30 commits into from
Aug 26, 2024

Conversation

aryan26roy
Copy link
Collaborator

Add the ability to find Proper Possibly Directed Paths to allow integration with DoWhy.

Fixes #111

Changes proposed in this pull request:

  • Add the necessary functions to find Proper Possibly Directed Paths in a Graph.

Before submitting

  • I've read and followed all steps in the Making a pull request
    section of the CONTRIBUTING docs.
  • I've updated or added any relevant docstrings following the syntax described in the
    Writing docstrings section of the CONTRIBUTING docs.
  • If this PR fixes a bug, I've added a test that will fail without my fix.
  • If this PR adds a new feature, I've added tests that sufficiently cover my new functionality.

After submitting

  • All GitHub Actions jobs for my pull request have passed.

Signed-off-by: Aryan Roy <[email protected]>
@aryan26roy aryan26roy changed the title Added function skeleton Add the ability to find Proper Possibly Directed Paths Jun 8, 2024
@aryan26roy aryan26roy changed the title Add the ability to find Proper Possibly Directed Paths [ENH] Add the ability to find Proper Possibly Directed Paths Jun 8, 2024
@adam2392
Copy link
Collaborator

The CIs should now work. You can also test locally ofc with pytest.

@aryan26roy
Copy link
Collaborator Author

aryan26roy commented Aug 10, 2024

@adam2392 I have completed the implementation and it seems to be correct. However, there is one problem. The output is a list of dictionaries. And the dictionaries can be in any order inside the list which is why the test may fail right now. How do I compare them in an order agnostic way?

I know the brute force way which is to compare every element of the expected output to every element of the actual output. Was wondering if there is a better way.

@adam2392
Copy link
Collaborator

Is there any inspiration from network's method for testing all_simple_paths?

https://github.com/networkx/networkx/blob/main/networkx/algorithms/tests/test_simple_paths.py

@aryan26roy
Copy link
Collaborator Author

They are returning a set of tuples. I am assuming the order of tuples inside a set won't matter during comparison because of it's hashibality. However, I cannot store dictionaries inside sets. Either I change my implementation to store paths in sets(tuple()) or I can do the tests using the brute force method I described above.

What do you want me to do?

@adam2392
Copy link
Collaborator

Is there any technical reason to do dictionaries instead of triples that I'm missing?

Copy link
Collaborator

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

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

Just left a few comments to hopefully push in the right direction

pywhy_graphs/algorithms/generic.py Outdated Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Outdated Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Outdated Show resolved Hide resolved
@aryan26roy
Copy link
Collaborator Author

Sorry for the late reply.

Is there any technical reason to do dictionaries instead of triples that I'm missing?

Not really, I just did not think of using tuples at the time. I think it would be easy to go from List to Set. A better approach in terms of memory as well.

@aryan26roy
Copy link
Collaborator Author

@adam2392 I just realised, since in this implementation, all the first nodes of all the paths are in X, this finds all the proper possibly directed paths, doesn't it?

@adam2392
Copy link
Collaborator

Perhaps it's easier to implement just the function wrt a single node rather than a set of nodes. Do we need the functionality with X as a set? Wdyt?

@aryan26roy
Copy link
Collaborator Author

The paper assumes everywhere that X will be a set. And the current implementation already covers and tests X being a set. It seems to me that changing the implementation now to only support a single node in X would be wasted effort.

Signed-off-by: Aryan Roy <[email protected]>
@adam2392
Copy link
Collaborator

@adam2392 I just realised, since in this implementation, all the first nodes of all the paths are in X, this finds all the proper possibly directed paths, doesn't it?

Yes I believe so.

@aryan26roy
Copy link
Collaborator Author

@adam2392 I believe the PR is complete. Can you do one last round of review? (PS. The failing test is due to some environment issue with some existing test)

Copy link
Collaborator

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

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

Few short comments, but otw, it's looking good

pywhy_graphs/algorithms/tests/test_generic.py Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Outdated Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Outdated Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Show resolved Hide resolved
@aryan26roy
Copy link
Collaborator Author

@adam2392 I have incorporated all of your suggestions. Can you take another look?

Copy link
Collaborator

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

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

LGTM except two minor nits

pywhy_graphs/algorithms/generic.py Outdated Show resolved Hide resolved
pywhy_graphs/algorithms/generic.py Outdated Show resolved Hide resolved
Signed-off-by: Aryan Roy <[email protected]>
@aryan26roy
Copy link
Collaborator Author

Done!

@aryan26roy
Copy link
Collaborator Author

@adam2392 This can be optimised further by switching to a stack based implementation rather than recursion. We can add this to the TODO list.

@adam2392 adam2392 merged commit 053a58b into py-why:main Aug 26, 2024
23 of 25 checks passed
@adam2392
Copy link
Collaborator

Thanks @aryan26roy !

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.

[ENH] Add the ability to find Proper Possibly Directed Paths in a Graph
2 participants