FenTechSolutions / CausalDiscoveryToolbox

Package for causal inference in graphs and in the pairwise settings. Tools for graph structure recovery and dependencies are included.
https://fentechsolutions.github.io/CausalDiscoveryToolbox/html/index.html
MIT License
1.08k stars 198 forks source link

PC.predict(data) RuntimeError: RProcessError #130

Closed amnesicloud closed 2 years ago

amnesicloud commented 2 years ago

hi,

I was running following script on my dataset(variable 'data'),

import networkx as nx from cdt.causality.graph import PC from cdt.data import load_dataset data, graph = load_dataset("sachs") obj = PC() output = obj.predict(data)

when this occurs:

R Python Error Output

[Errno 2] No such file or directory: '/tmp/cdt_pc_fcb4fbae-5fbf-4b63-9e37-8e92bdbe4e9b/result.csv'

RuntimeError Traceback (most recent call last)

in ----> 1 output = obj.predict(data) /opt/conda/envs/rapids/lib/python3.7/site-packages/cdt/causality/graph/model.py in predict(self, df_data, graph, **kwargs) 61 """ 62 if graph is None: ---> 63 return self.create_graph_from_data(df_data, **kwargs) 64 elif isinstance(graph, nx.DiGraph): 65 return self.orient_directed_graph(df_data, graph, **kwargs) /opt/conda/envs/rapids/lib/python3.7/site-packages/cdt/causality/graph/PC.py in create_graph_from_data(self, data, **kwargs) 276 self.arguments['{VERBOSE}'] = str(self.verbose).upper() 277 --> 278 results = self._run_pc(data, verbose=self.verbose) 279 280 return nx.relabel_nodes(nx.DiGraph(results), /opt/conda/envs/rapids/lib/python3.7/site-packages/cdt/causality/graph/PC.py in _run_pc(self, data, fixedEdges, fixedGaps, verbose) 313 except Exception as e: 314 rmtree(run_dir) --> 315 raise e 316 except KeyboardInterrupt: 317 rmtree(run_dir) /opt/conda/envs/rapids/lib/python3.7/site-packages/cdt/causality/graph/PC.py in _run_pc(self, data, fixedEdges, fixedGaps, verbose) 309 310 pc_result = launch_R_script(Path("{}/R_templates/pc.R".format(os.path.dirname(os.path.realpath(__file__)))), --> 311 self.arguments, output_function=retrieve_result, verbose=verbose) 312 # Cleanup 313 except Exception as e: /opt/conda/envs/rapids/lib/python3.7/site-packages/cdt/utils/R.py in launch_R_script(template, arguments, output_function, verbose, debug) 219 print("\nR Python Error Output \n-----------------------\n") 220 print(e) --> 221 raise RuntimeError("RProcessError \nR Process Error Output \n-----------------------\n" + str(err, "ISO-8859-1")) from None 222 print("\nR Python Error Output \n-----------------------\n") 223 print(e) RuntimeError: RProcessError R Process Error Output ----------------------- 载入需要的程辑包:momentchi2 载入需要的程辑包:MASS Error in cor(X) : 'x' 必需是数值 Calls: runPC -> cor 停止执行 it seems that cdt was looking for a temporary file which does not exist.
amnesicloud commented 2 years ago
image
diviyank commented 2 years ago

Hello,

It's the R process that failed ( the file error you see comes from the python that tries to fetch the results from R, that do no exist since the script failed. However, the R Error seems cryptic... Do you have any more info?

amnesicloud commented 2 years ago

hi,

what kind of info would you need? I'm using R 4.1.1, prior using cdt I installed RCIT / pcalg / kpcalg and their dependencies.

I was using a company's server (probably a docker), and I was using jupyter to run the code above. I'm not familiar with the docker thing, but I'm not able to execute sudo command in that environment, could the docker environment cause the path error?

amnesicloud commented 2 years ago

before installing R 4.1.1, I installed R 3.4.4, then I found out some of the dependencies were not available for R 3.4, the I download R 4.1.1 and update all previous packages. (without uninstall R 3.4)

amnesicloud commented 2 years ago

it seems there are categorical variables involved, and pc requires numerical variables. thanks, and sorry for taking your time.