Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging Master into Develop #158

Merged
merged 17 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cz.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.commitizen]
name = "cz_conventional_commits"
version = "2.3.3"
version = "2.3.5"
version_provider = "poetry"
version_files = [
"pyproject.toml",
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/publish-to-dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ jobs:
id: push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
tags: hypernetx/hypernetx:latest
push: true

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: hypernetx/hypernetx
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
4 changes: 2 additions & 2 deletions LONG_DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _long_description:

HyperNetX
=================
=========

The HyperNetX library provides classes and methods for the analysis
and visualization of complex network data modeled as hypergraphs.
Expand All @@ -25,7 +25,7 @@ Documentation is available at: https://pnnl.github.io/HyperNetX
For questions and comments contact the developers directly at: [email protected]

HyperNetX 2.3
=============
~~~~~~~~~~~~~

HyperNetX 2.3. is the latest, stable release. The core library has been refactored to take better advantage
of Pandas Dataframes, improve readability and maintainability, address bugs, and make it easier to change.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ lint: pylint flake8

.PHONY: pylint
pylint:
@$(PYTHON3) -m pylint --recursive=y --persistent=n --verbose hypernetx
@$(PYTHON3) -m pylint --recursive=y --persistent=n --exit-zero --verbose hypernetx

# Todo: fix flake8 errors and remove --exit-zero
.PHONY: flake8
Expand Down
109 changes: 62 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,63 +235,96 @@ After the container has started, access the HyperNetX Jupyter Notebooks by openi
[http://localhost:8888/tree](http://localhost:8888/tree)


Development
===========
# Development

Install an editable version
```
pip install -e .
```
As a developer, set up your environment using either the standard `pip` tool or [`Poetry`](https://python-poetry.org/).

## Using Pip

Install additional dependencies to support testing and jupyter notebooks:
### Setup virtual environment and install HNX

Create a virtual environement. Then install an editable version of HNX and also install additional dependencies to support testing and jupyter notebooks:
```
python -m venv venv-hnx
source venv-hnx/bin/activate
pip install -e .
pip install -r requirements.txt
```

You can also install all these requirements in one Make target:
As an alternative, you can also install all these requirements in one Make target:

```
make venv
source venv-hnx/bin/activate
make install
```

Poetry
======
### Setup pre-commit

Use the [pre-commit framework](https://pre-commit.com/) to automatically point out issues and resolve those issues before code review.
It is highly recommended to install pre-commit in your development environment so that issues with your code can be found before you submit a
pull request. More importantly, using pre-commit will automatically format your code changes so that they pass the CI build. For example, pre-commit will
automatically run the formatter Black on your code changes.

```shell
# Once installed, pre-commit will be triggered every time you make a commit in your environment
pre-commit install
```


## Using Poetry

This library uses [Poetry](https://python-poetry.org/docs/) to manage dependencies and packaging. Poetry can also be
used to manage your environment for development.

Prerequisites
-------------
### Prerequisites

* [Install Poetry](https://python-poetry.org/docs/#installation)


Configure Poetry
----------------
### Configure Poetry

[Configure your Poetry](https://python-poetry.org/docs/configuration/) to ensure that the virtual environment gets created in your project directory (this is not necessary but recommended for convenience):

[Configure your Poetry](https://python-poetry.org/docs/configuration/) to create the virtual environment in your project directory:
```
poetry config virtualenvs.in-project true

# check the poetry configuration
poetry config --list
```

Set up virtual environment
----------------------------
### Setup virtual environment and install HNX

Create and activate a virtual environment.

```
poetry shell
```

Install required dependencies and HyperNetX in editable mode.
Install HyperNetX in editable mode, the library's core/required dependencies, and the optional dependencies to support development.

```
poetry install
poetry install --with test,lint,docs,release,tutorials
```

Install support for testing
-----------------------------
Details about these dependencies are defined in [pyproject.toml](pyproject.toml).

### Setup Pre-commit

Use the [pre-commit framework](https://pre-commit.com/) to automatically point out issues and resolve those issues before code review.
It is highly recommended to install pre-commit in your development environment so that issues with your code can be found before you submit a
pull request. More importantly, using pre-commit will automatically format your code changes so that they pass the CI build. For example, pre-commit will
automatically run the formatter Black on your code changes.

```shell
# Once installed, pre-commit will be triggered every time you make a commit in your environment
pre-commit install
```

### Details about optional dependencies

#### Install support for testing


> ℹ️ **NOTE:** This project has pytest configuration contained in pyproject.toml. By default, pytest will use those configuration settings to run tests.

Expand All @@ -312,8 +345,7 @@ coverage html
open htmlcov/index.html
```

Install support for tutorials
-----------------------------
#### Install support for tutorials

```shell
poetry install --with tutorials
Expand All @@ -325,8 +357,8 @@ poetry shell
make tutorials
```

Code Quality
------------
#### Code Quality: Pylint, Black

HyperNetX uses a number of tools to maintain code quality:

* Pylint
Expand All @@ -341,8 +373,6 @@ poetry install --with lint
poetry shell
```

Pylint
------

[Pylint](https://pylint.pycqa.org/en/latest/index.html) is a static code analyzer for Python-based projects. From the [Pylint docs](https://pylint.pycqa.org/en/latest/index.html#what-is-pylint):

Expand All @@ -362,30 +392,14 @@ pylint hypernetx --output=pylint-results.txt

For more information on configuration, see https://pylint.pycqa.org/en/latest/user_guide/configuration/index.html

Black
-----
[Black](https://black.readthedocs.io/en/stable/) is a PEP 8 compliant formatter for Python-based project. This tool is highly opinionated about how Python should be formatted and will automagically reformat your code.


```shell
black hypernetx
```

Pre-commit
---------

Use the [pre-commit framework](https://pre-commit.com/) to automatically point out issues and resolve those issues before code review.
It is highly recommended to install pre-commit in your development environment so that issues with your code can be found before you submit a
pull request. More importantly, using pre-commit will automatically format your code changes so that they pass the CI build. For example, pre-commit will
automatically run the formatter Black on your code changes.

```shell
# Once installed, pre-commit will be triggered every time you make a commit in your environment
pre-commit install
```

Documentation
-------------
### Documentation

Build and view documentation locally:

Expand Down Expand Up @@ -422,13 +436,14 @@ The HTML pages are in docs/html.
Click on [http://127.0.0.1:8000/install.html](http://127.0.0.1:8000/install.html) to open the docs on your browser. Since this will auto-rebuild, every time
you change a document file, it will automatically render on your browser, allowing you to verify your document changes.

Testing the Docker Image
------------------------

## Developing and Testing the Docker Image

If you want to test the Docker image after making any source code changes, follow this workflow:

1. Make a change in the HNX codebase
2. Build image: `docker build --rm --tag hypernetx/hypernetx:latest`
2. Build image for multi-platforms (i.e.ARM64, x86): `docker build --platform linux/amd64,linux/arm64 --rm --tag hypernetx/hypernetx:latest .`
3. If you're having issues building, see https://docs.docker.com/desktop/containerd/
3. Test image: `docker run -it --rm -p 8888:8888 -v "${PWD}":/home/jovyan/work hypernetx/hypernetx:latest`
4. Open a browser to [http://localhost:8888/tree](http://localhost:8888/tree). Check that tutorials still work and/or open a notebook and test the changes that you made.
5. Once finished testing, kill the container using Ctrl-C
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os


__version__ = "2.3.3"
__version__ = "2.3.5"


# If extensions (or modules to document with autodoc) are in another directory,
Expand Down
2 changes: 1 addition & 1 deletion hypernetx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
from hypernetx.utils import *
from hypernetx.utils.toys import *

__version__ = "2.3.3"
__version__ = "2.3.5"
20 changes: 13 additions & 7 deletions hypernetx/algorithms/hypergraph_modularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def modularity(HG, A, wdc=linear):
_df = pd.DataFrame(zip(_keys, _vals), columns=["key", "val"])
_df = _df.groupby(by="key").sum()
EC = sum(
[wdc(k[1], k[0]) * v[0] for (k, v) in _df.iterrows() if k[0] > k[1] / 2]
[wdc(k[1], k[0]) * v.iloc[0] for (k, v) in _df.iterrows() if k[0] > k[1] / 2]
)

## Degree Tax
Expand Down Expand Up @@ -292,6 +292,12 @@ def two_section(HG):
w = 1 / (len(E) - 1)
s.extend([(k[0], k[1], w) for k in itertools.combinations(E, 2)])
G = ig.Graph.TupleList(s, weights=True).simplify(combine_edges="sum")

## add isolates if any
isolates = list(set([v for v in HG.nodes]) - set(G.vs['name']))
if len(isolates)>0:
G.add_vertices(isolates)

return G


Expand Down Expand Up @@ -392,17 +398,17 @@ def _last_step_weighted(H, A, wdc, delta=0.01, verbose=False):
n_moves = 0
for v in list(np.random.permutation(list(H.nodes))):
dct_A_v = dct_A[v]
H_id = [H.incidence_dict[x] for x in H.nodes[v].memberships]
H_id = [H.incidence_dict[x] for x in H.nodes[v]]
L = [[dct_A[i] for i in x] for x in H_id]

## ec portion before move
_keys = [(Counter(l).most_common(1)[0][1], len(l)) for l in L]
_vals = [H.edges[x].weight for x in H.nodes[v].memberships]
_vals = [H.edges[x].weight for x in H.nodes[v]]
_df = pd.DataFrame(zip(_keys, _vals), columns=["key", "val"])
_df = _df.groupby(by="key").sum()
ec = sum(
[
wdc(k[1], k[0]) * val[0]
wdc(k[1], k[0]) * val.iloc[0]
for (k, val) in _df.iterrows()
if k[0] > k[1] / 2
]
Expand All @@ -425,12 +431,12 @@ def _last_step_weighted(H, A, wdc, delta=0.01, verbose=False):
L = [[dct_A[i] for i in x] for x in H_id]
## EC
_keys = [(Counter(l).most_common(1)[0][1], len(l)) for l in L]
_vals = [H.edges[x].weight for x in H.nodes[v].memberships]
_vals = [H.edges[x].weight for x in H.nodes[v]]
_df = pd.DataFrame(zip(_keys, _vals), columns=["key", "val"])
_df = _df.groupby(by="key").sum()
ecp = sum(
[
wdc(k[1], k[0]) * val[0]
wdc(k[1], k[0]) * val.iloc[0]
for (k, val) in _df.iterrows()
if k[0] > k[1] / 2
]
Expand Down Expand Up @@ -491,7 +497,7 @@ def _last_step_unweighted(H, A, wdc, delta=0.01, verbose=False):
n_moves = 0
for v in list(np.random.permutation(list(H.nodes))):
dct_A_v = dct_A[v]
H_id = [H.incidence_dict[x] for x in H.nodes[v].memberships]
H_id = [H.incidence_dict[x] for x in H.nodes[v]]
L = [[dct_A[i] for i in x] for x in H_id]
deg_v = H.degree(v)

Expand Down
2 changes: 1 addition & 1 deletion hypernetx/algorithms/s_centrality_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _s_centrality(func, H, s=1, edges=True, f=None, return_singletons=True, **kw
vertices = h.nodes

if h.shape[edges * 1] == 1:
stats = {v: 0 for v in vertices}
stats.update({v: 0 for v in vertices})
else:
g = h.get_linegraph(s=s, edges=edges)
stats.update({k: v for k, v in func(g, **kwargs).items()})
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[MAIN]

# Specify a score threshold to be exceeded before program exits with error.
fail-under=7.00
# fail-under=

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hypernetx"
version = "2.3.3"
version = "2.3.5"
description = "HyperNetX is a Python library for the creation and study of hypergraphs."
authors = ["Brenda Praggastis <[email protected]>", "Dustin Arendt <[email protected]>",
"Sinan Aksoy <[email protected]>", "Emilie Purvine <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ basepython = python3.11
commands_pre =
poetry install --with lint
commands =
poetry run pylint --recursive=y --persistent=n hypernetx
poetry run pylint --recursive=y --exit-zero --persistent=n hypernetx
poetry run flake8 hypernetx --exit-zero
poetry run pre-commit install
poetry run pre-commit run --all-files
Expand Down
Loading