FlowModelingControl / flowtorch

flowTorch - a Python library for analysis and reduced-order modeling of fluid flows
GNU General Public License v3.0
131 stars 45 forks source link

Segmentation fault for CNM #31

Closed jacktang closed 2 years ago

jacktang commented 2 years ago

Hello,

I run the demo of CNM (https://flowmodelingcontrol.github.io/flowtorch-docs/1.1/notebooks/cnm_cylinder.html) and some segmentation fault error comes up:

[1]    14357 segmentation fault  python3 03-cnm.py

Maybe the problem is recorded in https://github.com/FlowModelingControl/flowtorch/issues/26. And my dataset is minimal dataset.

AndreWeiner commented 2 years ago

Hi @jacktang, thanks for bringing up this issue. It would be helpful if you could provide some more details since I can't reproduce the error on my system. If you execute the notebook cell-by-cell, in which cell does the seg-fault happen? Can you also provide the installed versions of NumPy and ScikitLearn? E.g.:

>>> import numpy
>>> import sklearn
>>> numpy.__version__
1.22.3
>>> sklearn.__version__
1.1.2

Edit: yes, the problem is related to the minimal dataset. Most tutorials require the full dataset. The minimal dataset is only for unit testing.

Best, Andre

jacktang commented 2 years ago
>>> numpy.__version__
1.22.4
>>> sklearn.__version__
1.1.2

my OS is macOS Monterey 12.5.1

AndreWeiner commented 2 years ago

As mentioned above, you will have to download the full dataset to make the tutorial work. Nonetheless, there should be a warning/exception due to insufficient data to avoid the seg fault. Best, Andre

jacktang commented 2 years ago

Hello @AndreWeiner, I located the statement of causing segentation fault: https://github.com/FlowModelingControl/flowtorch/blob/main/flowtorch/rom/cnm.py#L106

      self._cluster = KMeans(n_clusters, **cluster_config).fit(
           reduced_state.T.numpy()  # batch dimension comes first in Scikit-Learn
        )

And the related issue on sklearn package: https://github.com/scikit-learn/scikit-learn/issues/23574

AndreWeiner commented 2 years ago

Hi @jacktang, thank you for digging into this. It appears to be a problem related to OpenMP and Blas on MacOS. Maybe an update can solve the problem:

python3 -m pip install --upgrade pip
pip3 install -U threadpoolctl scikit-learn

Not sure if the commands work out-of-the-box since I never used a Mac. Another workaround would be using a virtual environment created with, e.g., conda or venv. Cheers

jacktang commented 2 years ago

@AndreWeiner Thanks! I've gave up and switched to linux box 🥲, and it worked fine.