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

Conversion API to other causal libraries' graph #57

Closed
adam2392 opened this issue Feb 20, 2023 · 7 comments · Fixed by #63
Closed

Conversion API to other causal libraries' graph #57

adam2392 opened this issue Feb 20, 2023 · 7 comments · Fixed by #63
Milestone

Comments

@adam2392
Copy link
Collaborator

adam2392 commented Feb 20, 2023

Is your feature request related to a problem? Please describe.
We should expose an API (there is one untested really rn) for exporting to the following packages:

  • tigramite (3D time-series graph that supports time-series DAG, ADMG, PAG) -> WIP
  • pgmpy (DAG and PDAG)
  • causal-learn (currently we have this implemented) -> done
  • dagitty (DAG, ADMG) -> handled by pygraphviz
  • pcalg -> done
  • networkx to a DiGraph with a specific structure
  • numpy (tigramite, causal-learn, pcalg are all numpy-like array structures) -> done
  • ananke -> @jaron-lee to handle
  • tetrad text -> done
  • bnlearn -> handled by pygraphviz I think

This will enable pywhy-graphs to be interoperable across many other packages and also allow other users to take their graphs and convert to pywhy-graphs for the sake of using it in dodiscover and dowhy.

Describe the solution you'd like
If the other package is not in R, we can directly test roundtrip compatibility.

If the other package is in R, we should just do some basic testing that the format is "as expected". I think loading in R runtime is a whole other beast we don't want to figure out how to do in the CI pipeline.

The solution requires the following for each export:

io roundtrip: That is the basic graph structure should be preserved. Some metadata might be lost depending on the format each package stores graphs in. When possible, metadata should be preserved. A unit test would look like the following where the edge and node structure is preserved.

pcalg_G = pywhy_graphs.export(G, 'pcalg')
G_copy = pywhy_graphs.import(G, 'pcalg')

for edge_type in G.edge_types:
    assert nx.is_isomorphic(G.get_graphs(edge_type), G_copy.get_graphs(edge_type))

Additional context
n/a

@adam2392 adam2392 added this to the v0.2 milestone Feb 20, 2023
@jaron-lee
Copy link
Collaborator

I would also be happy to extend the API to ananke!

@adam2392
Copy link
Collaborator Author

I think based on today's discussion, this seems pretty high value. So I'ma start chipping away at this. Happy to review PR related to ananke.

Re all these packages btw, we'll only add them as soft dependencies for unit-testing purposes. This will go into the poetry group test in the pyproject.toml file

@jaron-lee
Copy link
Collaborator

Will get started on this later this week, on the ananke side I need to remove a hard dependency on graphviz and make sure that didn't break anything.

@jaron-lee
Copy link
Collaborator

Is there a rough sketch of how the api should look? Presumably we want to expose a set of functions that all look and behave roughly the same. One idea that comes to mind is the pandas export functionality, where df.to_<format>() is the pattern.

@adam2392
Copy link
Collaborator Author

Is there a rough sketch of how the api should look? Presumably we want to expose a set of functions that all look and behave roughly the same. One idea that comes to mind is the pandas export functionality, where df.to_<format>() is the pattern.

Currently, I have a functional API, which is just graph_to_<format> and <format>_to_graph. We can add more convenience once we have the working functions.

Will get started on this later this week, on the ananke side I need to remove a hard dependency on graphviz and make sure that didn't break anything.

You can keep it if you want, and just make ananke an optional dependency.

@adam2392 adam2392 modified the milestones: v0.2, Release v0.1 Mar 7, 2023
@adam2392
Copy link
Collaborator Author

adam2392 commented Mar 7, 2023

Everything is done that is doable except Ananke now.

Note: some of the other packages which only supports DAGs, I did not handle or implement. I think those work fine w/ nx.DiGraph for now, so community can PR that if they want it.

This was referenced Mar 7, 2023
@adam2392
Copy link
Collaborator Author

adam2392 commented Mar 9, 2023

Example about tetrad conversion and other library conversion in examples script.

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 a pull request may close this issue.

2 participants