fffiloni commited on
Commit
ab33ce3
·
verified ·
1 Parent(s): 57eca73

add driver node

Browse files
Files changed (1) hide show
  1. app.py +116 -1
app.py CHANGED
@@ -15,6 +15,26 @@ logging.basicConfig(
15
  log = logging.getLogger("daggr.micro")
16
 
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  def make_d(seed_d: int, salt_d: int) -> tuple[int, str]:
19
  run_id = uuid.uuid4().hex[:8]
20
  t0 = time.time()
@@ -89,6 +109,97 @@ def observe(b_text: str, note: str) -> str:
89
  return out
90
 
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  D = FnNode(
93
  fn=make_d,
94
  inputs={
@@ -148,7 +259,11 @@ C = FnNode(
148
  outputs={"c_text": gr.Textbox(label="C text")},
149
  )
150
 
151
- graph = Graph(name="micro-restore-debug-nojson", nodes=[D, E, A, B, C], persist_key=False)
 
 
 
 
152
 
153
  port = int(os.getenv("PORT", "7860"))
154
  graph.launch(host="0.0.0.0", port=port, open_browser=False, log_level="debug", access_log=True)
 
15
  log = logging.getLogger("daggr.micro")
16
 
17
 
18
+ import hashlib
19
+
20
+ def _stamp(*parts) -> str:
21
+ h = hashlib.sha1("||".join(map(str, parts)).encode("utf-8")).hexdigest()[:10]
22
+ return h
23
+
24
+ def _phase(title: str):
25
+ log.info("========== %s ==========", title)
26
+
27
+ def _drv(lines, msg: str):
28
+ log.info("[DRV] %s", msg)
29
+ lines.append(msg)
30
+
31
+ def _assert_drv(lines, cond: bool, msg_ok: str, msg_bad: str):
32
+ if cond:
33
+ _drv(lines, f"OK | {msg_ok}")
34
+ else:
35
+ _drv(lines, f"FAIL | {msg_bad}")
36
+
37
+
38
  def make_d(seed_d: int, salt_d: int) -> tuple[int, str]:
39
  run_id = uuid.uuid4().hex[:8]
40
  t0 = time.time()
 
109
  return out
110
 
111
 
112
+ def driver(run_id: int = 1) -> str:
113
+ """
114
+ Driver: exécute une séquence déterministe d'appels Python
115
+ pour valider la logique (phases 0-3) et produire un rapport.
116
+ IMPORTANT: ne met pas à jour l'historique UI des nodes D/E/A/B/C.
117
+ """
118
+ lines = []
119
+ sid = _stamp("driver", run_id, time.time_ns())
120
+ _phase(f"DRIVER start sid={sid}")
121
+ _drv(lines, f"sid={sid}")
122
+ _drv(lines, "NOTE: driver calls functions directly; UI history for D/E/A/B/C will NOT change.")
123
+
124
+ # ----------------
125
+ # PH0 baseline
126
+ # ----------------
127
+ _phase("PH0 baseline")
128
+ d0 = make_d(0, 0)
129
+ e0 = make_e(0, 0)
130
+ a0 = combine(d0[0], d0[1], e0[0], e0[1], 0.5)
131
+ b0 = postprocess(a0[0], a0[1], "none", 1)
132
+ c0 = observe(b0, "hello")
133
+
134
+ _drv(lines, f"PH0 | D={d0} | E={e0}")
135
+ _drv(lines, f"PH0 | A(mix,summary)={a0}")
136
+ _drv(lines, f"PH0 | B(text)={b0}")
137
+ _drv(lines, f"PH0 | C(text)={c0}")
138
+
139
+ # invariants simples
140
+ _assert_drv(lines, isinstance(a0[0], int), "A.mix is int", f"A.mix not int: {type(a0[0])}")
141
+ _assert_drv(lines, "alpha=0.50" in a0[1], "A.summary contains alpha", "A.summary missing alpha")
142
+ _assert_drv(lines, "mix=" in a0[1], "A.summary contains mix", "A.summary missing mix")
143
+
144
+ # ----------------
145
+ # PH1A D versions
146
+ # ----------------
147
+ _phase("PH1A D versions (E fixed)")
148
+ for sd in [1, 2]:
149
+ d = make_d(sd, 0)
150
+ a = combine(d[0], d[1], e0[0], e0[1], 0.5)
151
+ _drv(lines, f"PH1A | seed_d={sd} => D={d} | A={a}")
152
+ _assert_drv(lines, a[0] == int(d[0] * 0.5 + e0[0] * 0.5), "A.mix matches weighted sum", "A.mix mismatch")
153
+
154
+ # ----------------
155
+ # PH1B E versions (D fixed)
156
+ # ----------------
157
+ _phase("PH1B E versions (D fixed to seed=2)")
158
+ d2 = make_d(2, 0)
159
+ for se in [1, 2]:
160
+ e = make_e(se, 0)
161
+ a = combine(d2[0], d2[1], e[0], e[1], 0.5)
162
+ _drv(lines, f"PH1B | seed_e={se} => E={e} | A={a}")
163
+ _assert_drv(lines, a[0] == int(d2[0] * 0.5 + e[0] * 0.5), "A.mix matches weighted sum", "A.mix mismatch")
164
+
165
+ # ----------------
166
+ # PH2 alpha variations (same upstream pair)
167
+ # ----------------
168
+ _phase("PH2 alpha variations (D=2,E=1)")
169
+ d = make_d(2, 0)
170
+ e = make_e(1, 0)
171
+ for alpha in [0.2, 0.8, 0.35]:
172
+ a = combine(d[0], d[1], e[0], e[1], alpha)
173
+ _drv(lines, f"PH2 | alpha={alpha:.2f} => A={a}")
174
+ _assert_drv(lines, f"alpha={alpha:.2f}" in a[1], "A.summary alpha matches", "A.summary alpha mismatch")
175
+
176
+ # ----------------
177
+ # PH3 downstream noise
178
+ # ----------------
179
+ _phase("PH3 downstream noise")
180
+ a = combine(d[0], d[1], e[0], e[1], 0.35)
181
+ for mode, bump in [("add", 1), ("add", 2), ("mul", 2)]:
182
+ b = postprocess(a[0], a[1], mode, bump)
183
+ c = observe(b, f"note-{mode}-{bump}")
184
+ _drv(lines, f"PH3 | B({mode},{bump}) => {b}")
185
+ _drv(lines, f"PH3 | C(note-{mode}-{bump}) => {c}")
186
+
187
+ _phase(f"DRIVER done sid={sid}")
188
+ return "\n".join(lines)
189
+
190
+
191
+ DRIVER = FnNode(
192
+ fn=driver,
193
+ inputs={
194
+ "run_id": gr.Slider(label="Driver run_id", minimum=1, maximum=20, step=1, value=1),
195
+ },
196
+ outputs={
197
+ "report": gr.Textbox(label="Driver report", lines=30),
198
+ },
199
+ )
200
+
201
+
202
+
203
  D = FnNode(
204
  fn=make_d,
205
  inputs={
 
259
  outputs={"c_text": gr.Textbox(label="C text")},
260
  )
261
 
262
+ graph = Graph(
263
+ name="micro-restore-debug-nojson",
264
+ nodes=[D, E, A, B, C, DRIVER],
265
+ persist_key=False,
266
+ )
267
 
268
  port = int(os.getenv("PORT", "7860"))
269
  graph.launch(host="0.0.0.0", port=port, open_browser=False, log_level="debug", access_log=True)