~tfardet/NNGT

f4e5002ec6f409eb8f2b1af4f70ba8e49877650c — Tanguy Fardet 5 months ago 643871f
Various - Support Networkx 2.6, improved config, coverage

Fix assortativity and adjacency matrix for networkx 2.6+.
Enable NEST/GIS import skip in config file.
Readd coverage support.
M .build.yml => .build.yml +5 -2
@@ 3,8 3,10 @@ sources:
    - https://git.sr.ht/~tfardet/NNGT
secrets:
    - ceb490c3-68b4-41f7-9aa9-eb2e4b91d424
    - 0b249c79-8eaf-4b82-b1d1-f3c38c7eae4b
tasks:
    - check: |
        mv .coveralls.yml NNGT/.coveralls.yml
        cd NNGT
        python3 extra/check_headers.py
    - setup: |


@@ 19,7 21,7 @@ tasks:
        pip3 install numpy scipy cython mpi4py
        pip3 install networkx python-igraph
        pip3 install pycairo matplotlib seaborn shapely svg.path dxfgrabber
        pip3 install pytest pytest-mpi cov-core coverage
        pip3 install pytest pytest-mpi cov-core coverage coveralls[yaml]
        cd NNGT
        python3 setup.py install --user
        echo 'export PATH=$PATH:/home/build/.local/bin' >> /home/build/.buildenv


@@ 33,4 35,5 @@ tasks:
        GL=gt OMP=2 coverage run -p -m pytest testing
        GL=gt OMP=0 MPI=1 mpirun -n 2 coverage run -p -m pytest --with-mpi testing
        coverage combine
        coverage report
        GIT_BRANCH=$(git show -s --pretty=%D HEAD | tr -s ', /' '\n' | grep -v HEAD | sed -n 2p)
        CI_NAME=$BUILD_SUBMITTER CI_BUILD_NUMBER=$JOB_ID CI_BUILD_URL=$JOB_URL CI_BRANCH=$GIT_BRANCH coveralls

M .coveragerc => .coveragerc +1 -0
@@ 19,5 19,6 @@ omit =
    nngt/geometry/*
    nngt/database/*
    nngt/simulation/*
    nngt/geospatial/*
    nngt/lib/db_tools.py
    nngt/plot/chord_diag/*

M README.md => README.md +1 -0
@@ 6,6 6,7 @@
 simple circular nodes to form a graph." />

[![builds.sr.ht status](https://builds.sr.ht/~tfardet/nngt/commits.svg)](https://builds.sr.ht/~tfardet/nngt/commits?)
[![Coverage Status](https://coveralls.io/repos/github/tfardet/NNGT/badge.svg?branch=main)](https://coveralls.io/github/tfardet/NNGT?branch=main)
[![Documentation Status](https://readthedocs.org/projects/nngt/badge/?version=latest)](http://nngt.readthedocs.org/en/latest/?badge=latest) [![License](http://img.shields.io/:license-GPLv3+-yellow.svg)](http://www.gnu.org/licenses/gpl-3.0.html)<br>
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3402493.svg)](https://doi.org/10.5281/zenodo.3402493)
![Release (latest by date)](https://img.shields.io/github/v/release/tfardet/NNGT)

M nngt/__init__.py => nngt/__init__.py +5 -2
@@ 120,6 120,8 @@ _config = {
    'use_database': False,
    'use_tex': False,
    'seeds': None,
    'load_nest': True,
    'load_gis': True,
    'with_nest': False,
    'with_plot': False,
}


@@ 335,7 337,7 @@ except ImportError as e:

# lazy load for simulation module

if _imputil.find_spec("nest") is not None:
if _config['load_nest'] and _imputil.find_spec("nest") is not None:
    _config['with_nest'] = True
    simulation = _lazy_load("nngt.simulation")
    __all__.append("simulation")


@@ 344,8 346,9 @@ if _imputil.find_spec("nest") is not None:
# lazy load for geospatial module

_has_geospatial = False
_has_geopandas = _imputil.find_spec("geopandas")

if _imputil.find_spec("geopandas") is not None and _has_shapely:
if _config["load_gis"] is not None and _has_shapely:
    geospatial = _lazy_load("nngt.geospatial")
    __all__.append("geospatial")
    _has_geospatial = True

M nngt/analysis/nx_functions.py => nngt/analysis/nx_functions.py +4 -7
@@ 115,14 115,10 @@ def assortativity(g, degree, weights=None):
    .. [nx-assortativity]
       :nxdoc:`algorithms.assortativity.degree_assortativity_coefficient`
    '''
    if weights is not None:
        raise NotImplementedError("Weighted assortatibity is not yet "
                                  "implemented for networkx backend.")

    w = _get_nx_weights(g, weights)

    return nx.degree_assortativity_coefficient(g.graph, x=degree, y=degree,
                                               weight=w)
    return nx.degree_pearson_correlation_coefficient(
        g.graph, x=degree, y=degree, weight=w)


def reciprocity(g):


@@ 741,7 737,8 @@ def adj_mat(g, weights=None, mformat="csr"):
    '''
    w = _get_nx_weights(g, weights)

    return nx.to_scipy_sparse_matrix(g.graph, weight=w, format=mformat)
    return nx.to_scipy_sparse_matrix(g.graph, nodelist=range(g.node_nb()),
                                     weight=w, format=mformat)


def get_edges(g):

M nngt/lib/nngt_config.py => nngt/lib/nngt_config.py +5 -2
@@ 75,6 75,8 @@ def get_config(key=None, detailed=False):
            del cfg["use_tex"]
            del cfg["mpl_backend"]
            del cfg["color_lib"]
            del cfg["load_nest"]
            del cfg["load_gis"]

            # hide database config if not used
            rm = []


@@ 195,7 197,7 @@ def set_config(config, value=None, silent=False):
                        "This functionality is not available")

    # update nest
    if imputil.find_spec("nest") is not None:
    if nngt._config["load_nest"] and imputil.find_spec("nest") is not None:
        _lazy_load("nngt.simulation")
        nngt._config["with_nest"] = True
    else:


@@ 220,8 222,9 @@ def set_config(config, value=None, silent=False):

    # check geospatial
    has_geospatial = False
    has_geopandas = imputil.find_spec("geopandas") is not None

    if imputil.find_spec("geopandas") is not None and has_shapely:
    if nngt._config["load_gis"] and has_geopandas and has_shapely:
        _lazy_load("nngt.geospatial")
        has_geospatial = True


M nngt/nngt.conf.default => nngt/nngt.conf.default +18 -0
@@ 83,3 83,21 @@ multithreading = True
# Note that the MPI version is not locally multithreaded.

mpi = False


#----------------------------
## Third party libraries -----------------------------------------------------
#----------------------------

# NNGT uses some 3rd party libraries for neuroscience and geospatial
# applications. Because these use compiled code, it can sometime lead to
# unexpected issues. You can prevent them from being loaded by setting their
# load option to False if you encounter such issues.

# try to load NEST on import

load_nest = True

# try to load geospatial tools on import

load_gis = True

M testing/library_compatibility.py => testing/library_compatibility.py +3 -4
@@ 133,10 133,9 @@ def test_assortativity():
            nngt.analyze_graph["assortativity"](g, "in"), assort_unweighted)

        # not check weighted version for networkx for now
        if bckd != "networkx":
            assert np.isclose(
                nngt.analyze_graph["assortativity"](g, "in", weights=True),
                assort_weighted)
        assert np.isclose(
            nngt.analyze_graph["assortativity"](g, "in", weights=True),
            assort_weighted)

    # UNDIRECTED
    edge_list = [(0, 3), (1, 0), (1, 2), (2, 4), (4, 1), (4, 3)]