label_propagation#
Binary harmonic label propagation under vertex batches (DynLP). The algorithm page is
label_propagation: binary harmonic label propagation under vertex batches; the containers it reads are the slot rows of
Graphs (Row layouts, vertex batches and capacities), its stream generators are in Generators
and its oracles (dyng::testing::harmonic_solution, union_find, lp_host_model) in
Testing oracles.
The header is frozen since the end of M10b (ADR 0109: The label_propagation API review and freeze (0.4), and per-algorithm kernel groups)
and stable from 0.4.0 (maturity stable; SemVer, PLAN 5.9; the author’s decision of
2026-11-18 on AD15, GOVERNANCE.md): a removed or changed declaration needs the api-change label
and a CHANGELOG entry with a migration note, and fields, enumerators and functions are only
appended. The same holds for <dyng/generators/vertex_arrival.hpp> (Generators). The
three oracle headers (Testing oracles) are frozen too, but outside the stable tier, as the
testing oracles of 0.1-0.3 are.
-
enum class dyng::label_propagation::schedule : std::uint8_t#
The update rule of the propagation (update(); compute() is IrLP’s Jacobi).
Values:
-
enumerator in_place#
The published rule: every iteration updates its frontier in two hashed half-sweeps, each vertex reading its neighbours’ current labels (the second half sees the first’s). Fast; not bitwise reproducible on CUDA (a tolerance, calibrated against the original’s runs).
-
enumerator damped#
1/2-damped Jacobi: every new label F’ = (F + average) / 2 is computed from the labels of the previous iteration and committed after both half-sweeps. Bitwise reproducible per backend and build; the same fixed point.
-
enumerator in_place#
-
enum class dyng::label_propagation::on_limit : std::uint8_t#
What update() does when the propagation reaches options::max_iterations with vertices still changing.
Values:
-
enumerator error#
throw convergence_error (the result is left unusable)
-
enumerator report#
keep the labels and report stats::converged = false (the default) recompute every label with compute()’s IrLP; stats::fallback_used. If IrLP reaches the cap too, its labels are kept and stats::converged is false (compute() would raise convergence_error)
-
enumerator fallback_recompute#
-
enumerator error#
-
template<typename vertex_t, typename edge_t>
result<vertex_t> dyng::label_propagation::compute(const resources &res, const graph<vertex_t, edge_t, float> &g, array_view<const vertex_t> seed_vertices, array_view<const std::int8_t> seed_labels, const options &opt = {})# The static propagation from the seeds: IrLP, the published baseline (the original’s runIrLPSnapshot): Jacobi iterations over every active vertex without a seed label, from 0.5, until no label changes by more than options::tolerance or options::max_iterations.
The neighbours are read from the graph’s current edges with every row sorted by column (the snapshot the original builds from its full graph); a vertex that is not active keeps 0.5. The result’s propagation state starts fresh (no tag consumed: the first update() is the original’s first batch).
- Synchronization:
Blocks until the work has completed (synchronous).
- Backends:
sequential, cuda (IrLP’s kernel verbatim: per snapshot bitwise the original’s)
- Determinism:
Bitwise per backend and build (Jacobi from fixed starting labels).
- Paper:
DynLP (ICS 2026):
dyng::citation("label_propagation"), key dynlp2026 in docs/references.bib; IrLP is the paper’s baseline.- Exception safety:
Strong:
gis not modified, and nothing is kept if the call throws.
- Template Parameters:
vertex_t – Vertex id type.
edge_t – Edge offset type.
- Parameters:
res – [in] Execution resources (sequential or cuda; OpenMP is not a backend of label_propagation in 0.4).
g – [in] An undirected graph with float weights: row_layout::slotted (the published setup; compute() on graph::with_capacity()’s empty graph gives every label 0.5), slack (the streaming mode) or compact. It is not modified.
seed_vertices – [in] The seeds: active vertices of
g, each once (any memory space: read on the host).seed_labels – [in] One class (0 or 1) per seed.
opt – [in] Options.
- Throws:
invalid_argument_error – if
gis directed, an option is out of range (tolerance <= 0 or NaN, max_iterations <= 0, a NaN similarity_threshold), the seed arrays differ in size, a seed is out of range, listed twice, not active, or its label is not 0 or 1, orgis not host storage for host resources.not_supported_error – if the backend of
resis not available for label_propagation (OpenMP in 0.4: the message names sequential and cuda; use dyng.Resources(“sequential”)), or on cuda options::cuda_engine is engine::operators with schedule::in_place (the operators engine runs schedule::damped only).convergence_error – if the cap is reached and options::on_iteration_limit is on_limit::error or on_limit::fallback_recompute (compute() is the recomputation).
out_of_memory_error – if host or device memory cannot be allocated.
cuda_error – if the CUDA runtime reports an error (cuda backend).
- Returns:
The result, matching
g.version().
-
template<typename vertex_t, typename edge_t>
stats dyng::label_propagation::update(const resources &res, graph<vertex_t, edge_t, float> &g, const edge_batch_view<vertex_t, float> &batch, result<vertex_t> &r)# Apply a vertex batch to
gand bring the labelsrup to date (DynLP).The batch holds the arriving vertices (edge_batch_view::insert_vertices, with insert_vertex_labels: -1, or the class 0 / 1 of a new seed), the edges they bring (insert_src / insert_dst / insert_weights) and the departing vertices (delete_vertices), applied with their net effect (batch_semantics::net_effect(), ADR 0069). Then, in the original’s order: the affected vertices (the neighbours of the deleted vertices on the rows before the batch; the inserted vertices; both endpoints of every new edge, also in a batch of edges between present vertices), G’ (the new edges of weight > tau between two inserted vertices) and its components over the inserted vertices (numbered by their smallest vertex in insertion order), the initial labels (each inserted seed its class; every other inserted vertex W1 / (W0 + W1), its component’s summed weights to seeds of class 1 and 0, in 64-bit fixed point, or 0.5 when the sum is at most 1e-10), then the propagation from the affected vertices that are active and have no seed label, with options::update_schedule, until no label changes by more than options::tolerance; finally every seed’s label is its class. Deleted vertices keep their last label; a vertex that never entered the graph (or arrived and left in one batch) stays at 0.5.
After a seed is deleted, labels far from it can stay stale: the propagation starts at the deleted seed’s neighbours and stops where the changes fall below options::tolerance (under schedule::damped each update halves the change), so it may not reach every vertex whose harmonic label moved; those labels catch up when a later batch’s affected vertices reach them.
- Synchronization:
Blocks until the work has completed (synchronous).
- Backends:
sequential, cuda (the fused engine: the original’s pipeline on the resources’ one stream, the graph’s rows resident on the device; ADR 0075)
- Determinism:
schedule::damped: bitwise per backend and build. schedule::in_place: the sequential backend is deterministic (it updates each half-sweep in vertex order); on CUDA a tolerance (the published rule is not reproducible). The deterministic stages (affected set, G’, components, initial labels, the rows) are identical everywhere.
- Paper:
DynLP (ICS 2026).
- Exception safety:
Strong for every error found before the batch is applied (
gandrunchanged); basic after the commit (gupdated,rpoisoned until it is recomputed).
- Template Parameters:
vertex_t – Vertex id type.
edge_t – Edge offset type.
- Parameters:
res – [in] Execution resources (sequential or cuda, the result’s backend: a result moves between them with result::clone()).
g – [inout] The graph: undirected, float weights, row_layout::slotted or slack with batch_semantics::net_effect() (graph::with_capacity()). The batch is applied to it and its version increases by one. A batch that would grow a slack graph’s vertex set (allow_vertex_growth) is refused.
batch – [in] The vertex batch.
r – [inout] Result of compute() or of a previous update() on
g.
- Throws:
stale_result_error – if r.graph_version() != g.version() or
rbelongs to another graph.invalid_argument_error – if the batch breaks the input contract (graph::apply(): an id or endpoint out of range, an id listed twice or inserted a second time, a labelled vertex deleted in the same batch, labels that do not match the insertions), or
gis not undirected, orrbelongs to another backend or device thanres(move it with result::clone()); nothing is changed.capacity_error – if an edge does not fit into its row (an edge delivered twice, or not of the graph the capacities were made for); nothing is changed on the host backends; on cuda the overflow is found on the device after the batch was applied (the graph is poisoned and
runusable; graph::apply()).not_supported_error – if
gdoes not have row_layout::slotted or slack, the batch deletes edges or would grow the vertex set (nothing is changed), or the backend ofresis not available for label_propagation (OpenMP in 0.4: use dyng.Resources(“sequential”)), or on cuda options::cuda_engine is engine::operators with schedule::in_place (the operators engine runs schedule::damped only; nothing is changed).convergence_error – if the cap is reached under on_limit::error (after the batch was applied:
ris left unusable).out_of_memory_error – if host or device memory cannot be allocated.
cuda_error – if the CUDA runtime reports an error (cuda backend; after the batch was applied,
ris left unusable).
- Returns:
Counters of this update.
-
DYNG_LABEL_PROPAGATION_TYPES_MESSAGE#
The message of label_propagation’s static_assert for an unsupported graph type.
-
struct options#
- #include <dyng/label_propagation.hpp>
Options of compute() and update() (an aggregate; fields are only ever appended). Every field is a tunable: set_options() may change it between updates.
Public Members
-
std::optional<float> similarity_threshold#
tau, the sparsification threshold: an edge between two vertices inserted in the same batch joins G’ when its weight is > tau.
A value: the published setup passes generators::vertex_arrival_stream::similarity_threshold (the full graph’s average edge weight, the original’s computeAvgEdgeWeight). std::nullopt (the streaming mode, ADR 0104): the average weight of the live directed entries of the graph after the batch, rounded to float (0.5 for a graph without edges), from a double sum and a count that the result maintains: the first update that needs them (after compute() or set_options()) sums the graph before its batch in vertex order and slot order; then every update takes out, for each deleted vertex in the order of the batch’s deletions (those active before it), the double sum of its row’s live entries in slot order (each entry’s weight, and again for its mirror entry when the neighbour is neither the vertex itself nor deleted in the same batch), and adds the weight of every appended entry in batch order (an edge’s two entries one after the other). The value is deterministic and bitwise the same on every backend; on cuda the rows of the graph before the batch are downloaded to the host for it (not part of the published setup). It must not be NaN.
-
float tolerance = 1e-4F#
delta: a label changes “by more than delta” (> 0)
-
std::int64_t max_iterations = 100000#
The cap of the propagation per update() and of compute()’s iterations (> 0; the original’s default).
-
engine cuda_engine = engine::automatic#
The CUDA engine of update(): engine::automatic or engine::fused (the verbatim port of the original’s pipeline, bitwise the original’s damped labels; ADR 0075), or engine::operators (the framework’s hooks written with label_propagation’s operators, schedule::damped only, the fused engine’s bits; ADR 0101; not_supported_error from compute() and update() under schedule::in_place). compute() is IrLP on every engine. Ignored on the host backends.
-
std::optional<float> similarity_threshold#
-
struct stats : public dyng::update_stats#
- #include <dyng/label_propagation.hpp>
Counters of one update() (fields are only ever appended).
The determinism of the inherited fields (core/stats.hpp’s levels; AD20):
affected(the vertices whose label bits changed),convergedandfallback_usedare deterministic per backend under schedule::damped and schedule-dependent under schedule::in_place (where the labels depend on the order of the updates);iterationsandfrontier_visitsare schedule-dependent (under schedule::damped they repeat from run to run on one backend);engine_usedis deterministic per backend.Public Members
-
apply_summary batch#
Deterministic: what applying the batch did to the graph.
-
std::int64_t components = 0#
Deterministic: the components of the inserted vertices in G’ (0 when none was inserted).
-
std::int64_t sparsified_edges = 0#
Deterministic: the edges of G’ (kept by the tau filter between two inserted vertices).
-
std::int64_t initial_frontier = 0#
Deterministic: the initial frontier of the propagation, |V_aff| (the affected vertices that are active and have no seed label).
-
apply_summary batch#
-
template<typename vertex_t>
class result# - #include <dyng/label_propagation.hpp>
The labels kept up to date by update() (opaque, move-only).
The result owns the label of every vertex, the seed labels, its options, the graph version it matches and the propagation’s run-wide state (the original’s tags: every update consumes at least one).
- Template Parameters:
vertex_t – Vertex id type (std::int32_t).
Public Functions
-
result(result &&other) noexcept#
Move constructor.
- Parameters:
other – [inout] The result to move from; it may only be assigned to or destroyed after.
-
result &operator=(result &&other) noexcept#
Move assignment.
- Parameters:
other – [inout] The result to move from; it may only be assigned to or destroyed after.
- Returns:
*this.
-
~result()#
releases the labels
-
array_view<const float> labels() const#
The labels.
- Throws:
invalid_argument_error – for a moved-from result.
stale_result_error – if a failed update left the result unusable (poisoned).
- Returns:
One label per vertex in [0, 1] (memory space(): host on the host backends, the device of the result’s resources on cuda): a seed’s class exactly (0 or 1); a deleted vertex keeps its last label; a vertex that never entered the graph 0.5 (after compute(): every vertex that is not active 0.5). Valid until the next update() of this result.
-
array_view<const std::int8_t> seed_labels() const#
The seed labels.
- Throws:
invalid_argument_error – for a moved-from result.
stale_result_error – if a failed update left the result unusable (poisoned).
- Returns:
One per vertex: -1 (none), or the class 0 / 1 of a seed (given to compute() or inserted with a label by a batch; kept when the vertex is deleted), host memory.
-
const options &get_options() const#
The options.
- Throws:
invalid_argument_error – for a moved-from result.
stale_result_error – if a failed update left the result unusable (poisoned).
- Returns:
The options given to compute(), as changed by set_options().
-
void set_options(const options &opt)#
Change the options (every field is a tunable).
The options are checked here one by one; a combination a backend refuses is refused by the next update() (on cuda, options::cuda_engine = engine::operators with schedule::in_place: not_supported_error, nothing changed).
- Parameters:
opt – [in] The new options.
- Throws:
invalid_argument_error – if an option is out of range (tolerance <= 0 or NaN, max_iterations <= 0, a NaN similarity_threshold), or for a moved-from result.
stale_result_error – if a failed update left the result unusable (poisoned).
-
std::uint64_t graph_version() const noexcept#
The graph version this result matches.
-
memory_space space() const noexcept#
The memory space of the labels.
- Returns:
memory_space::host on the host backends, memory_space::device on cuda.
-
result clone(const resources &res) const#
A deep copy for the resources
res(labels, seeds, options, the run-wide state).- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources of the copy.
- Throws:
invalid_argument_error – for a moved-from result.
stale_result_error – if a failed update left the result unusable (poisoned).
not_supported_error – if the backend of
resis not available for label_propagation (OpenMP: use dyng.Resources(“sequential”) or cuda).out_of_memory_error – if the copy cannot be allocated (host or device memory).
cuda_error – if the CUDA runtime reports an error (cuda backend).
- Returns:
The copy.
-
void reserve(const resources &res, std::size_t max_batch_vertices, std::size_t max_batch_edges)#
Size the per-batch workspaces of
resfor batches of up tomax_batch_verticesinserted vertices andmax_batch_edgesedges (the original’s setup), so that the updates of such batches allocate nothing for the result; a larger batch grows them later, with headroom.The graph’s own per-batch storage is the graph’s: on cuda, graph::reserve(res,
max_batch_edges) sizes the device scratch of a batch’s edges, and the graph’s device arrays of a batch’s vertex ids and the page-locked staging of its pageable arrays grow on demand (the first vertex batch’s size exactly, a later larger batch with headroom; ADR 0074), so an update of the published stream allocates in its first two vertex batches at most.
- Synchronization:
Blocks until the work has completed (synchronous).
- Parameters:
res – [in] Execution resources the updates will use.
max_batch_vertices – [in] The largest number of vertex insertions of a batch (generators::vertex_arrival_stream::max_batch_vertices).
max_batch_edges – [in] The largest number of edges of a batch (generators::vertex_arrival_stream::max_batch_edges).
- Throws:
invalid_argument_error – for a moved-from result.
stale_result_error – if a failed update left the result unusable (poisoned).
not_supported_error – if the backend of
resis not available for label_propagation.out_of_memory_error – if the workspaces cannot be allocated (host or device memory).
cuda_error – if the CUDA runtime reports an error (cuda backend).