GUDHI / TDA-tutorial

A set of jupyter notebooks for the practice of TDA with the python Gudhi library together with popular machine learning and data sciences libraries.
MIT License
378 stars 114 forks source link

not finding POT #57

Open Estudiant-roqueta opened 2 years ago

Estudiant-roqueta commented 2 years ago

I have POT, pymanopt autograd following POT instructions in https://pythonot.github.io/index.html. I made git clone of this github to try the tutorials and so. everything installed, most of them work. But when I try to run Tuto-GUDHI-Barycenters-of-persistence.diagrams.ipyb when it calls bary this happens:

b, log = bary(diags, init=0, verbose=True) # we initialize our estimation on the first diagram (the red one.)

NameError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_10868/2194333359.py in ----> 1 b, log = bary(diags, 2 init=0, 3 verbose=True) # we initialize our estimation on the first diagram (the red one.)

~\anaconda3\lib\site-packages\gudhi\wasserstein\barycenter.py in lagrangian_barycenter(pdiagset, init, verbose) 92 # the points of Y. 93 # If points disappear, there thrown ---> 94 # on [0,0] by default. 95 new_created_points = [] # will store potential new points. 96

~\anaconda3\lib\site-packages\gudhi\wasserstein\wasserstein.py in wasserstein_distance(X, Y, matching, order, internal_p, enable_autodiff, keep_essential_parts) 319 if matching: 320 assert not enable_autodiff, "matching and enable_autodiff are currently incompatible" --> 321 P = ot.emd(a=a,b=b,M=M, numItermax=2000000) 322 ot_cost = np.sum(np.multiply(P,M)) 323 P[-1, -1] = 0 # Remove matching corresponding to the diagonal

NameError: name 'ot' is not defined

I revised the files and they import OT correctly. I even tried to put "import ot" in the exact subprocess but even then it does not recognize it.

VincentRouvreau commented 2 years ago

@Estudiant-roqueta As you have conda, here is the list of commands that works for me:

conda create -n tda-tutorial
conda activate tda-tutorial
conda install -c conda-forge python
which python  # check it is somewhere in .../envs/tda-tutorial/...
pip install -r .binder/requirements.txt
pip install jupyter
jupyter notebook

And from here, barycenter notebook works fine for me (with gudhi 3.5.0).

It seems to you have a python kernel in your notebook that is not the one with which you installed pot or something like that. If you import ot in a notebook cell, do you have any error ? And what if you do import gudhi.wasserstein in a notebook cell ?

bghattas commented 1 year ago

I have a similar error when calling the barry function

b, log = bary(diags, init=0, verbose=True) # we initialize our estimation on the first diagram (the red one.) in the Tuto-GUDHI-Barycenters-of-persistence-diagrams notebook.

I am running the notebook through google collab, i have installed the pot module and "import ot" executes without warning.. Nevertheless, i have the following error

NameError Traceback (most recent call last) in <cell line: 1>() ----> 1 b, log = bary(diags, 2 init=0, 3 verbose=True) # we initialize our estimation on the first diagram (the red one.)

1 frames /usr/local/lib/python3.10/dist-packages/gudhi/wasserstein/wasserstein.py in wasserstein_distance(X, Y, matching, order, internal_p, enable_autodiff, keep_essential_parts) 319 if matching: 320 assert not enable_autodiff, "matching and enable_autodiff are currently incompatible" --> 321 P = ot.emd(a=a,b=b,M=M, numItermax=2000000) 322 ot_cost = np.sum(np.multiply(P,M)) 323 P[-1, -1] = 0 # Remove matching corresponding to the diagonal

NameError: name 'ot' is not defined

mglisse commented 1 year ago

I just tried on google colab, I added a code cell with !pip install POT gudhi at the beginning of the notebook, and it ran just fine...

bghattas commented 1 year ago

thank you @mglisse, i had only to reinitialise my session for that to work !