6. Importing causal graphs to PyWhy-Graphs, or exporting PyWhy-Graphs to another package#

Pywhy-graphs provides light-weight data structures and networkx-like methods for storing causal graphs.

The causality community is quite large and currently there is no de-facto standard for representing causal graphs with mixed edges. Therefore, we provide an interface for importing/exporting graphs from other packages.

We currently only offer support for a package if they have a way of representing all types of causal graphs (not just DAGs). We welcome contributions here!

6.1. Causal-Learn#

Causal-learn maintains its own graph interpretation in the form of a structured upper-triangular numpy array.

graph_to_clearn(G)

clearn_to_graph(arr, arr_idx, graph_type)

Convert causal-learn array to a graph object.

6.2. Numpy (graphviz and dagitty)#

GraphViz stores a graph that allows mixed-edges using a numpy array with values filled in following a specific enumeration, so all values can be mapped to an edge, or multiple edges if more than one edge is allowed between nodes.

graph_to_numpy(causal_graph)

Convert causal graph to a numpy adjacency array.

numpy_to_graph(arr, arr_idx, graph_type)

Convert an enumerated numpy array into causal graph.

6.3. PCAlg from R (Experimental)#

pcalg from R uses the following mapping for their array:

  • 0: no edge

  • 1: -o

  • 2: -> (arrowhead)

  • 3: - (tail)

and stores a structured numpy array following this format. This functionality is experimental because this is not tested against the actual implementation in R. Please raise an issue if you encounter errors, or issues.

graph_to_pcalg(causal_graph)

Convert causal graph to a pcalg type adjacency array.

pcalg_to_graph(arr, arr_idx, amat_type)

Convert an array from R's pcalg into causal graph.

6.4. Tetrad from Java#

tetrad from Java uses the following mapping for their endpoints stored in a text file:

  • TAIL = “-”

  • ARROW = “>”

  • CIRCLE = “o”

This functionality is experimental because this is not tested against the actual implementation in Java. Please raise an issue if you encounter errors, or issues.

graph_to_tetrad(G, filename)

Convert a pywhy causal graph to a tetrad text file.

tetrad_to_graph(filename, graph_type)

Convert a tetrad stored graph from a text file to causal graph in pywhy.