triad_count#

hypergraph h-motif triad counts. The algorithm page is triad_count: hypergraph h-motif triad counts.

The header is frozen and stable from 0.3.0 (maturity stable, the author’s decision of 2026-10-22, GOVERNANCE.md; ADR 0060: The triad_count API review and freeze (0.3)): a removed or changed declaration needs the api-change label and a CHANGELOG entry. Its extension point, a pattern of your own counted by the same engine, is the experimental API (count_local_patterns), which stays experimental: it may change in any minor release.

enum class dyng::triad_count::pattern : std::uint8_t#

What a result counts.

Values:

enumerator h_motif#

the 30 h-motifs (bins 20-25, the open triads, are always 0)

enumerator stathyper_type1#

one bin: the sum of C(|e|, 3) over the live hyperedges

enumerator stathyper_type2#

one bin: the sum of C(a, 2) * b * c over the adjacent pairs

enumerator stathyper_type3#

one bin: the sum of x * y * z over the triads

constexpr int dyng::triad_count::max_bins = 30#

The number of bins of pattern::h_motif, the size of stats::delta.

The most bins a pattern of triad_count has; a pattern appended later has at most as many (a count of more bins is an Op of experimental::count_local_patterns, whose bins are its own).

std::string_view dyng::triad_count::to_string(pattern p) noexcept#

The lower-case name of a pattern (“h_motif”, “stathyper_type1”, “stathyper_type2”, “stathyper_type3”).

Parameters:

p – [in] The pattern.

Returns:

A static string naming p (the enumerator’s name).

template<typename vertex_t, typename weight_t>
result dyng::triad_count::compute(const resources &res, const hypergraph<vertex_t, weight_t> &h, const options &opt = {})#

Count the triads of h (the static count, the oracle of update()).

h_motif and type 3: every triangle (a, b, c) of the line graph with a < b < c is counted once, from its out-wedge (a, b): the rows of a after b and of b after b are intersected for the closing c, and the triad is classified with the three hyperedges’ member sets (one merge over the three rows). Type 2 visits every pair of adjacent hyperedges (a, b), a < b, once, and type 1 every live hyperedge. The CUDA backend runs one thread per out-wedge for h_motif and types 2 and 3, and a grid-stride loop over the hyperedges for type 1 (ESCHER-GPU’s full counts); the host backends loop over the same wedges and hyperedges.

Synchronization:

Blocks until the work has completed (synchronous). The counts are complete on return (a host array on every backend).

Backends:

sequential, openmp, cuda

Determinism:

Exact values: identical counts on every backend and thread count.

Exception safety:

Strong: h is not modified (its line graph may be built under line_graph_policy::automatic, which changes no observable state but h2h()’s availability), and nothing is kept if the call throws.

Paper:

ESCHER (IPDPS 2026) and ESCHER+ (TKDE 2026): dyng::citation("triad_count"), keys escher2026 and escherplus2026 in docs/references.bib.

Template Parameters:
  • vertex_t – Vertex id type (int32_t).

  • weight_t – Hyperedge weight type (unweighted or int32_t; ignored).

Parameters:
  • res – [in] Execution resources.

  • h – [in] The hypergraph; it is not modified (under line_graph_policy::automatic its line graph is built here, once, for the patterns that read it).

  • opt – [in] Options.

Throws:
Returns:

The counts, matching h.version().

template<typename vertex_t, typename weight_t>
stats dyng::triad_count::update(const resources &res, hypergraph<vertex_t, weight_t> &h, const hyperedge_batch_view<vertex_t, weight_t> &batch, result &r)#

Apply a batch of hyperedge changes to h and update the counts r.

The triads through the deleted hyperedges are subtracted on the hypergraph before the batch, the batch is applied once, and the triads through the inserted hyperedges are added on the hypergraph after it, each attributed to exactly one changed hyperedge (the smallest id among its phase’s changes in it; see triad_count). Postcondition: r equals compute(res, h, r.get_options()) exactly.

Exception safety:

).

Synchronization:

Blocks until the work has completed (synchronous). The hypergraph and the counts are updated on return.

Backends:

sequential, openmp, cuda

Determinism:

Exact values: identical counts and counters on every backend and thread count.

Exception safety:

Strong for every error found before the batch is applied (the ones marked “nothing is

changed” above, and allocation failures before the commit):

h and r are unchanged. Basic for an error inside the commit (an allocation, storage-capacity or CUDA failure of hypergraph::apply’s store operations): h is poisoned (as hypergraph::apply), and r is not changed and not poisoned: it keeps the counts of the hypergraph before the batch, and must be recomputed with compute() once h is rebuilt (an update of r on the rebuilt hypergraph throws stale_result_error). Basic for an error after the commit (a negative bin, an unclassifiable triad, a count past 2^64 - 1 or outside stats::delta’s range, a CUDA or allocation failure): h holds the new version and r is poisoned, so every later use of it throws stale_result_error until it is recomputed.

Paper:

ESCHER (IPDPS 2026) and ESCHER+ (TKDE 2026): dyng::citation("triad_count").

Template Parameters:
  • vertex_t – Vertex id type (int32_t).

  • weight_t – Hyperedge weight type (unweighted or int32_t; ignored).

Parameters:
  • res – [in] Execution resources.

  • h – [inout] The hypergraph; the batch is applied to it and its version increases by one.

  • batch – [in] Hyperedge deletions (by id) and insertions (host memory, or device memory under the copy policy of res).

  • r – [inout] Result of compute() or of a previous update() on h.

Throws:
  • stale_result_error – if r.graph_version() != h.version(), r was computed on another hypergraph, or r was left unusable by a failed update.

  • invalid_argument_error – if a batch member or weight is invalid, h belongs to another backend than res, or h was poisoned (nothing is changed).

  • not_supported_error – if the backend of res is not available for triad_count, options::cuda_engine is engine::operators on cuda, the batch has incidence edits (they need slack_csr storage), or h has hypergraph_storage::slack_csr (0.4: triad_count reads the escher storage only; nothing is changed).

  • internal_error – if a bin would become negative, or the device engine meets a triad it cannot classify (a library bug; then the hypergraph was updated and r is left unusable).

  • capacity_error – if a count exceeds 2^64 - 1 or the change of a bin is outside the signed 64-bit range of stats::delta (2^63 or more triads added or removed on balance; both after the batch was applied: r is left unusable), or the hypergraph’s storage cannot hold the batch (as hypergraph::apply).

  • out_of_memory_error – if host or device memory cannot be allocated (before the commit: nothing is changed; inside it: h is poisoned; after it: r is poisoned; see

  • cuda_error – if the CUDA runtime reports an error.

Returns:

Counters of this update (all deterministic; stats::batch.inserted_ids: the ids of the inserted hyperedges).

DYNG_TRIAD_COUNT_TYPES_MESSAGE#

The message of triad_count’s static_assert for an unsupported hypergraph type.

DYNG_TRIAD_COUNT_CONTAINER_MESSAGE#

The message of triad_count’s static_assert for a container that is not a hypergraph.

struct options#

Options of compute() and update() (an aggregate; fields are only ever appended).

kind is fixed at compute() (the result counts that pattern). cuda_engine is a tunable: it chooses how the cuda backend counts, never what it counts, and result::set_options() changes it.

Public Members

pattern kind = pattern::h_motif#

what the result counts; fixed at compute()

engine cuda_engine = engine::automatic#

The CUDA engine: automatic and fused select the wedge engine (ESCHER-GPU’s kernels, the Tier B engine of docs/developer/framework.md); operators throws not_supported_error (triad_count has no operators engine). Ignored on the host backends. A tunable (result::set_options()).

struct stats : public dyng::update_stats#

Counters of one update() (fields are only ever appended).

Every counter is deterministic (identical on every backend, thread count and run). The inherited fields mean:

Public Members

hyper_apply_summary batch#

What applying the batch did to the hypergraph (the inserted ids among it).

std::int64_t deleted_frontier = 0#

The hyperedges of the subtract phase: the live ids the batch deleted (distinct).

std::int64_t inserted_frontier = 0#

The hyperedges of the add phase: the hyperedges the batch inserted.

std::uint64_t triads_removed = 0#

The triads the batch destroyed, summed over the bins: the count of the subtract phase. For the types 1-3, whose one bin is a sum of contributions (C(|e|, 3), C(a, 2) * b * c, x * y * z; the hyperedge weights are ignored), the contributions the batch removed.

std::uint64_t triads_added = 0#

The triads the batch created, summed over the bins: the count of the add phase (types 1-3: the contributions the batch added).

std::array<std::int64_t, max_bins> delta = {}#

The change of every bin: counts() after the update minus counts() before it (bins at and above result::num_bins() are 0). A fixed-size array, so the stats allocate nothing.

class result#

Triad counts kept up to date by update() (opaque, move-only).

counts()[k] is the count of bin k: num_bins() is 30 for pattern::h_motif and 1 for the types. The counts are 64-bit host arrays on every backend. The scratch memory of the engines is leased from the resources handle (ADR 0015), not owned.

Thread safety. A result is not thread-safe: its accessors may run concurrently with each other, but not with an update() of it (or a dyng::update() that includes it), which must also not overlap another call on its hypergraph.

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(const result&) = delete#

not copyable: use clone()

result &operator=(const result&) = delete#

not copyable: use clone()

~result()#

releases the counts

pattern kind() const#

What the result counts.

Throws:
Returns:

options::kind of compute().

int num_bins() const#

The number of bins.

Throws:
Returns:

30 for pattern::h_motif, 1 for the types.

array_view<const std::uint64_t> counts() const#

The counts.

Throws:
Returns:

counts[k] = the count of bin k (host memory), num_bins() entries. Valid until the next update() of this result.

std::uint64_t count(int bin) const#

The count of one bin.

Parameters:

bin – [in] A bin in [0, num_bins()).

Throws:
Returns:

The count.

std::uint64_t total() const#

The count of every bin.

Throws:
Returns:

The sum of counts() (for pattern::h_motif: the number of triads).

const options &get_options() const#

The options.

Throws:
Returns:

The options given at compute(), as changed by set_options().

void set_options(const options &opt)#

Change the tunables (cuda_engine); the next update() uses them.

Exception safety:

Strong: every check runs before the options change.

Parameters:

opt – [in] The new options; kind must stay the same.

Throws:
  • invalid_argument_error – if opt.kind differs from the result’s, a field holds an invalid value, 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 hypergraph version this result matches.

Returns:

The version of the hypergraph after the last compute() / update() of this result.

memory_space space() const noexcept#

The memory space of the counts.

Returns:

memory_space::host (on every backend).

result clone(const resources &res) const#

A deep copy for the resources res (the counts are a host array on every backend).

Synchronization:

Blocks until the work has completed (synchronous). The copy is complete on return (host memory on every backend).

Parameters:

res – [in] Execution resources of the copy (any backend).

Throws:
Returns:

The copy.