Commit d86c43a
observatory: introduce Region/Session model with enter_context API
Lays the data model and runtime state machine for the worldview adopted
in RFC §4.4-4.5: a lightweight Region (named scope from enter_context;
nests freely; pure labelling) and a heavyweight Session (the outermost
Region; owns lens lifecycle hooks).
interfaces.py
- Add Session dataclass: id, name, start_ts, end_ts, start_data,
end_data. Holds per-session lens hook payloads.
- RecordDigest gains session_id and region_stack (snapshot of the
active region path at collect() time, outermost first). Both default
to "" / [] so existing record reload paths and tests keep working.
- SessionResult now carries an ordered `sessions: List[Session]` list
in addition to the legacy flat start_data/end_data dicts; the flat
views remain a union across sessions for transitional consumers.
- Module docstring spells out the Worldview block (Region/Session/
Record/Archive/Report) so anyone opening the file lands on the
same vocabulary as the RFC.
observatory.py
- Add enter_context(region_name=None, config=None):
* outermost (region_stack empty): pushes a Region; if region_name
is omitted, auto-generates "default" / "default-2" / ... ;
opens a Session and fires on_session_start.
* inner (region_stack non-empty): with a name, pushes a labelled
Region (no Session change); without a name, pure config-only
override (no Region pushed).
- Add _open_session / _close_session helpers; on_session_end fires
cleanly even on exception inside the with-block.
- Reuse path: enable_context becomes a thin alias of enter_context()
(no name) so existing call sites keep working.
- collect() now stamps each Record with the active session_id and
a copy of the active region_stack.
- clear() resets _sessions, _active_session_id, _region_stack, and
_config_stack alongside the legacy state.
tests/test_region_session.py (new)
Twelve focused unit tests covering: outermost with/without name,
inner without name = config-only, inner with name = labelled
Region inside the same Session, sibling outermost = multiple
Sessions, default-name auto-increment, on_session_start/end fire
exactly once per Session boundary (not per inner Region), collect
outside any context is a no-op, time-ordered records, name
uniqueness enforcement, on_session_end on exception, and the
enable_context alias still working.
Verification
PYTHONPATH=~ python -m pytest \
~/executorch/devtools/observatory/tests/ -v
→ 41 passed, 1 pre-existing unrelated failure
(test_per_layer_accuracy_lens, "psnr" key, untouched here).
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>1 parent 80a25ee commit d86c43a
3 files changed
Lines changed: 488 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
18 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
19 | 35 | | |
20 | 36 | | |
21 | 37 | | |
| |||
565 | 581 | | |
566 | 582 | | |
567 | 583 | | |
568 | | - | |
| 584 | + | |
569 | 585 | | |
570 | | - | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
571 | 595 | | |
572 | 596 | | |
573 | 597 | | |
574 | 598 | | |
| 599 | + | |
| 600 | + | |
575 | 601 | | |
576 | 602 | | |
577 | 603 | | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
578 | 634 | | |
579 | 635 | | |
580 | | - | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
581 | 644 | | |
| 645 | + | |
582 | 646 | | |
583 | 647 | | |
584 | 648 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
9 | 20 | | |
10 | | - | |
| 21 | + | |
11 | 22 | | |
12 | 23 | | |
13 | 24 | | |
14 | 25 | | |
15 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
16 | 36 | | |
17 | 37 | | |
18 | 38 | | |
| |||
42 | 62 | | |
43 | 63 | | |
44 | 64 | | |
| 65 | + | |
45 | 66 | | |
46 | 67 | | |
47 | 68 | | |
| |||
81 | 102 | | |
82 | 103 | | |
83 | 104 | | |
84 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
85 | 119 | | |
86 | 120 | | |
87 | 121 | | |
88 | 122 | | |
| 123 | + | |
| 124 | + | |
89 | 125 | | |
90 | 126 | | |
91 | 127 | | |
| 128 | + | |
92 | 129 | | |
93 | 130 | | |
94 | 131 | | |
| |||
126 | 163 | | |
127 | 164 | | |
128 | 165 | | |
129 | | - | |
130 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
131 | 189 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
136 | 193 | | |
137 | 194 | | |
138 | 195 | | |
| |||
150 | 207 | | |
151 | 208 | | |
152 | 209 | | |
153 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
154 | 227 | | |
155 | | - | |
156 | 228 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
165 | 234 | | |
166 | 235 | | |
167 | 236 | | |
168 | 237 | | |
169 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
170 | 243 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
179 | 248 | | |
180 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
181 | 304 | | |
182 | 305 | | |
183 | 306 | | |
| |||
223 | 346 | | |
224 | 347 | | |
225 | 348 | | |
226 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
227 | 355 | | |
228 | 356 | | |
229 | 357 | | |
| |||
256 | 384 | | |
257 | 385 | | |
258 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
259 | 391 | | |
260 | 392 | | |
261 | 393 | | |
| |||
0 commit comments