Skip to content

teaspoon.DAF.data_assimilation crashes on import after plain "pip install teaspoon" => unguarded from gudhi.tensorflow import RipsLayer on line 3 defeats the developer's own tensorflow try/except #197

@OmerJauhar

Description

@OmerJauhar

teaspoon.DAF.data_assimilation fails to import on default install because of unguarded TensorFlow import

After a plain pip install teaspoon, importing anything from teaspoon.DAF.data_assimilation fails, including rafda, which does not use TensorFlow.

Reproduction

python -m venv .test
source .test/bin/activate
pip install teaspoon
python -c "from teaspoon.DAF.data_assimilation import TADA"

Output

File ".../teaspoon/DAF/data_assimilation.py", line 3, in <module>
    from gudhi.tensorflow import RipsLayer
File ".../gudhi/tensorflow/__init__.py", line 1, in <module>
    from .cubical_layer import CubicalLayer
File ".../gudhi/tensorflow/cubical_layer.py", line 14, in <module>
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

Root cause

data_assimilation.py has two TensorFlow-related imports. The second one (lines 9-13) is correctly guarded:

try:
    import tensorflow as tf
    from tensorflow import keras
except:
    raise ImportError("TADA Requires tensorflow for optimization")

However, the first import on line 3 is unguarded and executes before the try/except block:

from gudhi.tensorflow import RipsLayer

gudhi.tensorflow internally imports TensorFlow, so it has the same dependency requirement. Because of this, the module crashes before reaching the guarded import block.

Impact

  • TADA is unusable on a default install.
  • rafda is also unusable even though it does not require TensorFlow, because the module-level import failure prevents importing anything from data_assimilation.

Suggested fix

Move the RipsLayer import inside the existing try/except block:

try:
    import tensorflow as tf
    from tensorflow import keras
    from gudhi.tensorflow import RipsLayer
except ImportError:
    raise ImportError(
        "TADA requires tensorflow. "
        "Install with: pip install 'teaspoon[full]'"
    )

Environment

  • teaspoon==1.5.30
  • Python 3.10.12
  • Fresh virtual environment with no TensorFlow installed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions