ADR 0059: triad_count in Python and on the command line, and the triad-bins JSON#
Status: Technical parts accepted under delegation (2026-10-21; GOVERNANCE.md, “Delegation of technical ADRs”); the new public names await the author (naming is not delegated: D9, the Open decisions table; taken on the plan’s defaults until the 0.3.0 release). It carries out M9b step 2 (python-cli-wheels; the M9b acceptance criteria 5-7) under PLAN 5.4-5.7 and 7.7. It changes no rule the author approved: PLAN 5.4’s rules hold as written (enumerations accept strings, no silent narrowing, the GIL released), every CLI option flag is still the kebab-case name of a field, the outputs are the original’s bytes, and no frozen header is edited. The freeze of
dyng.triad_countanddyng triad_countis M9b step 3’s API review (D4).Decided: the author accepted the new public names (D9) on 2026-10-22 (GOVERNANCE.md, approvals log, 2026-10-22);
dyng.triad_countanddyng triad_countarestablefrom 0.3.0 and"dyng.triad_bins"is a stable-tier format at version 1 (the same day’s stability decision).Date: 2026-10-21
Deciders: the AI assistant, on the author’s behalf for the technical parts (M9b, step python-cli-wheels); the names: S M Shovan (2026-10-22)
Builds on: ADR 0011 (the Python layer), ADR 0023 (the uniform contract), ADR 0025 (the command line), ADR 0041 section 1 and ADR 0046 (the hypergraph in Python; its item 10, the
dyng.update()gap), ADR 0049 (the triad oracle), ADR 0052 (the triad_count API).
Context#
dyng::triad_count (ADR 0052) and dyng::update() over hypergraphs exist in C++ since M9a.
PLAN 5.5 shows the Python form (dyng.triad_count.compute(hg), kind="h_motif",
dyng.triad_count.update(hg, hb, tri), st.batch.inserted_ids, st.delta,
dyng.citation("triad_count")); PLAN 5.6 asks for dyng <algo> compute|update with flags from
the option fields and the originals’ output formats; PLAN 5.7 lists “triad bins (JSON)” among the
result writers. ADR 0046 left dyng.update() over hypergraphs to the first hypergraph algorithm.
Four points needed a decision: the name of the container parameter (the uniform contract of the
Python modules says graph), the form of an enumeration that the API names (Pattern in PLAN
5.5’s kind=str|enum), whether counts is a dyng.Array, and what “A’s count lines” means for
a command line that reads files where ESCHER-GPU generates its inputs.
Decision#
1. dyng.triad_count#
Name |
Form |
|---|---|
|
|
|
|
|
30 ( |
|
the C++ fields and defaults (tested equal to the native defaults); |
|
|
|
|
|
|
|
|
The container parameter is
hypergraph. The uniform contract (test_api_surface.py) now reads the first parameter’s name from the registry’scontainer(graphfor the graph algorithms): adyng.Graphnamedgraphand adyng.Hypergraphnamedhypergraphsay what they take.dyng.update(graph, batch, *results)keeps its first parameter’s name (a frozen signature) and takes either container.Patternis the first public enumeration class of the typed layer. PLAN 5.4 rule 5 (enumerations accept strings) holds: every function takes the names; theStrEnumadds a typed, discoverable form (PLAN 5.5’skind=str|enum) without a second spelling, since a member is its string.Result.kindreturns a member, which compares equal to the name.Result.countsis a read-only uint64 NumPy copy, not adyng.Array: the counts are at most 30 host values on every backend (triad_count::result::counts()is host memory), so a copy costs nothing, and it never goes stale.Stats.deltais a read-only int64 array of the result’snum_binsvalues (C++ keeps a fixedstd::arrayof 30). Both are listed inpython_gaps.md.Errors are the library’s (ADR 0011): an unknown name is
InvalidArgumentErrorlisting the names; a pattern that reads the line graph on a hypergraph without it isInvalidArgumentErrorwhose message names the property (hypergraph_properties::line_graph,store_v2h);cuda_engine="operators"on cuda isNotSupportedError.
2. dyng.update() over hypergraphs (closes ADR 0046 item 10)#
python/bindings/update.cpp gains, for both hypergraph instantiations, the branch of a
hypergraph: every result must be a triad_count result, its participant is
detail::make_triad_count_participant<V, W> on the holder’s for_update() state, and the
participants run through participant_of<hypergraph<V, W>>::run(), the path of the C++
dyng::update() (every subtract phase on the old state, one commit, every add phase on the new
one). The hypergraph’s lock and every result’s are taken in address order. Two or more results
on one hypergraph (one per pattern) work; a result passed twice, no result, a graph result, or an
EdgeBatch are refused before anything changes.
3. Triad bins as JSON (<dyng/io/result_io.hpp>, tracked)#
io::triad_bins (kind, graph_version, counts, optional deltas), io::triad_bins_size(),
io::write_triad_bins_json() (a stream and a path overload) and io::read_triad_bins_json().
The document is RFC 8259 JSON, format "dyng.triad_bins", version 1 (docs/api/file_formats.md,
“Triad bins”): keys format, version, kind, num_bins, graph_version, counts, deltas;
integers only where integers are meant; unknown keys ignored (forward compatible within version
1); the errors at line and column. The io module keeps its own list of the four names (it does
not depend on the algorithm; a test checks it against triad_count::to_string()). The reader
is a small strict recursive-descent parser (nesting at most 64 levels) with its libFuzzer target
fuzz_triad_bins (PLAN 5.7: every reader has one; the corpus, the replay and the writer
self-test in every test build). Python: dyng.io.TriadBins (TriadBins.of(result, deltas)),
write_triad_bins(), read_triad_bins(), triad_bins_json(). The oracle is bound too:
dyng.testing.triad_reference(hypergraph, kind, threads=) (ADR 0049’s
testing::triad_reference).
4. dyng triad_count compute|update#
Flags from the fields (ADR 0025 item 2):
--kind,--cuda-enginefromdyng.triad_count.Options; the read flags fromdyng.io.read_hypergraph’s keywords (--index-base,--dedupe-hyperedges,--max-cardinality,--relabel,--num-vertices,--weighted,--storage,--line-graph,--id-reuse,--capacity,--store-v2h), with the help ofHypergraphReadOptions’ fields. The generator of the flags now unwrapsX | Nonebefore it looks atX(abool | Nonekeyword is a--x / --no-xpair, anint | Nonean integer) and gives a union with oneLiteralthatLiteral’s choices (kind: PatternName | Pattern); no existing flag changes (none had such a hint).Not fields:
--read-options escher_gpu|hsospisread_hypergraph’soptions=(the name--optionswould read as the algorithm’s options),--min-initial-payload Nwith--capacity escher_gpuisCapacityPolicy.escher_gpu(N)(ESCHER-GPU’s--payload-capacity),--input(also--hypergraph),--batches FILE...(.dgtor.dgbby the file’s magic, in order),--format json|escher,--output,--compare-recomputeand the backend flags.--format json(the default) writes the triad-bins JSON: the counts (after the last batch) and, forupdate, one delta row per batch.--format escherprints ESCHER-GPU@abcf9b2’s lines byte for byte:Hypergraph: N hyperedges, max vertex id V, P pins(V is the vertex count, ESCHER-GPU’s largest 1-based id), the baseline (Motif counts (30 bins): ...or[GPU] TypeN baseline motif count...), and per batchBatch b (D deletions, I insertions)(only when there is more than one batch, as the original) and the delta line. The[GPU]prefix is the original’s text on every backend. ESCHER-GPU generates its hypergraph and batches; the parity harness records them as.hgand.dgbfiles, and on those files the output is A’s standard output without its generator lines: the testpython/tests/test_triad_count_cli.pydiffs every make-test case (15 groups, 4 executables) against A’s unpatched stdout of the golden set, and in hosted CI the regenerated groups against the committed fixture’s counts.The expected ids of a
.dgbrecording are checked: a batch whose inserted ids differ from the file’s is an error (exit status 1), since later deletions would then name other hyperedges (the hypergraph was not built as the recording’s run built it).
Consequences#
PLAN 5.5’s triad_count lines run as ADR 0041 section 1 and ADR 0046 item 2 adapt them (
st.batch.inserted_idsis already an int64 NumPy array, so the plan’s.to_numpy()is dropped;test_plan_examples.py).python_gaps.mdloses thedyng.update()gap and gains a triad_count table (the copies, the compile-time messages, the oracle’s other entry points);count_local_patternsstays C++/nvcc-only (ADR 0058).Nine reader fuzzers: the fuzz workflow’s dispatch limit is 660 s per target (was 750 s for eight) so that they and the build fit its 120 minutes.
The stubs gain the native names (
TriadPattern,TriadCountOptions,TriadCountStats,TriadCountResult,triad_count_compute,triad_count_update,triad_bins_json,write_triad_bins,read_triad_bins,testing_triad_reference, the hypergraph overloads ofupdate); griffe reports additions only againstorigin/main.