Skip to content

yasu-sh/py-tetrad

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

py-tetrad

This package shows how to make arbitrary code in Tetrad directly available in Python via JPype as part of a Python workflow. We do this by giving reusable examples of how it can be done, along with API Javadoc documentation to allow further exploration of the entire Tetrad codebase.

It also gives some simple tools that can be used in both Python and R to hide the JPype facilities for those who don't want to (or can't, in the case of R) deal directly with the Tetrad codebase.

Part of our code uses the causal-learn Python package in py-why to show how it can be integrated.

You can also integrate Tetrad code into Python by making os.system (..) calls to Causal Command; here are some examples of how to do it.

Please bear with us as we add and refine example modules and keep our code up to date. Please submit any problems or suggestions to our Issue Tracker, so that we can resolve them. In some cases it may not be obvious how to call a Tetrad class or method from Python. Please point out any difficulties you have, so that we can make it more intuitive to use for the next version.

We maintain a current version of the Tetrad launch jar, which is either the current published version or else the current published version with some adjustments. The example code will work with this current jar. Feel free to use any version of Tetrad though. All artifacts for Tetrad for the last several releases are on Maven Central, with their corresponding API Javadocs, along wth signatures to verify authenticity.

We added a method to use Tetrad algorithms in R via py-tetrad. This is work in progress.

Install

  1. It is necessary to install a JDK. For this, see our Wiki article, Setting up Java for Tetrad.

  2. If JAVA_HOME is not already set to the correct location of your Java installation above, you'll need to set JAVA_HOME to the path of the Java installation you want to use for py-tetrad.

  3. Make sure you are using the latest Python--at least 3.5--as required by JPype; if not, update it.

  4. We use causal-learn. For installation instructions, see the Docs for the causal-learn package.

  5. We use the JPype package to interface Python with Java. For installation instructions, see the Docs for the JPype box.

  6. Finally, you will need to clone this GitHub repository, so if you don't have Git installed, google and install that for your machine type.

Then (for instance, on a Mac) in a terminal window, cd to a directory where you want the cloned project to appear and type the following--again, as above, make sure JAVA_HOME is set correctly to your java path:

git clone https://github.com/cmu-phil/py-tetrad/
cd py-tetrad/pytetrad
python run_continuous.py

If everything is set up right, the last command should cause this example module to run various algorithms in Tetrad and print out result graphs. Feel free to explore other example modules in that directory.

Feel free to use your favorite method for editing and running modules.

Citation

Please cite as:

Bryan Andrews and Joseph Ramsey. https://github.com/cmu-phil/py-tetrad, 2023.

About

Makes algorithms/code in Tetrad available in Python via JPype / for proposal

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 84.5%
  • R 15.5%