DavidLapous / multipers

Python library for multipersistence
https://davidlapous.github.io/multipers/
MIT License
15 stars 2 forks source link

Mac M1/M2/M? support #13

Open yossibokorbleile opened 4 months ago

yossibokorbleile commented 4 months ago

Hiya! Mac M1/M2/... are not compatible with CUDA, and so KeOps does not work. I keep getting

[KeOps] Warning : Cuda libraries were not detected on the system or could not be loaded ; using cpu only mode
[pyKeOps] Compiling pykeops cpp 25c52bb6f5 module ... 
[KeOps] Warning : There were warnings or errors :
g++: error: unrecognized command-line option '-Xclang'

OK

when I run

points = mp.data.three_annulus(5000,5000)
grades = - KDE(bandwidth=.1, return_log=True).fit(points).score_samples(points)

in the function_delaunay_test.ipynb notebook.

DavidLapous commented 4 months ago

Hey @yossibokorbleile, thanks for pointing that out;

First (unrelated) thing, I'm not really maintaining the notebooks in the tutorial folder anymore, as IIRC, they are all in the documentation in the docs/notebooks folder. I'm planning to remove this folder after checking that everything is in the doc.

For PyKeops on ARM + macOS, this is not linked with cuda and should work fine, but I opened an issue for a very similar problem (cf getkeops/keops#332) which was solved then, I hope what's in there helps you fix this. Otherwise, feel free to open an issue there, I don't own a mac anymore, so it's hard for me to debug this.

You can also try to launch this with the conda install cxx-compiler installed.

In the meantime, the KDE can be completely replaced by

from sklearn.neighbors import KernelDensity as KDE

This will be slower and not pytorch-auto-differentiable, but should work fine otherwise.

yossibokorbleile commented 4 months ago

Thanks!

Replacing KDE worked initially, until I tried

(simplextree,), = mmp.PointCloud2SimplexTree(expand_dim=2,bandwidths=[0.2], num_collapses="full", threshold=2, complex='rips').fit_transform([X])

in multipers_intro.ipynb.

I will just continue with testing functionality, and ignore anything KeOps related.

DavidLapous commented 4 months ago

Yes, this specific pipeline doesn't really have a non-keops alternative, but you can replace bandwidths by masses, which doesn't require keops, and should produce somehow similar pictures. This basically replaces a Gaussian Kernel Density Estimation (KDE) by the Distance To Measure (DTM), c.f., e.g., this tda paper.

I also forgot to mention that the GitHub workflow tests this pipeline on a mac with an M1 chip, and works fine with pykeops, with the default apple clang compiler. Can you try using the default compiler instead of gcc ?