From 745c9065878df07ad626d0b8a91ebac35220f51a Mon Sep 17 00:00:00 2001 From: Nicholas Landry Date: Tue, 10 Jan 2023 10:23:31 -0500 Subject: [PATCH] Fix networkx issue (#268) * initial commit * changed python version * fixed matrix multiply --- .github/workflows/test.yml | 4 ++-- README.md | 2 +- docs/source/about.rst | 2 +- docs/source/index.rst | 2 +- long_description.rst | 2 +- requirements/default.txt | 2 +- setup.py | 4 ++-- tests/linalg/test_matrix.py | 8 +++---- xgi/algorithms/centrality.py | 4 ++-- xgi/convert.py | 45 +++++++++++++++++++++++++++++++----- xgi/linalg/matrix.py | 6 ++--- 11 files changed, 57 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 82ad443ac..26b8231f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11'] steps: - uses: actions/checkout@v2 @@ -57,7 +57,7 @@ jobs: strategy: matrix: os: [ubuntu, macos, windows] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11'] steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index 9942068fb..5af28938d 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Sign up for our [mailing list](http://eepurl.com/igE6ez) and follow XGI on [Twit - [Other Resources](#other-resources) ## Installation -XGI runs on Python 3.7 or higher. +XGI runs on Python 3.8 or higher. To install the latest version of XGI, run the following command: ```sh diff --git a/docs/source/about.rst b/docs/source/about.rst index a91df8fb8..28253ebe1 100644 --- a/docs/source/about.rst +++ b/docs/source/about.rst @@ -34,7 +34,7 @@ If that command does not work, you may try the following instead pip install -e .\[all\] -XGI was developed and tested for Python 3.7-3.10 on Mac OS, Windows, and Ubuntu. +XGI was developed and tested for Python 3.8-3.11 on Mac OS, Windows, and Ubuntu. Academic References diff --git a/docs/source/index.rst b/docs/source/index.rst index 6757101b2..af5f02a91 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -91,7 +91,7 @@ If that command does not work, you may try the following instead pip install -e .\[all\] -XGI was developed and tested for Python 3.7-3.11 on Mac OS, Windows, and Ubuntu. +XGI was developed and tested for Python 3.8-3.11 on Mac OS, Windows, and Ubuntu. Corresponding Data ================== diff --git a/long_description.rst b/long_description.rst index f68118a7c..f44445ee6 100644 --- a/long_description.rst +++ b/long_description.rst @@ -9,7 +9,7 @@ and study of the structure, dynamics, and functions of complex systems with grou Installation ------------ -XGI runs on Python 3.7 or higher. +XGI runs on Python 3.8 or higher. To install the latest version of XGI, run the following command:: diff --git a/requirements/default.txt b/requirements/default.txt index 0ed826c10..8fe957a52 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -1,6 +1,6 @@ numpy>=1.19 scipy>=1.5 pandas>=1.0 -networkx>=2.0,<3.0 +networkx>=2.7 requests>=2.0 matplotlib>=3.3 \ No newline at end of file diff --git a/setup.py b/setup.py index a4bcc2c1c..028600068 100644 --- a/setup.py +++ b/setup.py @@ -5,8 +5,8 @@ __version__ = "0.5.2" -if sys.version_info < (3, 7): - sys.exit("XGI requires Python 3.7 or later.") +if sys.version_info < (3, 8): + sys.exit("XGI requires Python 3.8 or later.") name = "xgi" diff --git a/tests/linalg/test_matrix.py b/tests/linalg/test_matrix.py index c64f26b40..26391fe2c 100644 --- a/tests/linalg/test_matrix.py +++ b/tests/linalg/test_matrix.py @@ -1,6 +1,6 @@ import numpy as np import pytest -from scipy.sparse import csr_matrix +from scipy.sparse import csr_array from scipy.sparse.linalg import norm as spnorm import xgi @@ -89,7 +89,7 @@ def test_incidence_matrix(edgelist1, edgelist3, edgelist4): assert I6[node_dict6[8], edge_dict6[3]] == 1 data = xgi.incidence_matrix(H1) - assert type(data) == csr_matrix + assert type(data) == csr_array H7 = xgi.empty_hypergraph() H7.add_nodes_from(range(8)) # disconnected node 0 @@ -158,7 +158,7 @@ def test_adjacency_matrix(edgelist1, edgelist4): node_dict2 = {k: v for v, k in node_dict.items()} data = xgi.adjacency_matrix(H2) - assert type(data) == csr_matrix + assert type(data) == csr_array for i in range(np.size(A1, axis=0)): assert A1[i, i] == 0 @@ -390,7 +390,7 @@ def test_clique_motif_matrix(edgelist4): node_dict1 = {k: v for v, k in node_dict.items()} data = xgi.clique_motif_matrix(H1) - assert type(data) == csr_matrix + assert type(data) == csr_array for i in range(np.size(W1, axis=0)): assert W1[i, i] == 0 diff --git a/xgi/algorithms/centrality.py b/xgi/algorithms/centrality.py index 8feea527e..0892f1a15 100644 --- a/xgi/algorithms/centrality.py +++ b/xgi/algorithms/centrality.py @@ -220,8 +220,8 @@ def node_edge_centrality( check = np.inf for iter in range(max_iter): - u = np.multiply(x, g(I * f(y))) - v = np.multiply(y, psi(I.T * phi(x))) + u = np.multiply(x, g(I @ f(y))) + v = np.multiply(y, psi(I.T @ phi(x))) new_x = u / norm(u) new_y = v / norm(v) diff --git a/xgi/convert.py b/xgi/convert.py index 12ac6ca7a..2154f2293 100644 --- a/xgi/convert.py +++ b/xgi/convert.py @@ -5,7 +5,16 @@ import pandas as pd from networkx.algorithms import bipartite from numpy import matrix, ndarray -from scipy.sparse import coo_matrix, csc_matrix, csr_matrix, lil_matrix +from scipy.sparse import ( + coo_array, + coo_matrix, + csc_array, + csc_matrix, + csr_array, + csr_matrix, + lil_array, + lil_matrix, +) from .classes import ( Hypergraph, @@ -84,7 +93,19 @@ def convert_to_hypergraph(data, create_using=None): from_hyperedge_dict(data, create_using) elif isinstance( - data, (ndarray, matrix, csr_matrix, csc_matrix, coo_matrix, lil_matrix) + data, + ( + ndarray, + matrix, + csr_array, + csc_array, + coo_array, + lil_array, + csr_matrix, + csc_matrix, + coo_matrix, + lil_matrix, + ), ): from_incidence_matrix(data, create_using) @@ -108,7 +129,7 @@ def convert_to_graph(H): """ A = adjacency_matrix(H) # This is unweighted by design - G = nx.from_scipy_sparse_matrix(A) + G = nx.from_scipy_sparse_array(A) G = nx.relabel_nodes(G, {i: node for i, node in enumerate(H.nodes)}) return G @@ -161,7 +182,19 @@ def convert_to_simplicial_complex(data, create_using=None): # edge dict in the form we need raise XGIError("Cannot generate SimplicialComplex from simplex dictionary") elif isinstance( - data, (ndarray, matrix, csr_matrix, csc_matrix, coo_matrix, lil_matrix) + data, + ( + ndarray, + matrix, + csr_array, + csc_array, + coo_array, + lil_array, + csr_matrix, + csc_matrix, + coo_matrix, + lil_matrix, + ), ): # incidence matrix raise XGIError( @@ -382,7 +415,7 @@ def from_incidence_matrix(d, create_using=None, nodelabels=None, edgelabels=None incidence_matrix to_incidence_matrix """ - I = coo_matrix(d) + I = coo_array(d) n, m = I.shape if nodelabels is None: @@ -447,7 +480,7 @@ def to_incidence_matrix(H, sparse=True, index=False): Returns ------- - numpy.ndarray or scipy csr_matrix + numpy.ndarray or scipy csr_array The incidence matrix dict The dictionary mapping indices to node IDs, if index is True diff --git a/xgi/linalg/matrix.py b/xgi/linalg/matrix.py index 6f71ec511..2f227c9e5 100644 --- a/xgi/linalg/matrix.py +++ b/xgi/linalg/matrix.py @@ -2,7 +2,7 @@ from warnings import warn import numpy as np -from scipy.sparse import csr_matrix, diags +from scipy.sparse import csr_array, diags __all__ = [ "incidence_matrix", @@ -40,7 +40,7 @@ def incidence_matrix( Returns ------- - I: numpy.ndarray or scipy csr_matrix + I: numpy.ndarray or scipy csr_array The incidence matrix, has dimension (n_nodes, n_edges) rowdict: dict The dictionary mapping indices to node IDs, if index is True @@ -85,7 +85,7 @@ def incidence_matrix( data.append(0) rows.append(node_dict[node]) cols.append(edge_dict[edge]) - I = csr_matrix((data, (rows, cols))) + I = csr_array((data, (rows, cols))) else: # Create an np.matrix I = np.zeros((num_nodes, num_edges), dtype=int)