A declarative framework for designing efficient causal inference algorithms

Get Started

What is CIfly?

CIfly is a framework for developing and writing causal inference algorithms.


Python and R support:

CIfly algorithms can be developed language-independent and easily be called from both Python and R.

Concise specification:

Algorithms are specified in rule tables to avoid boilerplate and put the causal logic in the center.

Performance:

CIfly runs in linear time and its Rust implementation enables further speedups over native R or Python code.

Installation

CIfly can be installed via pip in Python and from R-universe in R (a CRAN submission is planned).

# Python installation with pip
pip install ciflypy

In Python, the installation should work out-of-the-box without relying on any further dependencies. In R, if the package is build on your system, as is the case for Linux distributions, the Rust toolchain needs to be installed.

Example

As a "Hello World" example, we show how to test d-separation with CIfly. The CIfly algorithm specified by the following rule table returns all nodes d-connected to set X given set Z.

dsep.txt
EDGES --> <--
SETS X, Z
START <-- AT X
OUTPUT ...

--> | <-- | current in Z
... | ... | current not in Z

The rule table can be embedded into the code as a multi-line string or loaded via file path such as in the implementation below that tests d-separation using Python and R.

import ciflypy as cf

dsep_table_path = "./dsep.txt"

def test_dsep(G, x, y, Z):
      R = cf.reach(G, {"X": x, "Z": Z}, dsep_table_path)
      return y not in R

# for graph 0 -> 1 -> 2, test whether 0 is d-separated from 2 by 1
print(test_dsep({"-->": [(0, 1), (1, 2)]}, 0, 2, [1]))

Find more details on this example and how to use CIfly in our documentation.

Applications

Beyond fundamental tasks such as deciding d-separation, a large class of problems in causal inference can be solved flexibly using CIfly. We present a number of selected applications.

Ruletables

We believe that causal inference software should be transparent, reusable and easy-to-adapt to the users needs. At the core of our framework lie rule tables which ensure these properties. We provide ruletables for many basic primitives.

Theoretical Foundations

CIfly is based on causality-specific reductions to reachability, which we formally introduce in this paper. The mapping to the reachability input and back to the causal domain is constrained such that the overall algorithm runs in linear time.