-
Notifications
You must be signed in to change notification settings - Fork 8
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] Export and import graph classes from other common interfaces #60
Conversation
Signed-off-by: Adam Li <[email protected]>
Signed-off-by: Adam Li <[email protected]>
Signed-off-by: Adam Li <[email protected]>
Signed-off-by: Adam Li <[email protected]>
At some point it would be great if you could pick one of |
So I notice that |
Ran into another issue - when I try and run unit tests python is picking up EDIT: I guess I can just work from another folder, never mind! |
What's the issue? The export submodule or the networkx submodule for mixed edge graphs? |
Ah yeah that's an issue. If it's easy to do it for ananke, then that would be great! I'll also submit an issue to tigramite to make the dependency not hard. I know the maintainer. |
Signed-off-by: Adam Li <[email protected]>
I think the export submodule - basically running tests from that folder would get python confused about which networkx to import. Might just be a weird issue on my test runner's end tho. |
Ah I see. We can def rename things if it's an issue. You can just run pytest from the root of the package folder. E.g. Pytest ./pywhy_graphs/... And it should work. |
Signed-off-by: Adam Li <[email protected]>
Signed-off-by: Adam Li <[email protected]>
This is somewhat of a big PR, and happy to break it up, but just wanted to get a high level review of the code from you @jaron-lee and @robertness to make sure the API looks good to you? |
Signed-off-by: Adam Li <[email protected]>
Signed-off-by: Adam Li <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #60 +/- ##
==========================================
+ Coverage 84.03% 84.26% +0.22%
==========================================
Files 29 33 +4
Lines 2255 2510 +255
Branches 578 671 +93
==========================================
+ Hits 1895 2115 +220
+ Misses 254 250 -4
- Partials 106 145 +39
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Signed-off-by: Adam Li <[email protected]>
Overall I think the API looks good, but have a few comments, mostly from the perspective of the Ananke API development. In the Additionally the |
The Note: not all graph types are supported in each export function. E.g. pcalg. We can change that tho, but I avoided the extra work.
Lmk how that sounds. If there's anything you want me to change for downstream ananke PR, lmk! |
tetrad format. | ||
""" | ||
# instantiate the type of causal graph | ||
if graph_type == "dag": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have seen different ways of dealing with DAGs - should we use nx.DiGraph or send it to pywhy_graphs? ADMG here seems like a hack. Maybe an in-house pywhy_graphs DAG class is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Perhaps nx.DiGraph
with some added semantics to ensure construction is acyclic... But it'd be too expensive to check acyclicity every time someone adds a node.
On one hand it seems overkill to recreate a DAG class when nx.DiGraph works. On the other hand, the mental switching is a bit weird.
Tbh not sure exactly which way to go.
import networkx as nx | ||
|
||
|
||
def assert_mixed_edge_graphs_isomorphic(G1, G2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, I presume all roundtrip tests should use this testing function ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
FYI I realized there's a lot of LOC scattered in the codebase doing this.
|
||
|
||
def test_to_tetrad(tmp_path): | ||
G = tetrad_to_graph(filename, graph_type="pag") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if a user has graph_type="dag"
instead here? Will this function detect that there are o->
edges and prevent that? Clearly the imported file does not represent a DAG so we shouldn't let the user make this mistake. Or we should have clear tests to show what happens when you import a graph under a different graph assumption than the one it was created with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point... I guess I can add a check for valid "edge types" present in each graph. I should probably add this to tetrad, pcalg and causallearn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to leave this for another PR.
This all looks good. What I'll do is if a user passes in something of type |
Towards #57
Changes proposed in this pull request:
Now need to add manual tests using what is present in: https://github.com/py-why/causal-learn/blob/main/tests/fci-test-data/result-py-FCI-8.txt for tetrad.
Before submitting
section of the
CONTRIBUTING
docs.Writing docstrings section of the
CONTRIBUTING
docs.After submitting