Skip to content

Commit

Permalink
Merge pull request #580 from graphistry/dev/comm_layout
Browse files Browse the repository at this point in the history
Dev/comm layout
  • Loading branch information
lmeyerov authored Aug 3, 2024
2 parents a9945bf + b46df4c commit 56d83db
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 10 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Development]

## [0.34.3 - 2024-08-03]

### Added

* Layout `modularity_weighted_layout` that uses edge weights to more strongly emphasize community structure

### Docs

* Tutorial for `modularity_weighted_layout`

### Infra

* Upgrade tests to`docker compose` from `docker-compose`
* Remove deprecated `version` to address warnings

## [0.34.2 - 2024-07-22]

### Fixed
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,22 @@ g.ring_categorical_layout(
)
```

### Layout: Modularity weighted

Weight edges by community membership to emphasize community structure. See [(Notebook tutorial)](https://github.com/graphistry/pygraphistry/blob/master/demos/more_examples/graphistry_features/layout_modularity_weighted.ipynb)

```python
g.modularity_weighted_layout().plot()
g.modularity_weighted_layout('my_community_col').plot()
g.modularity_weighted_layout(
community_alg='louvain',
engine='cudf',
same_community_weight=2.0,
cross_community_weight=0.3,
edge_influence=2.0
).plot()
```

### Plugin: igraph

With `pip install graphistry[igraph]`, you can also use [`igraph` layouts](https://igraph.org/python/doc/api/igraph.Graph.html#layout):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"### Modularity weighted layout\n",
"\n",
"When community labels are known, modularity weighting helps force the layout to better hightlight the community structure. The layout algorithm will weight edges based on whether they are same-community vs cross-community. If no community labels are provided, default to using Louivain."
],
"metadata": {
"id": "UEQyPUiIK6VS"
}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Z9i0f7MrH4V9",
"outputId": "5aa22d94-64e1-4bed-a579-e5333c0c19aa"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.0/75.0 kB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m263.0/263.0 kB\u001b[0m \u001b[31m9.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.1/3.1 MB\u001b[0m \u001b[31m28.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m332.3/332.3 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h"
]
}
],
"source": [
"! pip install -q graphistry igraph"
]
},
{
"cell_type": "code",
"source": [
"import graphistry\n",
"import pandas as pd\n",
"graphistry.register(api=3, username=FILL_ME_IN, password=FILL_ME_IN)"
],
"metadata": {
"id": "Nk2xIrpUH5ud"
},
"execution_count": 24,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df = pd.read_csv('https://raw.githubusercontent.com/graphistry/pygraphistry/master/demos/data/transactions.csv')\n",
"g = graphistry.edges(df, 'Destination', 'Source')"
],
"metadata": {
"id": "LWZoFxJ2IYMS"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Before\n",
"g.compute_igraph('community_multilevel', directed=False).plot()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 561
},
"id": "ffGGHcs_KPKH",
"outputId": "769c30cc-99cd-4f43-d059-06ade9446c8d"
},
"execution_count": 27,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"WARNING:graphistry.plugins.igraph:edge index g._edge not set so using edge index as ID; set g._edge via g.edges(), or change merge_if_existing to FalseWARNING:graphistry.plugins.igraph:edge index g._edge __edge_index__ missing as attribute in ig; using ig edge order for IDs"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<IPython.core.display.HTML object>"
],
"text/html": [
"\n",
" <iframe id=\"582bf801-1b1e-489a-82f6-ab125dfac968\" src=\"https://hub.graphistry.com/graph/graph.html?dataset=0d6a30dfaa094e8a8b328615444dfd95&type=arrow&viztoken=4d1bfb2c-ca98-4d37-868e-43529b4146c6&usertag=7b512218-pygraphistry-0.34.2&splashAfter=1722670549&info=true\"\n",
" allowfullscreen=\"true\" webkitallowfullscreen=\"true\" mozallowfullscreen=\"true\"\n",
" oallowfullscreen=\"true\" msallowfullscreen=\"true\"\n",
" style=\"width:100%; height:500px; border: 1px solid #DDD; overflow: hidden\"\n",
" \n",
" >\n",
" </iframe>\n",
" \n",
" <script>\n",
" try {\n",
" $(\"#582bf801-1b1e-489a-82f6-ab125dfac968\").bind('mousewheel', function(e) { e.preventDefault(); });\n",
" } catch (e) { console.error('exn catching scroll', e); }\n",
" </script>\n",
" "
]
},
"metadata": {},
"execution_count": 27
}
]
},
{
"cell_type": "code",
"source": [
"# After\n",
"g2 = g.modularity_weighted_layout(g)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ltw6qybCi0xA",
"outputId": "ef5ea3ea-5b3d-429e-c979-ce13ea80797f"
},
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"WARNING:graphistry.plugins.igraph:edge index g._edge not set so using edge index as ID; set g._edge via g.edges(), or change merge_if_existing to FalseWARNING:graphistry.plugins.igraph:edge index g._edge __edge_index__ missing as attribute in ig; using ig edge order for IDs"
]
}
]
},
{
"cell_type": "code",
"source": [
"g2.plot()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 543
},
"id": "rqBkXQDWdOE7",
"outputId": "f2eee36e-ddd5-4d21-fcec-32761476aa55"
},
"execution_count": 21,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<IPython.core.display.HTML object>"
],
"text/html": [
"\n",
" <iframe id=\"afae5f89-0caf-4aa5-b1af-b5dabdd43e79\" src=\"https://hub.graphistry.com/graph/graph.html?dataset=e64d74fbd26541169ac8b670ed57a19a&type=arrow&viztoken=5e9461fa-ad1d-4ccd-8632-43f15e379f62&usertag=7b512218-pygraphistry-0.34.2&splashAfter=1722667198&info=true&edgeInfluence=2.0\"\n",
" allowfullscreen=\"true\" webkitallowfullscreen=\"true\" mozallowfullscreen=\"true\"\n",
" oallowfullscreen=\"true\" msallowfullscreen=\"true\"\n",
" style=\"width:100%; height:500px; border: 1px solid #DDD; overflow: hidden\"\n",
" \n",
" >\n",
" </iframe>\n",
" \n",
" <script>\n",
" try {\n",
" $(\"#afae5f89-0caf-4aa5-b1af-b5dabdd43e79\").bind('mousewheel', function(e) { e.preventDefault(); });\n",
" } catch (e) { console.error('exn catching scroll', e); }\n",
" </script>\n",
" "
]
},
"metadata": {},
"execution_count": 21
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "oFTINwvZfsuH"
},
"execution_count": null,
"outputs": []
}
]
}
4 changes: 2 additions & 2 deletions docker/dc.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -ex

# Alias for docker-compose
# Alias for docker compose

COMPOSE_DOCKER_CLI_BUILD=1 \
DOCKER_BUILDKIT=1 \
docker-compose $@
docker compose $@
2 changes: 0 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.5"

networks:
grph_net:
name: grph_net
Expand Down
2 changes: 1 addition & 1 deletion docker/test-cpu-local-neo4j-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WITH_SUDO=${WITH_SUDO:-}

COMPOSE_DOCKER_CLI_BUILD=1 \
DOCKER_BUILDKIT=1 \
docker-compose build \
docker compose build \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--build-arg SENTENCE_TRANSFORMER="${SENTENCE_TRANSFOMER}" \
--build-arg PIP_DEPS="-e .[test,bolt]" \
Expand Down
2 changes: 1 addition & 1 deletion docker/test-cpu-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ then
echo "WITH_BUILD (transformer: $SENTENCE_TRANSFORMER)"
COMPOSE_DOCKER_CLI_BUILD=1 \
DOCKER_BUILDKIT=1 \
docker-compose build \
docker compose build \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--build-arg PIP_DEPS="${PIP_DEPS}" \
--build-arg SENTENCE_TRANSFORMER="${SENTENCE_TRANSFOMER}" \
Expand Down
2 changes: 1 addition & 1 deletion docker/test-gpu-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi

COMPOSE_DOCKER_CLI_BUILD=1 \
DOCKER_BUILDKIT=1 \
docker-compose build \
docker compose build \
--build-arg PIP_DEPS="${PIP_DEPS}" \
test-gpu

Expand Down
19 changes: 19 additions & 0 deletions docs/source/graphistry.layout.modularity_weighted.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
:orphan:

.. ^ FIXME
graphistry.layout.modularity_weighted package
=============================================

Submodules
----------

Module contents
---------------

.. automodule:: graphistry.layout.modularity_weighted
:members:
:undoc-members:
:show-inheritance:


3 changes: 2 additions & 1 deletion graphistry/layout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#from .utils import *
#from .graph import *
from .gib import group_in_a_box_layout
from .sugiyama import SugiyamaLayout
from .modularity_weighted import modularity_weighted_layout
from .ring import time_ring, ring_categorical, ring_continuous
from .sugiyama import SugiyamaLayout
1 change: 1 addition & 0 deletions graphistry/layout/modularity_weighted/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .modularity_weighted import modularity_weighted_layout
Loading

0 comments on commit 56d83db

Please sign in to comment.