Skip to content

Problems with old dependencies + How to fix #28

@max-hill

Description

@max-hill

Hi!

Thank you for making and sharing Dyneusr.

When attempting to get Dyneusr up and running, I started by attempting to run the code from the trefoil knot example as described in the github README. In doing so, I ran into some errors apparently involving dependencies, which I record here along with how they may be resolved, in hopes that it may be helpful to others.

To preface, I am running Python 3.11.2 in Debian 12, and I am using pip to install dependencies.

First, I began by setting up a virtual environment and using pip to install python package dependencies. This was done by running the following code from shell:

python3 -m venv ~/.virtualenvs/tda-env
source ~/.virtualenvs/tda-env/bin/activate
pip install setuptools==66.1.1 pytest==8.3.5 ipython==9.3.0 numpy==2.2.6 pandas==2.2.3 scipy==1.15.3 scikit-learn==1.6.1 matplotlib==3.10.3 seaborn==0.13.2 networkx==3.5 nilearn==0.11.1 kmapper==1.2.0 joblib==1.5.1
pip install dyneusr

The last line installs Dyneusr version 0.3.11. When installing the dependencies, I initially tried using the versions specified in this file, but I kept running into conflicts when trying to run the code, and eventually I gave up. So instead I installed the most up-to-date package versions available to me (i.e., with version numbers specified in the above code block) and hoped for the best.

At this point, the shell prompt now displays (tda-env) to indicate the active environment, and we open python in this virtual environment by running python3.

Unfortunately, running import dyneusr in the python REPL returns the following error:

  File "/home/mh/.virtualenvs/tda-env/lib/python3.11/site-packages/dyneusr/tools/graph_utils.py", line 14, in <module>
    from IPython.core.display import HTML, display
ImportError: cannot import name 'display' from 'IPython.core.display' 

This can be fixed by going into the file graph_utils.py (located in ~/.virtualenvs/tda-env/lib/python3.11/site-packages/dyneusr/tools/) and changing line 14 from

from IPython.core.display import HTML, display

to

from IPython.display import HTML, display

Great! We can now run import dyneusr without error. We can further run the following code from trefoil knot example also without error:

from dyneusr import DyNeuGraph
from dyneusr.datasets import make_trefoil
from dyneusr.tools import visualize_mapper_stages
from kmapper import KeplerMapper

# Generate synthetic dataset
dataset = make_trefoil(size=100)
X = dataset.data
y = dataset.target

# Generate shape graph using KeplerMapper
mapper = KeplerMapper(verbose=1)
lens = mapper.fit_transform(X, projection=[0])
graph = mapper.map(lens, X, nr_cubes=6, overlap_perc=0.2)

But oh no! I get an error when running the next line:

# Visualize the shape graph using DyNeuSR's DyNeuGraph
dG = DyNeuGraph(G=graph, y=y)

The error points to a line of code in the function extract_matrices in
graph_utils.py. The error message ends with:

  File "/home/mh/.virtualenvs/tda-env/lib/python3.11/site-packages/dyneusr/tools/graph_utils.py", line 420, in extract_matrices
    A = nx.to_numpy_matrix(G).A  # node x node
        ^^^^^^^^^^^^^^^^^^
AttributeError: module 'networkx' has no attribute 'to_numpy_matrix'

As with the earlier error, this error seems to arise due to changes in the dependency packages. To fix this, we make three changes to the file graph_utls.py, suggested to me by F. Nasrin:

First, change the line 420 from A = nx.to_numpy_matrix(G).A # node x node to

A =  nx.to_numpy_array(G)

Second, change line 431 from node_members = np.array(list(node_to_members.values())) to

node_members = list(node_to_members.values())

Finally, change line 460 from similar_TRs = np.hstack(node_members[similar_nodes]) to

similar_TRs = np.hstack([node_members[i] for i in similar_nodes])

Having made and saved these changes, the rest of the code from the example will run without error (after restarting python):

# Visualize the shape graph using DyNeuSR's DyNeuGraph 
dG = DyNeuGraph(G=graph, y=y)
dG.visualize('dyneusr_trefoil_knot.html', static=True, show=True)

We now have dyneusr up and running!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions