Skip to content

Conversation

@ZLBillShaw
Copy link

Summary

Fixed infinite loop bug in label propagation algorithm caused by synchronous updates leading to oscillation in certain graph structures.

Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation/Tests

Objective

The previous implementation of the label propagation algorithm in community_operations.py used synchronous updates where all nodes update their community labels simultaneously. This approach can cause oscillation in certain graph topologies (e.g., bipartite graphs, regular graphs), where nodes continuously swap between two or more community assignments without ever converging, resulting in infinite loops.

Root Cause:

  • Synchronous updates create systematic patterns that can cause nodes to oscillate
  • No termination guarantee for non-convergent graphs
  • No mechanism to detect or break out of oscillation cycles

Solution:

  1. Asynchronous Updates: Process nodes in randomized order each iteration, breaking systematic oscillation patterns
  2. Maximum Iteration Limit: Set MAX_ITERATIONS = 100 to guarantee termination
  3. Oscillation Detection: Track recent state history and detect when the algorithm enters a cycle
  4. Deterministic Tie-Breaking: Improved sorting for consistent results across runs

- Changed from synchronous to asynchronous updates with randomized node order
- Added maximum iteration limit (100) to prevent infinite loops
- Implemented oscillation detection with early stopping mechanism
- Improved tie-breaking with deterministic sorting
- Added detailed logging for convergence and oscillation events

The previous implementation used synchronous updates where all nodes
updated simultaneously, which could cause oscillation in certain graph
structures (e.g., bipartite graphs). This fix ensures the algorithm
always terminates and produces stable community assignments.
Copy link
Collaborator

@prasmussen15 prasmussen15 left a comment

Choose a reason for hiding this comment

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

Are you able to fix the failing test case?

- Changed from synchronous to asynchronous updates with randomized node order
- Added maximum iteration limit (100) to prevent infinite loops
- Implemented oscillation detection with early stopping mechanism
- Improved tie-breaking with deterministic sorting
- Added detailed docstring and logging for convergence/oscillation events
- Fixed oscillation detection to properly break out of nested loops

The previous implementation used synchronous updates where all nodes
updated simultaneously, which could cause oscillation in certain graph
structures (e.g., bipartite graphs). This fix ensures the algorithm
always terminates and produces stable community assignments while
maintaining backward compatibility with existing tests.
@ZLBillShaw
Copy link
Author

ZLBillShaw commented Dec 12, 2025

Are you able to fix the failing test case?

Yes, I've fixed the failing test case.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants