Skip to content

Conversation

@ANJAN672
Copy link
Contributor

@ANJAN672 ANJAN672 commented Jan 3, 2026

Description

This PR addresses #82 by adding parallel implementations for several "embarrassingly parallel" distance algorithms. These measures are computationally intensive ($O(V \times (V+E))$), making them ideal candidates for parallelization across node-specific shortest path traversals.

Algorithms added:

  • eccentricity (Primary parallel engine)
  • diameter
  • radius
  • center
  • periphery

Key Features:

  • Optimized Strategy: The implementation parallelizes the shortest path calculations for each node using joblib.
  • Performance Policies: Integrated with nxp.should_run_if_large to ensure parallel overhead is only incurred when it provides a meaningful speedup for larger graphs.
  • Smart Fallbacks:
    • Automatically falls back to sequential NetworkX if shortest paths (sp) are precomputed or if a single node (v) is queried.
    • Specifically handles directed and undirected graphs according to NetworkX standards.
  • Clean Registry: Functions are properly registered in interface.py and exported via nx_parallel.algorithms.
  • Documentation: Backend metadata updated so that parallel details appear correctly in the NetworkX documentation.

Testing

  • Added comprehensive unit tests in nx_parallel/algorithms/tests/test_distance_measures.py.
  • Verified that all 108 tests (including existing suite) pass successfully.
  • Correctly handles disconnected graphs and strongly connected components in digraphs (raising NetworkXError as per sequential behavior).

Checklist

@dschult dschult added the type: Enhancement New feature or request label Jan 4, 2026
Copy link
Member

@Schefflera-Arboricola Schefflera-Arboricola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't reviewed the implementation in detail yet but have left a few comments below.

Pls consider taking a look at PR #97 (similar diameter algorithm). And consider cherry-picking relevant commits from that PR and crediting the original author in your commit messages, instead of reimplementing from scratch, to avoid duplication of effort. Thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these tests necessary? we already run nx tests with ParallelGraph obj

temp__init__.py

.DS_Store
.DS_Storeuv.lock

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a typo

Suggested change
.DS_Storeuv.lock
.DS_Store



@nxp._configure_if_nx_active(should_run=nxp.should_run_if_large)
def diameter(G, e=None, usebounds=False, weight=None, get_chunks="chunks"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see usebounds is not being used in the implementation below-- consider using can_run here. Same for the following algorithms..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your guidance, all done as u said !!

@ANJAN672
Copy link
Contributor Author

ANJAN672 commented Jan 6, 2026

Thank you for pointing out PR #97! I reviewed it and noticed that PR #97 implements the specialized iFub4S algorithm for diameter, which is optimized for real-world undirected unweighted graphs. My implementation takes a different approach - it parallelizes the basic eccentricity computation, which then enables parallel versions of diameter, radius, center, and periphery.

The two approaches could potentially complement each other - iFub4S for fast diameter-only calculations, and my implementation for when users need multiple distance measures. Would you like me to integrate both approaches, or keep them as separate implementations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: Enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

3 participants