Objective: Efficiently maintain Leiden communities in large dynamic graphs.
| Notation | Meaning |
|---|---|
| A graph with vertex set |
|
| The vertex |
|
| The weight of edge between |
|
| The weighted degree of vertex |
|
| The total weight of all edges in |
|
| A set of communities forming a partition of |
|
| The modularity of the graph |
|
| The supergraph in the |
|
| Modularity gain by moving |
|
| A mapping from vertices to communities | |
| A mapping from supervertices to communities | |
| A mapping from supervertices in |
|
| The set of changed edges in the dynamic graph | |
| Number of hierarchical levels | |
| Connected Component (CC) indices | |
| Resolution parameter | |
| Candidate move set collected in parallel | |
| Decoupled move subset selected from |
|
| Emitter and acceptor community sets in decoupling | |
| Sum of modularity gains of selected moves |
For an undirected weighted graph, the partition quality is measured by:
where
For moving node
$$ \Delta Q(v: C \to C', \gamma) = \frac{w(v,C') - w(v,C)}{2m}
- \gamma,\frac{k_v\left(d(C) - k_v - d(C')\right)}{(2m)^2} $$
where
Input:
-
$G^1 \leftarrow G$ ,$f^1(\cdot) \leftarrow f(\cdot)$ ; -
for
$p = 1$ to$P$ do -
$\quad f^p(\cdot) \leftarrow \text{Move}(G^p, f^p(\cdot), \gamma)$ ; -
$\quad s^p(\cdot) \leftarrow \text{Refine}(G^p, f^p(\cdot), \gamma)$ ; -
$\quad$ if$p < P$ then -
$\quad\quad G^{p+1}, f^{p+1}(\cdot) \leftarrow \text{Aggregate}(G^p, f^p(\cdot), s^p(\cdot))$ ; - Update
$f(\cdot)$ using$s^1(\cdot), \cdots, s^P(\cdot)$ ; -
return
$f(\cdot)$ ;
Input:
-
$A \leftarrow \emptyset$ ,$B \leftarrow \emptyset$ ,$K \leftarrow \emptyset$ ; -
for
$(v_i, v_j, \alpha) \in \Delta G$ do -
$\quad$ if$\alpha > 0$ and$f(v_i) \neq f(v_j)$ then -
$\quad\quad A.add(v_i)$ ;$A.add(v_j)$ ; -
$\quad$ if$\alpha < 0$ and$f(v_i) = f(v_j)$ then -
$\quad\quad A.add(v_i)$ ;$A.add(v_j)$ ; -
$\quad$ if$s(v_i) = s(v_j)$ and$\text{update_edge}(G_\Psi, (v_i, v_j, \alpha))$ then -
$\quad\quad K.add(v_i)$ ;$K.add(v_j)$ ; -
for
$A \neq \emptyset$ do -
$\quad v_i \leftarrow A.pop()$ ; -
$\quad C^* \leftarrow \text{argmax}_{C \in \mathbb{C} \cup \emptyset} \Delta Q(v_i \to C, \gamma)$ ; -
$\quad$ if$\Delta Q(v_i \to C^*, \gamma) > 0$ then -
$\quad\quad f(v_i) \leftarrow C^*$ ;$B.add(v_i)$ ; -
$\quad\quad$ for$v_j \in N(v_i)$ do -
$\quad\quad\quad$ if$f(v_j) \neq C^*$ then -
$\quad\quad\quad\quad A.add(v_j)$ ; -
$\quad\quad$ for$v_j \in N(v_i) \wedge s(v_i) = s(v_j)$ do -
$\quad\quad\quad$ if$\text{update_edge}(G_\Psi, (v_i, v_j, -w(v_i, v_j)))$ then -
$\quad\quad\quad\quad K.add(v_i)$ ;$K.add(v_j)$ ; -
return
$f(\cdot)$ ,$\Psi$ ,$B$ ,$K$ ;
Input:
-
$R \leftarrow \emptyset$ ; -
for
$v_i \in K$ do -
$\quad$ if$v_i$ is not in the largest connected component of$s(v)$ then -
$\quad\quad$ Map all vertices in the connected component into a new sub-community and add them into$R$ ; -
for
$v_i \in R$ do -
$\quad$ if$v_i$ is in singleton sub-community then -
$\quad\quad \mathcal{T} \leftarrow {s(v) | v \in N(v_i) \cap f(v_i), \Delta Q(s(v) \to \emptyset, \gamma) \leq 0}$ ; -
$\quad\quad S^* \leftarrow \text{argmax}_{S \in \mathcal{T}} \Delta M(v_i \to S, \gamma)$ ; -
$\quad\quad$ if$\Delta M(v_i \to S^*, \gamma) > 0$ then -
$\quad\quad\quad s(v_i) \leftarrow S^*$ ; -
$\quad\quad\quad$ for$v_j \in N(v_i)$ do -
$\quad\quad\quad\quad$ if$s(v_i) = s(v_j)$ then -
$\quad\quad\quad\quad\quad \text{update_edge}(G_\Psi, (v_i, v_j, w(v_i, v_j)))$ ; -
return
$s(\cdot)$ ,$\Psi$ ,$R$ ;
Input:
-
$\Delta H \leftarrow \emptyset$ ; -
for
$(v_i, v_j, \alpha) \in \Delta G$ do -
$\quad r_i \leftarrow s_{pre}(v_i)$ ,$r_j \leftarrow s_{pre}(v_j)$ ; -
$\quad \Delta H.add((s_i, s_j, \alpha))$ ; -
for
$v_i \in R$ do -
$\quad$ for$v_j \in N(v_j)$ do -
$\quad\quad$ if$s_{cur}(v_j) = s_{pre}(v_j)$ or$i < j$ then -
$\quad\quad\quad \Delta H.add((s_{pre}(v_i), s_{pre}(v_j), -w(v_i, v_j)))$ ; -
$\quad\quad\quad \Delta H.add((s_{cur}(v_i), s_{cur}(v_j), w(v_i, v_j)))$ ; -
$\quad \Delta H.add((s_{pre}(v_i), s_{pre}(v_i), -w(v_i, v_i)))$ ; -
$\quad \Delta H.add((s_{cur}(v_i), s_{cur}(v_i), w(v_i, v_i)))$ ; -
for
$v_i \in R$ do -
$\quad s_{pre}(v_i) \leftarrow s_{cur}(v_i)$ ; -
$\text{Compress}(\Delta H)$ ; -
return
$\Delta H$ ,$s_{pre}(\cdot)$ ;
Input:
-
for
$p$ from$P$ to 1 do -
$\quad$ if$p \neq P$ then -
$\quad\quad$ for$v_i^p \in B^p$ do -
$\quad\quad\quad f^p(v_i^p) = f^{p+1}(s^p(v_i^p))$ ; -
$\quad$ if$p \neq 1$ then -
$\quad\quad$ for$v_i^p \in B^p$ do -
$\quad\quad\quad B^{p-1}.add(s^{-p}(v_i^p))$ ; -
return
${f^P(\cdot)}$ ;
Input:
-
$\Delta G^1 \leftarrow \Delta G$ ; -
for
$p$ from 1 to$P$ do -
$\quad G^p \leftarrow G^p \oplus \Delta G^p$ ; -
$\quad f^p(\cdot), \Psi, B^p, K \leftarrow \text{inc-movement}(G^p, \Delta G^p, f^p(\cdot), s_{cur}^p(\cdot), \Psi, \gamma)$ ; -
$\quad s_{cur}^p(\cdot), \Psi, R^p \leftarrow \text{inc-refinement}(G^p, f^p(\cdot), s_{cur}^p(\cdot), \Psi, K, \gamma)$ ; -
$\quad$ if$p < P$ then -
$\quad\quad \Delta G^{p+1}, s_{pre}^p(\cdot) \leftarrow \text{inc-aggregation}(G^p, \Delta G^p, s_{pre}^p(\cdot), s_{cur}^p(\cdot), R^p)$ ; -
${f^P(\cdot)} \leftarrow \text{def-update}({f^P(\cdot)}, {s_{cur}^P(\cdot)}, {B^P}, P)$ ; -
${g^P(\cdot)} \leftarrow \text{def-update}({g^P(\cdot)}, {s_{cur}^P(\cdot)}, {R^P}, P)$ ; -
$f(\cdot) \leftarrow g^1(\cdot)$ ; -
return
$f(\cdot)$ ,${G^P}$ ,${f^P(\cdot)}$ ,${g^P(\cdot)}$ ,${s_{pre}^P(\cdot)}$ ,${s_{cur}^P(\cdot)}$ ,${\Psi^P}$ ;
The current throughput implementation adds three safeguards/extensions to the baseline pseudocode above.
In throughput mode, line 11 of Algorithm 2 is split into candidate generation and decoupled selection:
- Build candidate moves in parallel as records equivalent to Rust
MoveCandidate { node, from_comm, to_comm, node_degree, gain }: $$ M = {(v, C_{from}, C_{to}, d(v), \Delta Q(v\to C_{to},\gamma))} $$ - Sort
$M$ by descending$\Delta Q$ . - Greedily select decoupled moves into
$\hat{M}$ while tracking:-
$E_{emit}$ : communities that already emit, -
$E_{acc}$ : communities that already accept.
-
- Accept a candidate
$(v, C_{from}, C_{to}, \dots)$ iff: $$ C_{from} \notin E_{acc} \quad \land \quad C_{to} \notin E_{emit} $$ then update: $$ E_{emit} \leftarrow E_{emit}\cup{C_{from}},\quad E_{acc} \leftarrow E_{acc}\cup{C_{to}} $$
In code, this corresponds to select_decoupled_moves(...), which also enforces one move per node (moved_nodes).
This matches the decoupling rule from the paper (no move leaves an acceptor or enters an emitter).
Before applying selected moves, throughput computes total_gain:
$$
\Sigma\Delta Q(\hat{M}) = \sum_{m\in\hat{M}} \Delta Q(m)
$$
If:
$$
\Sigma\Delta Q(\hat{M}) \le 0
$$
then no move from this batch is applied.
In line 6-7 of Algorithm 6, throughput now skips inc-aggregation when both are true:
-
$\Delta G^p$ is empty, and -
$R^p$ is empty.
Formally, define:
$$
\operatorname{skip}(p) = (|\Delta G^p| = 0) \land (|R^p| = 0)
$$
If
In code this predicate is implemented by:
should_skip_aggregation(delta_graph, refined_nodes).
For the standalone multilevel movement path (outside Algorithm 6 incremental updates), parallel movement remains safety-gated off in throughput mode until full quality parity is guaranteed. Incremental throughput in Algorithm 6 remains enabled with T1-T3.
This appendix maps mathematical symbols and algorithm operators to concrete Rust symbols in the current implementation.
| Math symbol | Rust symbol(s) | Location |
|---|---|---|
GraphInput, InMemoryGraph
|
src/core/types.rs, src/core/graph/in_memory.rs
|
|
delta_g, delta_graph, current_delta
|
src/core/algorithm/hit_leiden.rs |
|
state.node_to_comm |
src/core/algorithm/hit_leiden.rs |
|
state.community_mapping_per_level[p] |
src/core/algorithm/hit_leiden.rs |
|
state.refined_community_mapping_per_level[p] |
src/core/algorithm/hit_leiden.rs |
|
state.previous_subcommunity_mapping_per_level[p] |
src/core/algorithm/hit_leiden.rs |
|
state.current_subcommunity_mapping_per_level[p] |
src/core/algorithm/hit_leiden.rs |
|
state.levels, p_max
|
src/core/algorithm/hit_leiden.rs |
|
gamma, resolution_parameter
|
src/core/algorithm/hit_leiden.rs, throughput.rs
|
|
node_degrees[node], current_node_degree
|
hit_leiden.rs, throughput.rs, parallel_frontier.rs
|
|
twice_total_weight |
hit_leiden.rs, throughput.rs, parallel_frontier.rs
|
| Spec operator | Rust function | Location |
|---|---|---|
Move / inc-movement |
inc_movement(...) |
src/core/algorithm/hit_leiden.rs |
parallel inc-movement shard eval |
execute_shard(...) |
src/core/algorithm/parallel_frontier.rs |
parallel inc-movement orchestrator |
inc_movement_parallel(...) |
src/core/algorithm/throughput.rs |
Refine / inc-refinement |
inc_refinement(...) |
src/core/algorithm/hit_leiden.rs |
parallel inc-refinement |
inc_refinement_parallel(...) |
src/core/algorithm/throughput.rs |
Aggregate / inc-aggregation |
inc_aggregation(...) |
src/core/algorithm/hit_leiden.rs |
def-update |
def_update(...) |
src/core/algorithm/hit_leiden.rs |
| HIT-Leiden loop | hit_leiden(...) |
src/core/algorithm/hit_leiden.rs |
| multilevel Leiden path | multilevel_leiden(...) |
src/core/algorithm/hit_leiden.rs |
| Math symbol | Rust symbol(s) | Location |
|---|---|---|
Vec<MoveCandidate> all_candidates |
src/core/algorithm/throughput.rs |
|
| candidate record | MoveCandidate { node, from_comm, to_comm, node_degree, gain } |
src/core/algorithm/parallel_frontier.rs |
selected_moves |
src/core/algorithm/throughput.rs |
|
| decoupling selector | select_decoupled_moves(...) |
src/core/algorithm/throughput.rs |
emitters: HashSet<usize> |
src/core/algorithm/throughput.rs |
|
acceptors: HashSet<usize> |
src/core/algorithm/throughput.rs |
|
| one-move-per-node constraint | moved_nodes: HashSet<usize> |
src/core/algorithm/throughput.rs |
total_gain: f64 |
src/core/algorithm/throughput.rs |
|
| changed node set |
shared_changed / changed_nodes
|
throughput.rs, hit_leiden.rs
|
| affected refinement set |
shared_affected / affected_nodes_for_refinement
|
throughput.rs, hit_leiden.rs
|
| Spec concept | Rust symbol(s) | Location |
|---|---|---|
| skip aggregation when no delta and no refinement | should_skip_aggregation(delta_graph, refined_nodes) |
src/core/algorithm/hit_leiden.rs |
| multilevel throughput safety gate | const USE_PARALLEL_MULTILEVEL_MOVEMENT: bool = false |
src/core/algorithm/hit_leiden.rs |
| max movement iterations (throughput) | const MAX_MOVEMENT_ITERATIONS: usize = 20 |
src/core/algorithm/hit_leiden.rs |
| lock-free bitsets for parallel writes | SharedBitVec |
src/core/algorithm/parallel_frontier.rs |