paulrolland1307 / SCORE

Code used in the paper "Score matching enables causal discovery of nonlinear additive noise models", Rolland et al., ICML 2022
GNU Affero General Public License v3.0
14 stars 4 forks source link

Install procedure / requirements file #1

Closed fred887 closed 7 months ago

fred887 commented 1 year ago

Hello,

I am struggling installing the source code with the proper packages using conda. Would you have some install procedure or requirements file that could help me? Thank you for your help, Bests,

paulrolland1307 commented 1 year ago

Hello,

what package in particular are you struggling with ? Can you send me the kind of error you get when trying to run the demo code ?

Paul


De : fred887 @.***> Envoyé : mercredi 26 juillet 2023 15:36:37 À : paulrolland1307/SCORE Cc : Subscribed Objet : [paulrolland1307/SCORE] Install procedure / requirements file (Issue #1)

Hello,

I am struggling installing the source code with the proper packages using conda. Would you have some install procedure or requirements file that could help me? Thank you for your help, Bests,

— Reply to this email directly, view it on GitHubhttps://github.com/paulrolland1307/SCORE/issues/1, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADNORFE2W4Y6PBNHTGN76UTXSEMOLANCNFSM6AAAAAA2YTNCRA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

fred887 commented 1 year ago

Hello, by reproducing my install procedure in order to understand precisely the part where my install failed, I have made some progresses.

In fact now, demo_SCORE.py is running almost entirely. There is still the last step of SID computation that crashes because I could not install the SID R package, but this is an issue with the cdt package, not with your source code.

So, if I remove the computation of the SID, then demo_SCORE.py is finally running without crashing.

If you have some hints about installing the SID R package, they will be welcome (as I am not using a cdt docker and I have not installed R with apt-get, I cannot use the solutions proposed in the github of cdt, moreover the SID package has been removed from the CRAN repository and installing from the provided archive raised several dependency issues that I have not solved yet - I am not very familiar with R...).

Anyway, here is my install procedure, maybe it will help others:

1) Install the python packages inside a conda environment

conda create -n env_score python=3.8
conda activate env_score

conda install -c conda-forge cdt
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch
conda install -c conda-forge gpy
conda install -c conda-forge python-igraph

2) Add the missing folder R_templates to the cdt package installed in the conda environment

Because the file R_templates/test_import.R is needed to run demo_SCORE.py.

Strangely this folder is not present in the cdt package from conda but is present inside the github repository. So I got it there:

git clone https://github.com/FenTechSolutions/CausalDiscoveryToolbox.git

cp -r <my_src_path>/CausalDiscoveryToolbox/cdt/utils/R_templates <my_conda_path>/miniconda3/envs/env_score/lib/python3.8/site-packages/cdt/utils/

3) Install R inside another conda environment

conda create -n env_R 
conda activate env_R

conda install -c r r r-essentials

4) Set the rpath variable for the cdt package inside demo_SCORE.py

Add the next line at the top of the file, after import cdt:

cdt.SETTINGS.rpath = '<my_conda_path>/miniconda3/envs/env_R/bin/Rscript'

5) Comment the call to the SID R package in demo_SCORE.py

# print("SID: {}".format(int(cdt.metrics.SID(target=adj, pred=A_SCORE))))
cmaspi commented 10 months ago

It is a good practice to include a requirements.txt or equivalent!