1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Bridge between god-graph's [`EditOperation`] and tokitai's
//! [`WitnessSample`].
//!
//! god-graph's `tensor::differentiable` module represents
//! neural-architecture-search edits (edge / node add / remove / modify)
//! as a discrete enum; tokitai's `verify::witnesses` module defines
//! `WitnessSample<T>` (label, observed, expected) as a first-class
//! sample type. The bridge turns each [`EditOperation`] into a
//! concrete `WitnessSample<i64>` that downstream code can pass through a
//! `ValuationAdditivityWitness` / `UltrametricWitness` /
//! `PrecisionPreservationWitness` batch.
//!
//! The numeric `observed` / `expected` values are produced by
//! hashing the edit fields with [`std::collections::hash_map::DefaultHasher`].
//! god-graph edits are *structural* — they don't carry natural numeric values
//! — so the hash is the only compact numeric value we can extract. The exact
//! hash value is not a stable public contract across Rust releases; use the
//! label and original edit fields for persistent identity. The bridge
//! deliberately writes `observed == expected`: the result is a traceability /
//! self-consistency sample, not evidence that an optimization edit is correct.
//! The label is a human-readable description of the edit kind.
//!
//! This module is gated on both the `graph` and the `operator`
//! features, since the witness is consumed by the tokitai verify
//! layer.
use DefaultHasher;
use ;
use ;
use WitnessSample;
use crateBridgeError;
/// Convert a god-graph [`EditOperation`] into a traceability
/// [`WitnessSample<i64>`].
///
/// The label describes the edit; `observed` and `expected` are both
/// set to a hash of the edit fields, so the sample is always
/// self-consistent (i.e. `is_satisfied()` is always `true`). The value is
/// suitable for same-build traceability and deterministic replay of bridge
/// metadata, but it is not a stable cross-Rust-version identifier. It is not
/// a witness that an optimizer's proposed edit is mathematically correct.
///
/// # Errors
///
/// Always returns `Ok` for the variants of `EditOperation` that exist
/// in god-graph v0.6.0-alpha. We keep the `Result` return type so
/// future edits (e.g. `EditOperation::Custom`) can fail without
/// breaking the public signature.
///
/// # Example
///
/// ```rust
/// # #[cfg(all(feature = "graph", feature = "operator"))]
/// # fn demo() {
/// use god_graph::tensor::differentiable::{EdgeEditOp, EditOperation};
/// use tokitai_dl::witness_bridge::traceability_sample_of_edit_op;
///
/// let edit = EditOperation::EdgeEdit(0, 1, EdgeEditOp::Add);
/// let witness = traceability_sample_of_edit_op(&edit).unwrap();
/// assert_eq!(witness.label, "edge_add:0->1");
/// // The bridge records a self-consistent traceability sample.
/// assert!(witness.is_satisfied());
/// # }
/// ```
/// Compatibility wrapper for [`traceability_sample_of_edit_op`].
///
/// The historical name is kept for callers that already depend on it.
/// Despite the `witness` wording, this function only emits a
/// traceability / self-consistency sample with `observed == expected`;
/// it does not verify optimization correctness.
///
/// # Errors
///
/// Same as [`traceability_sample_of_edit_op`].
/// Hash a sequence of byte fields into an `i64`.
///
/// `DefaultHasher` is enough for same-build traceability samples, but its
/// algorithm is not a stable public contract across Rust releases. We do not
/// use `Hasher::finish()` directly because we want the result to fit in `i64`
/// for the `WitnessSample<i64>` payload.