giotto-ai / giotto-tda

A high-performance topological machine learning toolbox in Python
https://giotto-ai.github.io/gtda-docs
Other
847 stars 173 forks source link

gtda/mapper/tests/test_visualization.py tests failed #661

Open beew opened 1 year ago

beew commented 1 year ago

Running pytest gtda produces two failed tests.

FAILED gtda/mapper/tests/test_visualization.py::test_pipeline_cloned[False] - AssertionError
FAILED gtda/mapper/tests/test_visualization.py::test_pipeline_cloned[True] - AssertionError

More detailed outputs

==================================================================================================== FAILURES =====================================================================================================
___________________________________________________________________________________________ test_pipeline_cloned[False] ___________________________________________________________________________________________

clone_pipeline = False

    @pytest.mark.parametrize("clone_pipeline", [False, True])
    def test_pipeline_cloned(clone_pipeline):
        """Verify that the pipeline is changed on interaction if and only if
        `clone_pipeline` is False."""
        # TODO: Monitor development of the ipytest project to convert these into
        # true notebook tests integrated with pytest
        params = {
            "cover": {
                "initial": {"n_intervals": 10, "kind": "uniform",
                            "overlap_frac": 0.1},
                "new": {"n_intervals": 15, "kind": "balanced", "overlap_frac": 0.2}
                },
            "clusterer": {
                "initial": {"affinity": "euclidean"},
                "new": {"affinity": "manhattan"}
                },
            "contract_nodes": {"initial": True, "new": False},
            "min_intersection": {"initial": 4, "new": 1},
            }

        pipe = make_mapper_pipeline(
            cover=CubicalCover(**params["cover"]["initial"]),
            clusterer=FirstSimpleGap(**params["clusterer"]["initial"]),
            contract_nodes=params["contract_nodes"]["initial"],
            min_intersection=params["min_intersection"]["initial"]
            )
        fig = plot_interactive_mapper_graph(pipe, X_arr,
                                            clone_pipeline=clone_pipeline)

        # Get relevant widgets and change their states, then check final values
        for step, values in params.items():
            if step in ["cover", "clusterer"]:
                for param_name, initial_param_value in values["initial"].items():
                    new_param_value = values["new"][param_name]
>                   widgets = _get_widgets_by_trait(fig, "description", param_name)

gtda/mapper/tests/test_visualization.py:432: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
gtda/mapper/tests/test_visualization.py:336: in _get_widgets_by_trait
    for k, v in getattr(fig, widgets_attr).items():
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <ipywidgets.widgets.widget._staticproperty object at 0x7f8810bfd780>
owner_self = VBox(children=(HBox(children=(VBox(children=(HTML(value='<b>Cover parameters</b>'), Text(value='uniform', continuous_u...escriptionStyle(description_width='100px')), Checkbox(value=False, description='Show logs: ', indent=False), Output()))
owner_cls = <class 'ipywidgets.widgets.widget_box.VBox'>

    def __get__(self, owner_self, owner_cls):
>       assert owner_self is None
E       AssertionError

../../opt/python310/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:295: AssertionError
___________________________________________________________________________________________ test_pipeline_cloned[True] ____________________________________________________________________________________________

clone_pipeline = True

    @pytest.mark.parametrize("clone_pipeline", [False, True])
    def test_pipeline_cloned(clone_pipeline):
        """Verify that the pipeline is changed on interaction if and only if
        `clone_pipeline` is False."""
        # TODO: Monitor development of the ipytest project to convert these into
        # true notebook tests integrated with pytest
        params = {
            "cover": {
                "initial": {"n_intervals": 10, "kind": "uniform",
                            "overlap_frac": 0.1},
                "new": {"n_intervals": 15, "kind": "balanced", "overlap_frac": 0.2}
                },
            "clusterer": {
                "initial": {"affinity": "euclidean"},
                "new": {"affinity": "manhattan"}
                },
            "contract_nodes": {"initial": True, "new": False},
            "min_intersection": {"initial": 4, "new": 1},
            }

        pipe = make_mapper_pipeline(
            cover=CubicalCover(**params["cover"]["initial"]),
            clusterer=FirstSimpleGap(**params["clusterer"]["initial"]),
            contract_nodes=params["contract_nodes"]["initial"],
            min_intersection=params["min_intersection"]["initial"]
            )
        fig = plot_interactive_mapper_graph(pipe, X_arr,
                                            clone_pipeline=clone_pipeline)

        # Get relevant widgets and change their states, then check final values
        for step, values in params.items():
            if step in ["cover", "clusterer"]:
                for param_name, initial_param_value in values["initial"].items():
                    new_param_value = values["new"][param_name]
>                   widgets = _get_widgets_by_trait(fig, "description", param_name)

gtda/mapper/tests/test_visualization.py:432: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
gtda/mapper/tests/test_visualization.py:336: in _get_widgets_by_trait
    for k, v in getattr(fig, widgets_attr).items():
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <ipywidgets.widgets.widget._staticproperty object at 0x7f8810bfd780>
owner_self = VBox(children=(HBox(children=(VBox(children=(HTML(value='<b>Cover parameters</b>'), Text(value='uniform', continuous_u...escriptionStyle(description_width='100px')), Checkbox(value=False, description='Show logs: ', indent=False), Output()))
owner_cls = <class 'ipywidgets.widgets.widget_box.VBox'>

    def __get__(self, owner_self, owner_cls):
>       assert owner_self is None
E       AssertionError

../../opt/python310/lib/python3.10/site-packages/ipywidgets/widgets/widget.py:295: AssertionError

import platform; print(platform.platform()) Linux-5.15.0-60-generic-x86_64-with-glibc2.35

import sys; print("Python", sys.version) Python 3.10.9 (main, Feb 7 2023, 22:43:20) [GCC 11.3.0]

import numpy; print("NumPy", numpy.version) NumPy 1.23.5

import scipy; print("SciPy", scipy.version) SciPy 1.10.0

import joblib; print("Joblib", joblib.version) Joblib 1.2.0

import sklearn; print("Scikit-learn", sklearn.version) Scikit-learn 1.2.1

import gtda; print("Giotto-tda", gtda.version) Giotto-tda 0.6.0

beew commented 1 year ago

I think it is because of this that plot doesn't work.

ulupo commented 1 year ago

Thank you @beew. I'm looking into the CI to see if I can reproduce there. Meanwhile, besides unit tests issues, could you clarify what you mean by

plot doesn't work

? Namely, could you provide another code example that seems to fail?

beew commented 1 year ago

Hi,

I just tried the code from https://giotto-ai.github.io/gtda-docs/0.5.1/notebooks/plotting_api.html to test the installation.

and also this one

import sys

sys.path.append("/home/beew/opt/python310/giotto-tda/examples/data")
from generate_datasets import make_point_clouds

n_samples_per_class = 10
point_clouds, labels = make_point_clouds(n_samples_per_class, 10, 0.1)
point_clouds.shape
print(f"There are {point_clouds.shape[0]} point clouds in {point_clouds.shape[2]} dimensions, "
      f"each with {point_clouds.shape[1]} points.")

from gtda.homology import VietorisRipsPersistence

VR = VietorisRipsPersistence(homology_dimensions=[0, 1, 2])  # Parameter explained in the text
diagrams = VR.fit_transform(point_clouds)
diagrams.shape

from gtda.plotting import plot_diagram

i = 0
plot_diagram(diagrams[i])

No plot shows up.

beew commented 1 year ago

Any update?

beew commented 1 year ago

Actually the code above does produce plot in jupyter notebook, I was running it in spyder.

matteocao commented 4 months ago

dear @beew ,

I also noticed those tests failing and I could not figure out the cause. They are deactivated for now: if you ahve any idea on how to fix the issue, we would happily review your PR!