From bf72de79650cf2509523c9e4ec6047f22abed6d2 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Wed, 4 Dec 2024 09:25:54 -0600 Subject: [PATCH 1/4] Fix links in README (#54) This is targeting branch-25.02 since it's non-critical. Authors: - Erik Welch (https://github.com/eriknw) Approvers: - Ralph Liu (https://github.com/nv-rliu) URL: https://github.com/rapidsai/nx-cugraph/pull/54 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec61a2796..fd81257bb 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ nx.betweenness_centrality(nxcg_G, k=1000) # nxcg Graph type causes cugraph back ## Supported Algorithms The nx-cugraph backend to NetworkX connects -[pylibcugraph](../../readme_pages/pylibcugraph.md) (cuGraph's low-level python +[pylibcugraph](https://github.com/rapidsai/cugraph/blob/-/readme_pages/pylibcugraph.md) (cuGraph's low-level python interface to its CUDA-based graph analytics library) and [CuPy](https://cupy.dev/) (a GPU-accelerated array library) to NetworkX's familiar and easy-to-use API. @@ -275,4 +275,4 @@ Below is the list of algorithms that are currently supported in nx-cugraph. To request nx-cugraph backend support for a NetworkX API that is not listed -above, visit the [cuGraph GitHub repo](https://github.com/rapidsai/cugraph). +above, visit the [nx-cugraph GitHub repo](https://github.com/rapidsai/nx-cugraph). From 138801c1e950f2b74b5e48d8ace0286e6c5c6a11 Mon Sep 17 00:00:00 2001 From: Ralph Liu <137829296+nv-rliu@users.noreply.github.com> Date: Fri, 6 Dec 2024 03:53:46 +0900 Subject: [PATCH 2/4] Add Bipartite Betweenness Centrality (#32) This PR adds `bipartite` > `betweenness_centrality` to nx-cugraph (seen [here](https://networkx.org/documentation/latest/reference/algorithms/generated/networkx.algorithms.bipartite.centrality.betweenness_centrality.html#networkx.algorithms.bipartite.centrality.betweenness_centrality) in NetworkX) This was a combined effort with @eriknw to get myself familiarized with adding new algorithms. Authors: - Ralph Liu (https://github.com/nv-rliu) - Erik Welch (https://github.com/eriknw) Approvers: - Erik Welch (https://github.com/eriknw) - Rick Ratzel (https://github.com/rlratzel) URL: https://github.com/rapidsai/nx-cugraph/pull/32 --- README.md | 2 + _nx_cugraph/__init__.py | 1 + benchmarks/pytest-based/bench_algos.py | 21 +++++++ nx_cugraph/algorithms/bipartite/__init__.py | 2 + nx_cugraph/algorithms/bipartite/centrality.py | 62 +++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 nx_cugraph/algorithms/bipartite/centrality.py diff --git a/README.md b/README.md index ec61a2796..af62de5f4 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ Below is the list of algorithms that are currently supported in nx-cugraph.
 bipartite
+ ├─ centrality
+ │   └─ betweenness_centrality
  └─ generators
      └─ complete_bipartite_graph
 centrality
diff --git a/_nx_cugraph/__init__.py b/_nx_cugraph/__init__.py
index 6b905e8db..a52583d4d 100644
--- a/_nx_cugraph/__init__.py
+++ b/_nx_cugraph/__init__.py
@@ -60,6 +60,7 @@
         "bfs_successors",
         "bfs_tree",
         "bidirectional_shortest_path",
+        "bipartite_betweenness_centrality",
         "bull_graph",
         "caveman_graph",
         "chvatal_graph",
diff --git a/benchmarks/pytest-based/bench_algos.py b/benchmarks/pytest-based/bench_algos.py
index d5257e2ef..a29f71923 100644
--- a/benchmarks/pytest-based/bench_algos.py
+++ b/benchmarks/pytest-based/bench_algos.py
@@ -853,6 +853,27 @@ def bench_ego_graph(benchmark, graph_obj, backend_wrapper):
     assert isinstance(result, (nx.Graph, nxcg.Graph))
 
 
+def bench_bipartite_BC_n1000_m3000_k100000(benchmark, backend_wrapper):
+    # Example how to run:
+    # $ pytest -sv -k "bench_bipartite_BC" \
+    #   --benchmark-json="logs/None__bipartite_BC__None.json" \
+    #   bench_algos.py
+    n = 1000
+    m = 3000
+    k = 100000
+    graph_obj = nx.bipartite.generators.gnmk_random_graph(n, m, k)
+    G = get_graph_obj_for_benchmark(graph_obj, backend_wrapper)
+    nodes = list(range(n))
+    result = benchmark.pedantic(
+        target=backend_wrapper(nx.bipartite.betweenness_centrality),
+        args=(G, nodes),
+        rounds=rounds,
+        iterations=iterations,
+        warmup_rounds=warmup_rounds,
+    )
+    assert type(result) is dict
+
+
 @pytest.mark.skip(reason="benchmark not implemented")
 def bench_complete_bipartite_graph(benchmark, graph_obj, backend_wrapper):
     pass
diff --git a/nx_cugraph/algorithms/bipartite/__init__.py b/nx_cugraph/algorithms/bipartite/__init__.py
index bfc7f1d4d..ce5e47ead 100644
--- a/nx_cugraph/algorithms/bipartite/__init__.py
+++ b/nx_cugraph/algorithms/bipartite/__init__.py
@@ -10,4 +10,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+from .centrality import *
 from .generators import *
diff --git a/nx_cugraph/algorithms/bipartite/centrality.py b/nx_cugraph/algorithms/bipartite/centrality.py
new file mode 100644
index 000000000..7e4b0baa9
--- /dev/null
+++ b/nx_cugraph/algorithms/bipartite/centrality.py
@@ -0,0 +1,62 @@
+# Copyright (c) 2024, NVIDIA CORPORATION.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import cupy as cp
+import pylibcugraph as plc
+
+from nx_cugraph.convert import _to_graph
+from nx_cugraph.utils import networkx_algorithm
+
+__all__ = ["betweenness_centrality"]
+
+
+@networkx_algorithm(
+    name="bipartite_betweenness_centrality",
+    version_added="24.12",
+    _plc="betweenness_centrality",
+)
+def betweenness_centrality(G, nodes):
+    G = _to_graph(G)
+
+    node_ids, values = plc.betweenness_centrality(
+        resource_handle=plc.ResourceHandle(),
+        graph=G._get_plc_graph(),
+        k=None,
+        random_state=None,
+        normalized=False,
+        include_endpoints=False,
+        do_expensive_check=False,
+    )
+    top_node_ids = G._nodekeys_to_nodearray(set(nodes))
+    bottom_node_ids = cp.delete(cp.arange(G._N, dtype=top_node_ids.dtype), top_node_ids)
+    n = top_node_ids.size
+    m = bottom_node_ids.size
+    s, t = divmod(n - 1, m)
+    bet_max_top = (
+        ((m**2) * ((s + 1) ** 2))
+        + (m * (s + 1) * (2 * t - s - 1))
+        - (t * ((2 * s) - t + 3))
+    ) / 2.0
+    p, r = divmod(m - 1, n)
+    bet_max_bot = (
+        ((n**2) * ((p + 1) ** 2))
+        + (n * (p + 1) * (2 * r - p - 1))
+        - (r * ((2 * p) - r + 3))
+    ) / 2.0
+
+    values = values[cp.argsort(node_ids)]
+
+    values[top_node_ids] /= bet_max_top
+    values[bottom_node_ids] /= bet_max_bot
+
+    return G._nodearray_to_dict(values)

From 5b44a6d8ad0e71cf4e85fe5b755903a072a11d5d Mon Sep 17 00:00:00 2001
From: Ray Douglass 
Date: Wed, 11 Dec 2024 13:12:02 -0500
Subject: [PATCH 3/4] Update Changelog [skip ci]

---
 CHANGELOG.md | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e69de29bb..aa6a621a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -0,0 +1,44 @@
+# nx-cugraph 24.12.00 (11 Dec 2024)
+
+## 🚨 Breaking Changes
+
+- Add `nx-cugraph` Package Publishing ([#16](https://github.com/rapidsai/nx-cugraph/pull/16)) [@nv-rliu](https://github.com/nv-rliu)
+- Merge fast-forwarded files from cugraph into nx-cugraph ([#13](https://github.com/rapidsai/nx-cugraph/pull/13)) [@nv-rliu](https://github.com/nv-rliu)
+- Update `.pre-commit-config.yaml` and Implement Suggestions ([#12](https://github.com/rapidsai/nx-cugraph/pull/12)) [@nv-rliu](https://github.com/nv-rliu)
+- [CI] Adding CI Workflows: checks, changed-files, builds ([#6](https://github.com/rapidsai/nx-cugraph/pull/6)) [@nv-rliu](https://github.com/nv-rliu)
+- Setting Up New Repo, Adding Files, etc. ([#5](https://github.com/rapidsai/nx-cugraph/pull/5)) [@nv-rliu](https://github.com/nv-rliu)
+
+## 🐛 Bug Fixes
+
+- Add sphinx-lint pre-commit (and some docs fixes) ([#29](https://github.com/rapidsai/nx-cugraph/pull/29)) [@eriknw](https://github.com/eriknw)
+- Update and test `_nx_cugraph._check_networkx_version` ([#24](https://github.com/rapidsai/nx-cugraph/pull/24)) [@eriknw](https://github.com/eriknw)
+- Remove automatic "Python" labeler ([#23](https://github.com/rapidsai/nx-cugraph/pull/23)) [@eriknw](https://github.com/eriknw)
+
+## 📖 Documentation
+
+- Remove `docs/` directory ([#37](https://github.com/rapidsai/nx-cugraph/pull/37)) [@eriknw](https://github.com/eriknw)
+
+## 🛠️ Improvements
+
+- Small Updates to Benchmarks Directory ([#48](https://github.com/rapidsai/nx-cugraph/pull/48)) [@nv-rliu](https://github.com/nv-rliu)
+- Includes all deferred conversion costs in benchmarks ([#34](https://github.com/rapidsai/nx-cugraph/pull/34)) [@rlratzel](https://github.com/rlratzel)
+- Add Bipartite Betweenness Centrality ([#32](https://github.com/rapidsai/nx-cugraph/pull/32)) [@nv-rliu](https://github.com/nv-rliu)
+- Change `degree_type` of `core_number` to `"outgoing"` ([#28](https://github.com/rapidsai/nx-cugraph/pull/28)) [@eriknw](https://github.com/eriknw)
+- Drop support for NetworkX 3.0 and 3.1 ([#27](https://github.com/rapidsai/nx-cugraph/pull/27)) [@eriknw](https://github.com/eriknw)
+- remove versioning workaround for nightlies ([#26](https://github.com/rapidsai/nx-cugraph/pull/26)) [@jameslamb](https://github.com/jameslamb)
+- add devcontainers ([#25](https://github.com/rapidsai/nx-cugraph/pull/25)) [@jameslamb](https://github.com/jameslamb)
+- Add pre-commit hook to disallow improper comparison to `_nxver` ([#22](https://github.com/rapidsai/nx-cugraph/pull/22)) [@eriknw](https://github.com/eriknw)
+- Add notebooks/demo/accelerating_networkx.ipynb ([#21](https://github.com/rapidsai/nx-cugraph/pull/21)) [@eriknw](https://github.com/eriknw)
+- enforce wheel size limits, README formatting in CI ([#19](https://github.com/rapidsai/nx-cugraph/pull/19)) [@jameslamb](https://github.com/jameslamb)
+- Faster `shortest_path` ([#18](https://github.com/rapidsai/nx-cugraph/pull/18)) [@eriknw](https://github.com/eriknw)
+- nx-cugraph: dispatch graph method to gpu or cpu ([#17](https://github.com/rapidsai/nx-cugraph/pull/17)) [@eriknw](https://github.com/eriknw)
+- Add `nx-cugraph` Package Publishing ([#16](https://github.com/rapidsai/nx-cugraph/pull/16)) [@nv-rliu](https://github.com/nv-rliu)
+- add CI workflows running tests ([#15](https://github.com/rapidsai/nx-cugraph/pull/15)) [@jameslamb](https://github.com/jameslamb)
+- remove more cugraph-only details, other miscellaneous build/packaging changes ([#14](https://github.com/rapidsai/nx-cugraph/pull/14)) [@jameslamb](https://github.com/jameslamb)
+- Merge fast-forwarded files from cugraph into nx-cugraph ([#13](https://github.com/rapidsai/nx-cugraph/pull/13)) [@nv-rliu](https://github.com/nv-rliu)
+- Update `.pre-commit-config.yaml` and Implement Suggestions ([#12](https://github.com/rapidsai/nx-cugraph/pull/12)) [@nv-rliu](https://github.com/nv-rliu)
+- Adding a `dependencies.yaml` file ([#9](https://github.com/rapidsai/nx-cugraph/pull/9)) [@nv-rliu](https://github.com/nv-rliu)
+- [CI] Adding CI Workflows: checks, changed-files, builds ([#6](https://github.com/rapidsai/nx-cugraph/pull/6)) [@nv-rliu](https://github.com/nv-rliu)
+- Setting Up New Repo, Adding Files, etc. ([#5](https://github.com/rapidsai/nx-cugraph/pull/5)) [@nv-rliu](https://github.com/nv-rliu)
+
+

From 511d06f92f763770c3db033318f6ae75b3e1c777 Mon Sep 17 00:00:00 2001
From: Vyas Ramasubramani 
Date: Fri, 20 Dec 2024 14:09:39 -0800
Subject: [PATCH 4/4] Remove sphinx pinning (#60)

This pinning was needed for [historical reasons that are no longer relevant](https://github.com/rapidsai/cucim/pull/481/commits/5cbc80b3a7fa49f25959674d3a97e6d8cf503fcb).

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - James Lamb (https://github.com/jameslamb)
  - Rick Ratzel (https://github.com/rlratzel)

URL: https://github.com/rapidsai/nx-cugraph/pull/60
---
 CHANGELOG.md                                     | 2 --
 conda/environments/all_cuda-118_arch-x86_64.yaml | 2 +-
 conda/environments/all_cuda-125_arch-x86_64.yaml | 2 +-
 dependencies.yaml                                | 2 +-
 4 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa6a621a6..63f92cf38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,5 +40,3 @@
 - Adding a `dependencies.yaml` file ([#9](https://github.com/rapidsai/nx-cugraph/pull/9)) [@nv-rliu](https://github.com/nv-rliu)
 - [CI] Adding CI Workflows: checks, changed-files, builds ([#6](https://github.com/rapidsai/nx-cugraph/pull/6)) [@nv-rliu](https://github.com/nv-rliu)
 - Setting Up New Repo, Adding Files, etc. ([#5](https://github.com/rapidsai/nx-cugraph/pull/5)) [@nv-rliu](https://github.com/nv-rliu)
-
-
diff --git a/conda/environments/all_cuda-118_arch-x86_64.yaml b/conda/environments/all_cuda-118_arch-x86_64.yaml
index 2649a7449..faed92953 100644
--- a/conda/environments/all_cuda-118_arch-x86_64.yaml
+++ b/conda/environments/all_cuda-118_arch-x86_64.yaml
@@ -28,9 +28,9 @@ dependencies:
 - recommonmark
 - scipy
 - setuptools>=61.0.0
+- sphinx
 - sphinx-copybutton
 - sphinx-markdown-tables
-- sphinx<6
 - sphinxcontrib-websupport
 - wheel
 name: all_cuda-118_arch-x86_64
diff --git a/conda/environments/all_cuda-125_arch-x86_64.yaml b/conda/environments/all_cuda-125_arch-x86_64.yaml
index 65caea885..c7fa6f217 100644
--- a/conda/environments/all_cuda-125_arch-x86_64.yaml
+++ b/conda/environments/all_cuda-125_arch-x86_64.yaml
@@ -28,9 +28,9 @@ dependencies:
 - recommonmark
 - scipy
 - setuptools>=61.0.0
+- sphinx
 - sphinx-copybutton
 - sphinx-markdown-tables
-- sphinx<6
 - sphinxcontrib-websupport
 - wheel
 name: all_cuda-125_arch-x86_64
diff --git a/dependencies.yaml b/dependencies.yaml
index 32978cd24..690f26cfa 100644
--- a/dependencies.yaml
+++ b/dependencies.yaml
@@ -125,7 +125,7 @@ dependencies:
           - recommonmark
           - sphinx-copybutton
           - sphinx-markdown-tables
-          - sphinx<6
+          - sphinx
           - sphinxcontrib-websupport
   py_version:
     specific: