|
2 | 2 |
|
3 | 3 | import json |
4 | 4 | import math |
5 | | -import re |
6 | 5 | from collections.abc import Iterable, Mapping |
7 | 6 | from datetime import datetime |
8 | 7 | from pathlib import Path |
9 | 8 | from typing import Any |
10 | 9 |
|
11 | 10 | from ...domain_state import default_domain_state_file_path, upsert_domain_state_jsonl |
| 11 | +from .experiment_identity import ( |
| 12 | + ARM_ROLES, |
| 13 | + experiment_token_text as _token, |
| 14 | +) |
12 | 15 | from .factorial_contrast import ( |
13 | 16 | build_benchmark_factorial_contrasts, |
14 | 17 | build_benchmark_metric_delta, |
|
18 | 21 | BENCHMARK_EXPERIMENT_BOARD_SCHEMA_VERSION = "benchmark_experiment_board_v0" |
19 | 22 | BENCHMARK_EXPERIMENT_BOARD_LEDGER_FILENAME = "experiment-board.jsonl" |
20 | 23 |
|
21 | | -_TOKEN_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_.:@+-]{0,127}$") |
22 | | -_ARM_ROLES = {"baseline", "control", "treatment", "explore"} |
23 | 24 | _RUN_STATUSES = {"planned", "running", "completed", "runner_invalid", "cancelled"} |
24 | 25 | _RUN_STATUS_TRANSITIONS = { |
25 | 26 | "planned": _RUN_STATUSES, |
@@ -78,13 +79,6 @@ def _reject_unknown_fields( |
78 | 79 | raise ValueError(f"{field} contains unsupported fields: {', '.join(unknown)}") |
79 | 80 |
|
80 | 81 |
|
81 | | -def _token(value: Any, *, field: str) -> str: |
82 | | - text = str(value or "").strip() |
83 | | - if not _TOKEN_RE.fullmatch(text): |
84 | | - raise ValueError(f"{field} must be a compact public-safe token") |
85 | | - return text |
86 | | - |
87 | | - |
88 | 82 | def _optional_token(value: Any, *, field: str) -> str | None: |
89 | 83 | if value in (None, ""): |
90 | 84 | return None |
@@ -267,7 +261,7 @@ def normalize_benchmark_experiment_board_row( |
267 | 261 | raise ValueError("benchmark experiment board row schema mismatch") |
268 | 262 |
|
269 | 263 | arm_role = _token(payload.get("arm_role"), field="arm_role") |
270 | | - if arm_role not in _ARM_ROLES: |
| 264 | + if arm_role not in ARM_ROLES: |
271 | 265 | raise ValueError("arm_role is unsupported") |
272 | 266 | status = _token(payload.get("status"), field="status") |
273 | 267 | if status not in _RUN_STATUSES: |
@@ -744,12 +738,12 @@ def build_benchmark_experiment_board( |
744 | 738 | ] |
745 | 739 | role_counts = { |
746 | 740 | role: sum(1 for row in normalized if row["arm_role"] == role) |
747 | | - for role in sorted(_ARM_ROLES) |
| 741 | + for role in sorted(ARM_ROLES) |
748 | 742 | } |
749 | 743 | comparison_arm_role_counts = _comparison_lane_counts( |
750 | 744 | comparisons, |
751 | 745 | field="candidate_arm_role", |
752 | | - values=_ARM_ROLES - {"baseline"}, |
| 746 | + values=ARM_ROLES - {"baseline"}, |
753 | 747 | ) |
754 | 748 | comparison_claim_scope_counts = _comparison_lane_counts( |
755 | 749 | comparisons, |
|
0 commit comments