From 33e4164a02ebd9f6f5d0d0b8dc01e71f4e2d07f1 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 22:17:49 +0100 Subject: [PATCH 01/23] first try moved infomap, leidenalg, karate to be optional --- cdlib/algorithms/crisp_partition.py | 90 +++++++++++++++++++++++------ requirements.txt | 3 - requirements_complete.txt | 4 ++ requirements_optional.txt | 2 - 4 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 requirements_complete.txt diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 075a2b11..7d88d599 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -1,11 +1,15 @@ +missing_packages={} + try: import infomap as imp except ModuleNotFoundError: + missing_packages.append("infomap") imp = None try: from wurlitzer import pipes except ModuleNotFoundError: + missing_packages.append("wurlitzer") pipes = None try: @@ -16,20 +20,32 @@ try: import leidenalg except ModuleNotFoundError: + missing_packages.append("leidenalg") leidenalg = None try: import graph_tool.all as gt except ModuleNotFoundError: + missing_packages.append("graph_tool") gt = None +try: + import karateclub as kc + from karateclub import EdMot, GEMSEC, SCD +except ModuleNotFoundError: + missing_packages.append("karateclub") + kc = None + +if len(missing_packages)>0: + warnings.warn( + "Note: to be able to use all methods, you need to install some additional packages: "+missing_packages + ) import warnings import numpy as np from typing import Callable from copy import deepcopy from cdlib.algorithms.internal import DER import community as louvain_modularity -import warnings from collections import defaultdict from cdlib import NodeClustering, FuzzyNodeClustering from cdlib.algorithms.internal.belief_prop import detect_belief_communities @@ -68,7 +84,6 @@ except ModuleNotFoundError: pycombo_part = None -from karateclub import EdMot, GEMSEC, SCD import markov_clustering as mc from chinese_whispers import chinese_whispers as cw from chinese_whispers import aggregate_clusters @@ -570,10 +585,13 @@ def leiden( """ if ig is None or leidenalg is None: - raise ModuleNotFoundError( - "Optional dependency not satisfied: install igraph and leidenalg to use the " - "selected feature." - ) + try: + import leidenalg + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install igraph and leidenalg to use the " + "selected feature." + ) g = convert_graph_formats(g_original, ig.Graph) @@ -1051,13 +1069,19 @@ def infomap(g_original: object, flags: str = "") -> NodeClustering: """ if imp is None: - raise ModuleNotFoundError( - "Optional dependency not satisfied: install infomap to use the selected feature." - ) + try: + import infomap as imp + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install infomap to use the selected feature." + ) if pipes is None: - raise ModuleNotFoundError( - "Optional dependency not satisfied: install package wurlitzer to use infomap." - ) + try: + from wurlitzer import pipes + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install package wurlitzer to use infomap." + ) g = convert_graph_formats(g_original, nx.Graph, directed=g_original.is_directed()) @@ -1499,12 +1523,15 @@ def sbm_dl_nested( .. note:: Implementation from graph-tool library, please report to https://graph-tool.skewed.de for details """ if gt is None: - raise Exception( - "===================================================== \n" - "The graph-tool library seems not to be installed (or incorrectly installed). \n" - "Please check installation procedure there https://git.skewed.de/count0/graph-tool/wikis/installation-instructions#native-installation \n" - "on linux/mac, you can use package managers to do so(apt-get install python3-graph-tool, brew install graph-tool, etc.)" - ) + try: + import graph_tool.all as gt + except ModuleNotFoundError: + raise Exception( + "===================================================== \n" + "The graph-tool library seems not to be installed (or incorrectly installed). \n" + "Please check installation procedure there https://git.skewed.de/count0/graph-tool/wikis/installation-instructions#native-installation \n" + "on linux/mac, you can use package managers to do so(apt-get install python3-graph-tool, brew install graph-tool, etc.)" + ) gt_g = convert_graph_formats(g_original, nx.Graph) gt_g, label_map = __from_nx_to_graph_tool(gt_g) state = gt.minimize_nested_blockmodel_dl(gt_g) @@ -1717,6 +1744,15 @@ def edmot( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + if kc is None: + try: + from karateclub import EdMot, GEMSEC, SCD + kc=True + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install karateclub to use the selected feature." + ) + g = convert_graph_formats(g_original, nx.Graph) model = EdMot(component_count=2, cutoff=10) @@ -2360,6 +2396,15 @@ def gemsec( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + if kc is None: + try: + from karateclub import EdMot, GEMSEC, SCD + kc = True + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install karateclub to use the selected feature." + ) + g = convert_graph_formats(g_original, nx.Graph) model = GEMSEC( walk_number=walk_number, @@ -2438,6 +2483,15 @@ def scd( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + if kc is None: + try: + from karateclub import EdMot, GEMSEC, SCD + kc=True + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install karateclub to use the selected feature." + ) + g = convert_graph_formats(g_original, nx.Graph) model = SCD(iterations=iterations, eps=eps, seed=seed) model.fit(g) diff --git a/requirements.txt b/requirements.txt index ee42ae70..f3caa8c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,16 +12,13 @@ pulp seaborn pandas eva_lcd -karateclub bimlpa markov_clustering chinese_whispers python-igraph -leidenalg angel-cd pooch dynetx -infomap wurlitzer thresholdclustering pyclustering diff --git a/requirements_complete.txt b/requirements_complete.txt new file mode 100644 index 00000000..df761dd4 --- /dev/null +++ b/requirements_complete.txt @@ -0,0 +1,4 @@ +karateclub +leidenalg +infomap +wurlitzer \ No newline at end of file diff --git a/requirements_optional.txt b/requirements_optional.txt index d90da8d1..570f339a 100644 --- a/requirements_optional.txt +++ b/requirements_optional.txt @@ -1,5 +1,3 @@ -infomap>=1.3.0 -wurlitzer>=1.0.2 GraphRicciCurvature==0.5.2.1 networkit pycombo From 02b4189256a4da6f9a2ce1185fb41cc2f852b88e Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 22:31:39 +0100 Subject: [PATCH 02/23] fix --- cdlib/algorithms/crisp_partition.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 7d88d599..200e810b 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -1,4 +1,4 @@ -missing_packages={} +missing_packages=set() try: import infomap as imp @@ -2491,7 +2491,7 @@ def scd( raise ModuleNotFoundError( "Optional dependency not satisfied: install karateclub to use the selected feature." ) - + g = convert_graph_formats(g_original, nx.Graph) model = SCD(iterations=iterations, eps=eps, seed=seed) model.fit(g) From b43c614902d94b3031cb32fc11c8a526dbe9ce62 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 22:34:24 +0100 Subject: [PATCH 03/23] bug fix --- cdlib/algorithms/crisp_partition.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 200e810b..1f2421e8 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -3,13 +3,13 @@ try: import infomap as imp except ModuleNotFoundError: - missing_packages.append("infomap") + missing_packages.add("infomap") imp = None try: from wurlitzer import pipes except ModuleNotFoundError: - missing_packages.append("wurlitzer") + missing_packages.add("wurlitzer") pipes = None try: @@ -20,20 +20,20 @@ try: import leidenalg except ModuleNotFoundError: - missing_packages.append("leidenalg") + missing_packages.add("leidenalg") leidenalg = None try: import graph_tool.all as gt except ModuleNotFoundError: - missing_packages.append("graph_tool") + missing_packages.add("graph_tool") gt = None try: import karateclub as kc from karateclub import EdMot, GEMSEC, SCD except ModuleNotFoundError: - missing_packages.append("karateclub") + missing_packages.add("karateclub") kc = None if len(missing_packages)>0: From a94bcb2a5eaa855bb5a5416c07fd4396a422d7f7 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 22:38:45 +0100 Subject: [PATCH 04/23] bug fix --- cdlib/algorithms/crisp_partition.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 1f2421e8..2f0dcd7c 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -36,11 +36,12 @@ missing_packages.add("karateclub") kc = None +import warnings + if len(missing_packages)>0: warnings.warn( "Note: to be able to use all methods, you need to install some additional packages: "+missing_packages ) -import warnings import numpy as np from typing import Callable from copy import deepcopy From 2ba178ce3061ebae0a080a288cbd003459384fab Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 22:39:51 +0100 Subject: [PATCH 05/23] bug fix --- cdlib/algorithms/crisp_partition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 2f0dcd7c..f27a4c15 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -40,7 +40,7 @@ if len(missing_packages)>0: warnings.warn( - "Note: to be able to use all methods, you need to install some additional packages: "+missing_packages + "Note: to be able to use all methods, you need to install some additional packages: "+ str(missing_packages) ) import numpy as np from typing import Callable From 60e2c5b1789790b757d8c243b2243e919607dd58 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 22:52:13 +0100 Subject: [PATCH 06/23] added overlapping karateclub --- cdlib/algorithms/overlapping_partition.py | 43 +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index e8734377..ad972498 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -1,3 +1,22 @@ +missing_packages=set() + +def try_load_karate(init=False): + global kc + if kc is None: + try: + from karateclub import DANMF, EgoNetSplitter, NNSED, MNMF, BigClam, SymmNMF + kc=True + except ModuleNotFoundError: + if init==False: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install karateclub to use the selected feature." + ) + +kc=None +try_load_karate(init=True) +if kc==None: + missing_packages.add("karateclub") + try: import igraph as ig except ModuleNotFoundError: @@ -12,6 +31,16 @@ except ModuleNotFoundError: ASLPAw = None + +import warnings + +if len(missing_packages)>0: + warnings.warn( + "Note: to be able to use all methods, you need to install some additional packages: "+ str(missing_packages) + ) + + + from random import sample from demon import Demon from cdlib.algorithms.internal.NodePerception import NodePerception @@ -31,7 +60,6 @@ from cdlib.algorithms.internal.PercoMCV import percoMVC from cdlib.algorithms.internal.LPAM import LPAM from cdlib.algorithms.internal.core_exp import findCommunities as core_exp_find -from karateclub import DANMF, EgoNetSplitter, NNSED, MNMF, BigClam, SymmNMF from cdlib.algorithms.internal.weightedCommunity import weightedCommunity from cdlib.algorithms.internal.LPANNI import LPANNI, GraphGenerator from cdlib.algorithms.internal.DCS import main_dcs @@ -878,7 +906,7 @@ def big_clam( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - + try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = BigClam( @@ -949,6 +977,10 @@ def danmf( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + + try_load_karate() + + g = convert_graph_formats(g_original, nx.Graph) model = DANMF(layers, pre_iterations, iterations, seed, lamb) @@ -1012,6 +1044,8 @@ def egonet_splitter(g_original: object, resolution: float = 1.0) -> NodeClusteri .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + try_load_karate() + g = convert_graph_formats(g_original, nx.Graph) model = EgoNetSplitter(resolution=resolution) @@ -1074,6 +1108,9 @@ def nnsed( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + + try_load_karate() + g = convert_graph_formats(g_original, nx.Graph) model = NNSED(dimensions=dimensions, iterations=iterations, seed=seed) model.fit(g) @@ -1148,6 +1185,7 @@ def mnmf( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = MNMF( dimensions=dimensions, @@ -1601,6 +1639,7 @@ def symmnmf( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = SymmNMF(dimensions=dimensions, iterations=iterations, rho=rho, seed=seed) model.fit(g) From ead627d7d5022b2fbb61f4a4407a0f01efe9318c Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 22:56:01 +0100 Subject: [PATCH 07/23] bug fix --- cdlib/algorithms/crisp_partition.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index f27a4c15..ac30f212 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -39,9 +39,8 @@ import warnings if len(missing_packages)>0: - warnings.warn( - "Note: to be able to use all methods, you need to install some additional packages: "+ str(missing_packages) - ) + print("Note: to be able to use all methods, you need to install some additional packages: ", missing_packages) + import numpy as np from typing import Callable from copy import deepcopy From f42bcecf005ac5e4100a46fe1eb89ef673197314 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 23:02:08 +0100 Subject: [PATCH 08/23] louvain_fix colab --- cdlib/algorithms/crisp_partition.py | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index ac30f212..23081378 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -40,7 +40,7 @@ if len(missing_packages)>0: print("Note: to be able to use all methods, you need to install some additional packages: ", missing_packages) - + import numpy as np from typing import Callable from copy import deepcopy diff --git a/requirements.txt b/requirements.txt index f3caa8c4..d9706db6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ scikit-learn tqdm networkx>=2.4 demon -python-louvain +python-louvain>=0.16 nf1 scipy pulp From 9dd928b2b7918aeed29ccf0660fd3bc0b15d518d Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 23:08:19 +0100 Subject: [PATCH 09/23] louvain update --- cdlib/algorithms/crisp_partition.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 23081378..d2b581c7 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -45,7 +45,8 @@ from typing import Callable from copy import deepcopy from cdlib.algorithms.internal import DER -import community as louvain_modularity +#import community as louvain_modularity +from community import community_louvain from collections import defaultdict from cdlib import NodeClustering, FuzzyNodeClustering from cdlib.algorithms.internal.belief_prop import detect_belief_communities @@ -524,7 +525,7 @@ def louvain( g = convert_graph_formats(g_original, nx.Graph) - coms = louvain_modularity.best_partition( + coms = community_louvain.best_partition( g, weight=weight, resolution=resolution, randomize=randomize ) From ef84d37de96fc905ae7037799ad14c1e64db09ce Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 23:12:41 +0100 Subject: [PATCH 10/23] bug fix --- cdlib/algorithms/crisp_partition.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index d2b581c7..2e6cfcdb 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -1068,7 +1068,7 @@ def infomap(g_original: object, flags: str = "") -> NodeClustering: .. note:: Infomap Python API documentation: https://mapequation.github.io/infomap/python/ """ - + global imp,pipes if imp is None: try: import infomap as imp From b128bf9f7cc88ce65df2e6505f477992b71a06c9 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 23:21:45 +0100 Subject: [PATCH 11/23] bug fix --- cdlib/algorithms/crisp_partition.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 2e6cfcdb..a3619357 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -584,7 +584,7 @@ def leiden( .. note:: Reference implementation: https://github.com/vtraag/leidenalg """ - + global leidenalg if ig is None or leidenalg is None: try: import leidenalg @@ -1744,7 +1744,7 @@ def edmot( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - + global kc if kc is None: try: from karateclub import EdMot, GEMSEC, SCD @@ -2397,6 +2397,7 @@ def gemsec( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + global kc if kc is None: try: from karateclub import EdMot, GEMSEC, SCD From 6112ea62f0e8f6a44f7ea608d389813784e26d50 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Wed, 2 Mar 2022 23:54:58 +0100 Subject: [PATCH 12/23] bug fix --- cdlib/algorithms/crisp_partition.py | 1 + cdlib/algorithms/overlapping_partition.py | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index a3619357..313ce7f5 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -2485,6 +2485,7 @@ def scd( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + global kc if kc is None: try: from karateclub import EdMot, GEMSEC, SCD diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index ad972498..441875e7 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -34,10 +34,7 @@ def try_load_karate(init=False): import warnings -if len(missing_packages)>0: - warnings.warn( - "Note: to be able to use all methods, you need to install some additional packages: "+ str(missing_packages) - ) + From 70a145a842e83afccbd26aef84e4e9755ef87f29 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Thu, 3 Mar 2022 00:03:44 +0100 Subject: [PATCH 13/23] bug fix --- cdlib/algorithms/crisp_partition.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 313ce7f5..1bd7d600 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -30,17 +30,16 @@ gt = None try: - import karateclub as kc - from karateclub import EdMot, GEMSEC, SCD + import karateclub except ModuleNotFoundError: missing_packages.add("karateclub") - kc = None import warnings if len(missing_packages)>0: print("Note: to be able to use all methods, you need to install some additional packages: ", missing_packages) +import sys import numpy as np from typing import Callable from copy import deepcopy @@ -1744,18 +1743,16 @@ def edmot( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - global kc - if kc is None: + if "karateclub" not in sys.modules: try: - from karateclub import EdMot, GEMSEC, SCD - kc=True + import karateclub except ModuleNotFoundError: raise ModuleNotFoundError( "Optional dependency not satisfied: install karateclub to use the selected feature." ) g = convert_graph_formats(g_original, nx.Graph) - model = EdMot(component_count=2, cutoff=10) + model = karateclub.EdMot(component_count=2, cutoff=10) model.fit(g) members = model.get_memberships() @@ -2397,18 +2394,16 @@ def gemsec( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - global kc - if kc is None: + if "karateclub" not in sys.modules: try: - from karateclub import EdMot, GEMSEC, SCD - kc = True + import karateclub except ModuleNotFoundError: raise ModuleNotFoundError( "Optional dependency not satisfied: install karateclub to use the selected feature." ) g = convert_graph_formats(g_original, nx.Graph) - model = GEMSEC( + model = karateclub.GEMSEC( walk_number=walk_number, walk_length=walk_length, dimensions=dimensions, @@ -2485,18 +2480,16 @@ def scd( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - global kc - if kc is None: + if "karateclub" not in sys.modules: try: - from karateclub import EdMot, GEMSEC, SCD - kc=True + import karateclub except ModuleNotFoundError: raise ModuleNotFoundError( "Optional dependency not satisfied: install karateclub to use the selected feature." ) g = convert_graph_formats(g_original, nx.Graph) - model = SCD(iterations=iterations, eps=eps, seed=seed) + model = karateclub.SCD(iterations=iterations, eps=eps, seed=seed) model.fit(g) members = model.get_memberships() From 2eee970d27bd50c6a03104ad6ff9a3234f553d38 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Thu, 3 Mar 2022 00:08:54 +0100 Subject: [PATCH 14/23] bug fix --- cdlib/algorithms/crisp_partition.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 1bd7d600..c7748b03 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -1743,6 +1743,8 @@ def edmot( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + global karateclub + if "karateclub" not in sys.modules: try: import karateclub @@ -2394,6 +2396,7 @@ def gemsec( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + global karateclub if "karateclub" not in sys.modules: try: import karateclub @@ -2480,6 +2483,8 @@ def scd( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ + global karateclub + if "karateclub" not in sys.modules: try: import karateclub From 5d371140d819be3149110adbf8f4c89ec7aad743 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Thu, 3 Mar 2022 00:16:38 +0100 Subject: [PATCH 15/23] change in viz to allow working in colab --- cdlib/algorithms/overlapping_partition.py | 8 +++----- cdlib/viz/networks.py | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index 441875e7..847bfff3 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -1,18 +1,16 @@ missing_packages=set() def try_load_karate(init=False): - global kc - if kc is None: + global karateclub + if "karateclub" not in sys.modules: try: - from karateclub import DANMF, EgoNetSplitter, NNSED, MNMF, BigClam, SymmNMF - kc=True + import karateclub #import DANMF, EgoNetSplitter, NNSED, MNMF, BigClam, SymmNMF except ModuleNotFoundError: if init==False: raise ModuleNotFoundError( "Optional dependency not satisfied: install karateclub to use the selected feature." ) -kc=None try_load_karate(init=True) if kc==None: missing_packages.add("karateclub") diff --git a/cdlib/viz/networks.py b/cdlib/viz/networks.py index 0f9cffc9..ec8eb8bb 100644 --- a/cdlib/viz/networks.py +++ b/cdlib/viz/networks.py @@ -5,7 +5,7 @@ import networkx as nx from cdlib import NodeClustering from cdlib.utils import convert_graph_formats -from community import induced_graph +from community import community_louvain __all__ = ["plot_network_clusters", "plot_community_graph"] @@ -202,7 +202,7 @@ def plot_community_graph( s = nx.subgraph(graph, node_to_com.keys()) # algorithms graph construction - c_graph = induced_graph(node_to_com, s) + c_graph = community_louvain.induced_graph(node_to_com, s) node_cms = [[node] for node in c_graph.nodes()] return plot_network_clusters( From 7753cb7c16e95cd6dd4a5e093b8367c441e97ded Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Thu, 3 Mar 2022 00:18:58 +0100 Subject: [PATCH 16/23] bug fix --- cdlib/algorithms/overlapping_partition.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index 847bfff3..9d1d7c49 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -1,5 +1,6 @@ missing_packages=set() +import sys def try_load_karate(init=False): global karateclub if "karateclub" not in sys.modules: @@ -12,7 +13,7 @@ def try_load_karate(init=False): ) try_load_karate(init=True) -if kc==None: +if "karateclub" not in sys.modules: missing_packages.add("karateclub") try: From 82a9bd8459e71c03a726eec2a643a6cdf10873fd Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Thu, 3 Mar 2022 17:50:25 +0100 Subject: [PATCH 17/23] V1 light -Removed infomap, leidenalg, karateclub from defaults -Correct bug with louvain in google colab -Allow to install a package after loading cdlib (try reloading package when calling the function) -Display missing package at startup --- cdlib/algorithms/overlapping_partition.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index 9d1d7c49..702502fb 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -905,7 +905,7 @@ def big_clam( try_load_karate() g = convert_graph_formats(g_original, nx.Graph) - model = BigClam( + model = karateclub.BigClam( dimensions=dimensions, iterations=iterations, learning_rate=learning_rate ) model.fit(g) @@ -978,7 +978,7 @@ def danmf( g = convert_graph_formats(g_original, nx.Graph) - model = DANMF(layers, pre_iterations, iterations, seed, lamb) + model = karateclub.DANMF(layers, pre_iterations, iterations, seed, lamb) mapping = {node: i for i, node in enumerate(g.nodes())} rev = {i: node for node, i in mapping.items()} @@ -1043,7 +1043,7 @@ def egonet_splitter(g_original: object, resolution: float = 1.0) -> NodeClusteri try_load_karate() g = convert_graph_formats(g_original, nx.Graph) - model = EgoNetSplitter(resolution=resolution) + model = karateclub.EgoNetSplitter(resolution=resolution) mapping = {node: i for i, node in enumerate(g.nodes())} rev = {i: node for node, i in mapping.items()} @@ -1108,7 +1108,7 @@ def nnsed( try_load_karate() g = convert_graph_formats(g_original, nx.Graph) - model = NNSED(dimensions=dimensions, iterations=iterations, seed=seed) + model = karateclub.NNSED(dimensions=dimensions, iterations=iterations, seed=seed) model.fit(g) members = model.get_memberships() @@ -1183,7 +1183,7 @@ def mnmf( """ try_load_karate() g = convert_graph_formats(g_original, nx.Graph) - model = MNMF( + model = karateclub.MNMF( dimensions=dimensions, clusters=clusters, lambd=lambd, @@ -1637,7 +1637,7 @@ def symmnmf( """ try_load_karate() g = convert_graph_formats(g_original, nx.Graph) - model = SymmNMF(dimensions=dimensions, iterations=iterations, rho=rho, seed=seed) + model = karateclub.SymmNMF(dimensions=dimensions, iterations=iterations, rho=rho, seed=seed) model.fit(g) members = model.get_memberships() From 0caf0ee432ed0bbf394c22ee1c2e171fc8c83f04 Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Thu, 3 Mar 2022 18:56:56 +0100 Subject: [PATCH 18/23] fixed some bugs --- cdlib/algorithms/bipartite_clustering.py | 39 +++++++++++++++++------ cdlib/algorithms/crisp_partition.py | 2 +- cdlib/algorithms/overlapping_partition.py | 10 ++++-- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/cdlib/algorithms/bipartite_clustering.py b/cdlib/algorithms/bipartite_clustering.py index 151744fc..6816af7a 100644 --- a/cdlib/algorithms/bipartite_clustering.py +++ b/cdlib/algorithms/bipartite_clustering.py @@ -1,15 +1,18 @@ from cdlib import BiNodeClustering +missing_packages=set() import networkx as nx try: import infomap as imp except ModuleNotFoundError: + missing_packages.add("infomap") imp = None try: from wurlitzer import pipes except ModuleNotFoundError: + missing_packages.add("wurlitzer") pipes = None try: @@ -20,8 +23,13 @@ try: import leidenalg except ModuleNotFoundError: + missing_packages.add("leidenalg") leidenalg = None +if len(missing_packages)>0: + print("Note: to be able to use all bipartite methods, you need to install some additional packages: ", missing_packages) + + from cdlib.utils import convert_graph_formats from collections import defaultdict from cdlib.algorithms.internal.pycondor import condor_object, initial_community, brim @@ -123,11 +131,15 @@ def CPM_Bipartite( .. note:: Reference implementation: https://leidenalg.readthedocs.io/en/stable/multiplex.html?highlight=bipartite#bipartite """ + global leidenalg if ig is None or leidenalg is None: - raise ModuleNotFoundError( - "Optional dependency not satisfied: install igraph and leidenalg to use the " - "selected feature." - ) + try: + import leidenalg + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install igraph and leidenalg to use the " + "selected feature." + ) g = convert_graph_formats(g_original, ig.Graph) @@ -201,14 +213,21 @@ def infomap_bipartite(g_original: object, flags: str = "") -> BiNodeClustering: .. note:: Infomap Python API documentation: https://mapequation.github.io/infomap/python/ """ + global imp, pipes if imp is None: - raise ModuleNotFoundError( - "Optional dependency not satisfied: install infomap to use the selected feature." - ) + try: + import infomap as imp + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install infomap to use the selected feature." + ) if pipes is None: - raise ModuleNotFoundError( - "Optional dependency not satisfied: install package wurlitzer to use infomap." - ) + try: + from wurlitzer import pipes + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install package wurlitzer to use infomap." + ) g = convert_graph_formats(g_original, nx.Graph) diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index c7748b03..3956cf63 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -37,7 +37,7 @@ import warnings if len(missing_packages)>0: - print("Note: to be able to use all methods, you need to install some additional packages: ", missing_packages) + print("Note: to be able to use all crisp methods, you need to install some additional packages: ", missing_packages) import sys import numpy as np diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index 702502fb..37a4ffe0 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -1,11 +1,12 @@ missing_packages=set() - import sys + def try_load_karate(init=False): global karateclub - if "karateclub" not in sys.modules: + if init==True or "karateclub" not in sys.modules: try: import karateclub #import DANMF, EgoNetSplitter, NNSED, MNMF, BigClam, SymmNMF + except ModuleNotFoundError: if init==False: raise ModuleNotFoundError( @@ -14,8 +15,10 @@ def try_load_karate(init=False): try_load_karate(init=True) if "karateclub" not in sys.modules: + karateclub=None missing_packages.add("karateclub") + try: import igraph as ig except ModuleNotFoundError: @@ -29,9 +32,12 @@ def try_load_karate(init=False): from ASLPAw_package import ASLPAw except ModuleNotFoundError: ASLPAw = None + missing_packages.add("ASLPAw") import warnings +if len(missing_packages)>0: + print("Note: to be able to use all overlapping methods, you need to install some additional packages: ", missing_packages) From 13622a5e58389e1632fe7e8f6ac7cac8ecd14d2b Mon Sep 17 00:00:00 2001 From: Cazabet Remy Date: Fri, 4 Mar 2022 16:18:04 +0100 Subject: [PATCH 19/23] updated requirements and setup.py --- requirements.txt | 1 - requirements_complete.txt | 4 ---- requirements_optional.txt | 4 ++++ setup.py | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) delete mode 100644 requirements_complete.txt diff --git a/requirements.txt b/requirements.txt index d9706db6..229b478c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,6 @@ python-igraph angel-cd pooch dynetx -wurlitzer thresholdclustering pyclustering cython diff --git a/requirements_complete.txt b/requirements_complete.txt deleted file mode 100644 index df761dd4..00000000 --- a/requirements_complete.txt +++ /dev/null @@ -1,4 +0,0 @@ -karateclub -leidenalg -infomap -wurlitzer \ No newline at end of file diff --git a/requirements_optional.txt b/requirements_optional.txt index 570f339a..c328df25 100644 --- a/requirements_optional.txt +++ b/requirements_optional.txt @@ -1,3 +1,7 @@ GraphRicciCurvature==0.5.2.1 networkit pycombo +karateclub +leidenalg +infomap>=1.3.0 +wurlitzer>=1.0.2 \ No newline at end of file diff --git a/setup.py b/setup.py index 786f365c..a60d0484 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ long_description=long_description, long_description_content_type='text/markdown', extras_require={ - 'C': ["infomap>=1.3.0", "wurlitzer>=1.0.2", "GraphRicciCurvature", "networkit", "pycombo"], + 'C': ["infomap>=1.3.0", "wurlitzer>=1.0.2", "GraphRicciCurvature", "networkit", "pycombo","leidenalg","karateclub"], }, packages=find_packages(exclude=["*.test", "*.test.*", "test.*", "test", "cdlib.test", "cdlib.test.*"]), ) From 72c16e173a1366c210b9300c8d1687c4708df5dc Mon Sep 17 00:00:00 2001 From: Giulio Rossetti Date: Tue, 8 Mar 2022 11:25:24 +0100 Subject: [PATCH 20/23] :arrow_up: minor fix --- cdlib/algorithms/bipartite_clustering.py | 19 ++-- cdlib/algorithms/crisp_partition.py | 127 ++++++++++++---------- cdlib/algorithms/overlapping_partition.py | 105 +++++++++--------- 3 files changed, 132 insertions(+), 119 deletions(-) diff --git a/cdlib/algorithms/bipartite_clustering.py b/cdlib/algorithms/bipartite_clustering.py index 6816af7a..f608f8ed 100644 --- a/cdlib/algorithms/bipartite_clustering.py +++ b/cdlib/algorithms/bipartite_clustering.py @@ -1,7 +1,10 @@ from cdlib import BiNodeClustering -missing_packages=set() - import networkx as nx +from cdlib.utils import convert_graph_formats +from collections import defaultdict +from cdlib.algorithms.internal.pycondor import condor_object, initial_community, brim + +missing_packages = set() try: import infomap as imp @@ -26,13 +29,11 @@ missing_packages.add("leidenalg") leidenalg = None -if len(missing_packages)>0: - print("Note: to be able to use all bipartite methods, you need to install some additional packages: ", missing_packages) - - -from cdlib.utils import convert_graph_formats -from collections import defaultdict -from cdlib.algorithms.internal.pycondor import condor_object, initial_community, brim +if len(missing_packages) > 0: + print( + "Note: to be able to use all bipartite methods, you need to install some additional packages: ", + missing_packages, + ) __all__ = ["bimlpa", "CPM_Bipartite", "infomap_bipartite", "condor"] diff --git a/cdlib/algorithms/crisp_partition.py b/cdlib/algorithms/crisp_partition.py index 3956cf63..0be2dcba 100644 --- a/cdlib/algorithms/crisp_partition.py +++ b/cdlib/algorithms/crisp_partition.py @@ -1,50 +1,10 @@ -missing_packages=set() - -try: - import infomap as imp -except ModuleNotFoundError: - missing_packages.add("infomap") - imp = None - -try: - from wurlitzer import pipes -except ModuleNotFoundError: - missing_packages.add("wurlitzer") - pipes = None - -try: - import igraph as ig -except ModuleNotFoundError: - ig = None - -try: - import leidenalg -except ModuleNotFoundError: - missing_packages.add("leidenalg") - leidenalg = None - -try: - import graph_tool.all as gt -except ModuleNotFoundError: - missing_packages.add("graph_tool") - gt = None - -try: - import karateclub -except ModuleNotFoundError: - missing_packages.add("karateclub") - -import warnings - -if len(missing_packages)>0: - print("Note: to be able to use all crisp methods, you need to install some additional packages: ", missing_packages) - import sys import numpy as np from typing import Callable from copy import deepcopy from cdlib.algorithms.internal import DER -#import community as louvain_modularity + +# import community as louvain_modularity from community import community_louvain from collections import defaultdict from cdlib import NodeClustering, FuzzyNodeClustering @@ -73,22 +33,12 @@ from cdlib.algorithms.internal.principled import principled from cdlib.algorithms.internal.MCODE import m_code from cdlib.algorithms.internal.RSC import rsc_evaluate_graph - -try: - from GraphRicciCurvature.OllivierRicci import OllivierRicci -except ModuleNotFoundError: - OllivierRicci = None - -try: - import pycombo as pycombo_part -except ModuleNotFoundError: - pycombo_part = None +import warnings import markov_clustering as mc from chinese_whispers import chinese_whispers as cw from chinese_whispers import aggregate_clusters from thresholdclustering.thresholdclustering import best_partition as th_best_partition - import networkx as nx from cdlib.utils import ( @@ -98,6 +48,59 @@ nx_node_integer_mapping, ) +missing_packages = set() + +try: + import infomap as imp +except ModuleNotFoundError: + missing_packages.add("infomap") + imp = None + +try: + from wurlitzer import pipes +except ModuleNotFoundError: + missing_packages.add("wurlitzer") + pipes = None + +try: + import igraph as ig +except ModuleNotFoundError: + ig = None + +try: + import leidenalg +except ModuleNotFoundError: + missing_packages.add("leidenalg") + leidenalg = None + +try: + import graph_tool.all as gt +except ModuleNotFoundError: + missing_packages.add("graph_tool") + gt = None + +try: + import karateclub +except ModuleNotFoundError: + missing_packages.add("karateclub") + + +if len(missing_packages) > 0: + print( + "Note: to be able to use all crisp methods, you need to install some additional packages: ", + missing_packages, + ) + +try: + from GraphRicciCurvature.OllivierRicci import OllivierRicci +except ModuleNotFoundError: + OllivierRicci = None + +try: + import pycombo as pycombo_part +except ModuleNotFoundError: + pycombo_part = None + __all__ = [ "louvain", "leiden", @@ -1067,7 +1070,7 @@ def infomap(g_original: object, flags: str = "") -> NodeClustering: .. note:: Infomap Python API documentation: https://mapequation.github.io/infomap/python/ """ - global imp,pipes + global imp, pipes if imp is None: try: import infomap as imp @@ -1469,12 +1472,15 @@ def sbm_dl( .. note:: Implementation from graph-tool library, please report to https://graph-tool.skewed.de for details """ + if gt is None: raise Exception( "===================================================== \n" "The graph-tool library seems not to be installed (or incorrectly installed). \n" - "Please check installation procedure there https://git.skewed.de/count0/graph-tool/wikis/installation-instructions#native-installation \n" - "on linux/mac, you can use package managers to do so(apt-get install python3-graph-tool, brew install graph-tool, etc.)" + "Please check installation procedure there " + "https://git.skewed.de/count0/graph-tool/wikis/installation-instructions#native-installation \n" + "on linux/mac, you can use package managers to do so " + "(apt-get install python3-graph-tool, brew install graph-tool, etc.)" ) gt_g = convert_graph_formats(g_original, nx.Graph) gt_g, label_map = __from_nx_to_graph_tool(gt_g) @@ -1522,6 +1528,8 @@ def sbm_dl_nested( .. note:: Implementation from graph-tool library, please report to https://graph-tool.skewed.de for details """ + global gt + if gt is None: try: import graph_tool.all as gt @@ -1529,9 +1537,12 @@ def sbm_dl_nested( raise Exception( "===================================================== \n" "The graph-tool library seems not to be installed (or incorrectly installed). \n" - "Please check installation procedure there https://git.skewed.de/count0/graph-tool/wikis/installation-instructions#native-installation \n" - "on linux/mac, you can use package managers to do so(apt-get install python3-graph-tool, brew install graph-tool, etc.)" + "Please check installation procedure " + "there https://git.skewed.de/count0/graph-tool/wikis/installation-instructions#native-installation \n" + "on linux/mac, you can use package managers to do so(apt-get install python3-graph-tool, " + "brew install graph-tool, etc.)" ) + gt_g = convert_graph_formats(g_original, nx.Graph) gt_g, label_map = __from_nx_to_graph_tool(gt_g) state = gt.minimize_nested_blockmodel_dl(gt_g) diff --git a/cdlib/algorithms/overlapping_partition.py b/cdlib/algorithms/overlapping_partition.py index 37a4ffe0..16db1cea 100644 --- a/cdlib/algorithms/overlapping_partition.py +++ b/cdlib/algorithms/overlapping_partition.py @@ -1,48 +1,4 @@ -missing_packages=set() import sys - -def try_load_karate(init=False): - global karateclub - if init==True or "karateclub" not in sys.modules: - try: - import karateclub #import DANMF, EgoNetSplitter, NNSED, MNMF, BigClam, SymmNMF - - except ModuleNotFoundError: - if init==False: - raise ModuleNotFoundError( - "Optional dependency not satisfied: install karateclub to use the selected feature." - ) - -try_load_karate(init=True) -if "karateclub" not in sys.modules: - karateclub=None - missing_packages.add("karateclub") - - -try: - import igraph as ig -except ModuleNotFoundError: - ig = None -try: - from angel import Angel -except ModuleNotFoundError: - Angel = None - -try: - from ASLPAw_package import ASLPAw -except ModuleNotFoundError: - ASLPAw = None - missing_packages.add("ASLPAw") - - -import warnings -if len(missing_packages)>0: - print("Note: to be able to use all overlapping methods, you need to install some additional packages: ", missing_packages) - - - - - from random import sample from demon import Demon from cdlib.algorithms.internal.NodePerception import NodePerception @@ -76,6 +32,50 @@ def try_load_karate(init=False): endntm_find_overlap_cluster, endntm_evalFuction, ) +import warnings + +missing_packages = set() + + +def __try_load_karate(init=False): + global karateclub + if init == True or "karateclub" not in sys.modules: + try: + import karateclub + + except ModuleNotFoundError: + if not init: + raise ModuleNotFoundError( + "Optional dependency not satisfied: install karateclub to use the selected feature." + ) + + +__try_load_karate(init=True) +if "karateclub" not in sys.modules: + karateclub = None + missing_packages.add("karateclub") + + +try: + import igraph as ig +except ModuleNotFoundError: + ig = None +try: + from angel import Angel +except ModuleNotFoundError: + Angel = None + +try: + from ASLPAw_package import ASLPAw +except ModuleNotFoundError: + ASLPAw = None + missing_packages.add("ASLPAw") + +if len(missing_packages) > 0: + print( + "Note: to be able to use all overlapping methods, you need to install some additional packages: ", + missing_packages, + ) __all__ = [ "ego_networks", @@ -908,7 +908,7 @@ def big_clam( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - try_load_karate() + __try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = karateclub.BigClam( @@ -980,8 +980,7 @@ def danmf( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - try_load_karate() - + __try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = karateclub.DANMF(layers, pre_iterations, iterations, seed, lamb) @@ -1046,7 +1045,7 @@ def egonet_splitter(g_original: object, resolution: float = 1.0) -> NodeClusteri .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - try_load_karate() + __try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = karateclub.EgoNetSplitter(resolution=resolution) @@ -1111,7 +1110,7 @@ def nnsed( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - try_load_karate() + __try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = karateclub.NNSED(dimensions=dimensions, iterations=iterations, seed=seed) @@ -1187,7 +1186,7 @@ def mnmf( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - try_load_karate() + __try_load_karate() g = convert_graph_formats(g_original, nx.Graph) model = karateclub.MNMF( dimensions=dimensions, @@ -1641,9 +1640,11 @@ def symmnmf( .. note:: Reference implementation: https://karateclub.readthedocs.io/ """ - try_load_karate() + __try_load_karate() g = convert_graph_formats(g_original, nx.Graph) - model = karateclub.SymmNMF(dimensions=dimensions, iterations=iterations, rho=rho, seed=seed) + model = karateclub.SymmNMF( + dimensions=dimensions, iterations=iterations, rho=rho, seed=seed + ) model.fit(g) members = model.get_memberships() From b473564a4804ad93e2496e91c60ba722549a9209 Mon Sep 17 00:00:00 2001 From: Giulio Rossetti Date: Tue, 8 Mar 2022 14:08:08 +0100 Subject: [PATCH 21/23] :arrow_up: v0.2.6 --- conda/meta.yaml | 5 +---- docs/conf.py | 4 ++-- environment.yml | 4 ---- setup.py | 2 +- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/conda/meta.yaml b/conda/meta.yaml index 33400fe4..7d3780ab 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -1,5 +1,5 @@ {% set name = "cdlib" %} -{% set version = "0.2.5" %} +{% set version = "0.2.6" %} package: name: "{{ name|lower }}" @@ -45,8 +45,6 @@ requirements: - demon - dynetx - eva_lcd - - karateclub - - leidenalg - markov_clustering - matplotlib - networkx>=2.4 @@ -65,7 +63,6 @@ requirements: - seaborn - thresholdclustering - tqdm - - wurlitzer test: imports: diff --git a/docs/conf.py b/docs/conf.py index da37cc17..0c48f392 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -134,9 +134,9 @@ def __getattr__(cls, name): # built documents. # # The short X.Y version. -version = u"0.2.5" +version = u"0.2.6" # The full version, including alpha/beta/rc tags. -release = u"0.2.5" +release = u"0.2.6" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/environment.yml b/environment.yml index 3b737b64..10eae4d6 100644 --- a/environment.yml +++ b/environment.yml @@ -14,17 +14,13 @@ dependencies: - seaborn - pandas - eva_lcd -- karateclub - bimlpa - markov_clustering - chinese_whispers - python-igraph -- leidenalg - angel_cd - pooch - dynetx -- python-infomap -- wurlitzer - thresholdclustering - pyclustering - python-Levenshtein diff --git a/setup.py b/setup.py index a60d0484..7ac88ec6 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup(name='cdlib', - version='0.2.5', + version='0.2.6', license='BSD-Clause-2', description='Community Discovery Library', url='https://github.com/GiulioRossetti/cdlib', From a27873b9f0329271541a6ddab429a00e26c0f3a5 Mon Sep 17 00:00:00 2001 From: Giulio Rossetti Date: Tue, 8 Mar 2022 15:07:46 +0100 Subject: [PATCH 22/23] :arrow_up: minor fix --- cdlib/test/test_community_discovery_models.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cdlib/test/test_community_discovery_models.py b/cdlib/test/test_community_discovery_models.py index 2e52c8e6..2a73d439 100644 --- a/cdlib/test/test_community_discovery_models.py +++ b/cdlib/test/test_community_discovery_models.py @@ -348,6 +348,8 @@ def test_markov_clustering(self): self.assertEqual(type(communities.communities[0][0]), int) def test_bigClam(self): + if karateclub is None: + return g = nx.karate_club_graph() coms = algorithms.big_clam(g) self.assertEqual(type(coms.communities), list) @@ -478,6 +480,8 @@ def test_sbm_nested_dl(self): self.assertEqual(type(coms.communities[0][0]), str) def test_danmf(self): + if karateclub is None: + return g = get_string_graph() coms = algorithms.danmf(g) self.assertEqual(type(coms.communities), list) @@ -486,6 +490,8 @@ def test_danmf(self): self.assertEqual(type(coms.communities[0][0]), str) def test_egonet_splitter(self): + if karateclub is None: + return g = get_string_graph() coms = algorithms.egonet_splitter(g) self.assertEqual(type(coms.communities), list) @@ -494,6 +500,8 @@ def test_egonet_splitter(self): self.assertEqual(type(coms.communities[0][0]), str) def test_nnsed(self): + if karateclub is None: + return g = nx.karate_club_graph() coms = algorithms.nnsed(g) self.assertEqual(type(coms.communities), list) @@ -502,6 +510,8 @@ def test_nnsed(self): self.assertEqual(type(coms.communities[0][0]), int) def test_mnmf(self): + if karateclub is None: + return g = nx.karate_club_graph() coms = algorithms.mnmf(g) self.assertEqual(type(coms.communities), list) @@ -510,6 +520,8 @@ def test_mnmf(self): self.assertEqual(type(coms.communities[0][0]), int) def test_edmot(self): + if karateclub is None: + return g = nx.karate_club_graph() coms = algorithms.edmot(g) self.assertEqual(type(coms.communities), list) @@ -625,7 +637,8 @@ def test_CPM_Bipartite(self): g = ig.Graph.Erdos_Renyi(n=80, m=600) g.vs["type"] = 0 g.vs[15:]["type"] = 1 - + if leidenalg is None: + return coms = algorithms.CPM_Bipartite(g, 0.3) self.assertEqual(type(coms.communities), list) if len(coms.communities) > 0: @@ -640,6 +653,8 @@ def test_CPM_Bipartite(self): self.assertEqual(type(coms.communities[0][0]), int) def test_infomap_Bipartite(self): + if infomap is None: + return g = nx.algorithms.bipartite.random_graph(300, 100, 0.2) coms = algorithms.infomap_bipartite(g) self.assertEqual(type(coms.communities), list) @@ -788,6 +803,8 @@ def test_kcut(self): print("Kcut error to be checked (conda packaging)") def test_symmnmf(self): + if karateclub is None: + return G = nx.karate_club_graph() coms = algorithms.symmnmf(G) @@ -806,6 +823,8 @@ def test_scd(self): self.assertEqual(type(coms.communities[0][0]), int) def test_gemsec(self): + if karateclub is None: + return G = nx.karate_club_graph() coms = algorithms.gemsec(G) From f5d8376de34dd1f4f98fc266f27fcc24aa27f9c4 Mon Sep 17 00:00:00 2001 From: Giulio Rossetti Date: Tue, 8 Mar 2022 15:17:15 +0100 Subject: [PATCH 23/23] :arrow_up: minor fix --- cdlib/test/test_community_discovery_models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cdlib/test/test_community_discovery_models.py b/cdlib/test/test_community_discovery_models.py index 2a73d439..232b87e4 100644 --- a/cdlib/test/test_community_discovery_models.py +++ b/cdlib/test/test_community_discovery_models.py @@ -5,6 +5,11 @@ import random import os +try: + import karateclub +except ModuleNotFoundError: + karateclub = None + try: import pycombo as pycombo_part except ModuleNotFoundError: