AlxndrMlk/blogs-code

Bug in "Beyond the basics - Causal Discovery (causalpython.io).ipynb" ?

JuergenKanz opened this issue · 5 comments

I tried to run your notebook "Beyond the basics - Causal Discovery (causalpython.io).ipynb".
Three attribute errors occurred:

  1. true_dag = DAG.scale_free(n_nodes=10, n_edges=15, seed=18)
  2. B_und = DAG._graph_to_adjmat(G_und) in File "e:\anaconda3\lib\site-packages\castle\datasets\simulator.py:184, in DAG.scale_free(n_nodes, n_edges, weight_range, seed)"
  3. return nx.to_numpy_matrix(G) in File "e:\anaconda3\lib\site-packages\castle\datasets\simulator.py:64, in DAG._graph_to_adjmat(G)" with the message: "module 'networkx' has no attribute 'to_numpy_matrix'"

I have installed "castle version 1.0.3" and "networkx 3.0".

I hope this will help for further improvement.

Hi @JuergenKanz

Thank you for opening the issue. I appreciate it!

I added the missing conda environment file and environment installation instructions.

Can you confirm if the code works for you when you follow the instructions from newly added README.md

Hi @AlxndrMlk

Yes, the newly added instructions are working. Thanks for support.

Happy to hear that @JuergenKanz

Thank you for the contribution!

Hi @AlxndrMlk

Please forgive me, but I dislike to work with different Python environments. Hence, I checked what I can do to work with the latest versions of all needed packages. My described problem above is related to the latest networkx = 3.0 version. As already mentioned, the attribute error "module 'networkx' has no attribute 'to_numpy_matrix'" is the issue. 'to_numpy_matrix' is replaced in networkx 3.0 with 'to_numpy_array'.
Therefore, I replaced in Line 64 and Line 563, 'to_numpy_matrix' with 'to_numpy_array' in file E:\anaconda3\Lib\site-packages\castle\datasets\simulator.py
Your notebook is now running perfectly even with the latest package versions. Please don't hesitate to share this information with your readers.

Thank you for the update @JuergenKanz

I understand that you don't like to work with Python environments. Thank you for sharing your opinion and recommendations.

I am closing the issue now. If there's anything more I can do for you, feel free to let me know.