Complete M2 validation and lock the G1 evaluation protocol

Run and record both blind LLM validation passes and the external
cross-checks. Freeze the evaluation inputs, well splits, and reporting
scope with a SHA-256 checksum.

Use NPT definition b for DDR-code prediction with definition a as a
sensitivity analysis. Retain the class reporting thresholds and record
the empty set of eligible classes. Make T4 and OCR fidelity the headline
analyses and align the progress report and project documentation.

Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
2026-11-18 04:13:13 +00:00
parent 5ffc8b3008
commit 2b59d635ce
24 changed files with 3305 additions and 338 deletions

View File

@@ -13,6 +13,8 @@ import math
import numpy as np
import pandas as pd
from volve_dia import paths
#: Values the rater may choose (labels.yaml t2.cause_groups without hse, t1.op_classes without interruption).
CAUSES = ("equipment", "weather", "waiting", "stuck_fishing", "lost_circulation", "well_control", "sidetrack",
"operation_failed", "unspecified")
@@ -20,6 +22,17 @@ OP_CLASSES = ("drill_ream", "trip", "casing_cement", "circulate", "bop_wellhead"
"perforate", "wireline", "plug_abandon", "rig_move", "rig_up_down", "wait", "other")
def load_activity_labels() -> pd.DataFrame:
d = paths.outputs_dir() / "labels"
x = pd.read_parquet(d / "t2_inputs.parquet")
lab = pd.read_parquet(d / "t2_labels.parquet")[["act_id", "npt_a", "npt_b", "cause_a", "cause_b"]]
ops = pd.read_parquet(d / "t1_activities.parquet")[["act_id", "op_class"]]
x = x.sort_values(["report_id", "seq"])
g = x.groupby("report_id")["comments"]
x["prev_comment"], x["next_comment"] = g.shift(1), g.shift(-1)
return x.merge(lab, on="act_id", validate="1:1").merge(ops, on="act_id", validate="1:1")
def allocate(sizes: dict[str, int], k: int, minimum: int) -> dict[str, int]:
"""Split k items over strata: `minimum` each (or the whole stratum if smaller), the rest proportional to the
square root of the stratum size, by largest remainder, never more than a stratum holds."""
@@ -84,7 +97,8 @@ def cohen_kappa(a: pd.Series, b: pd.Series, weight: pd.Series | None = None) ->
po = float(w[a == b].sum() / w.sum())
pa = w.groupby(a).sum() / w.sum()
pb = w.groupby(b).sum() / w.sum()
pe = float(sum(pa.get(c, 0.0) * pb.get(c, 0.0) for c in set(pa.index) | set(pb.index)))
categories = sorted(set(pa.index) | set(pb.index))
pe = float(sum(pa.get(c, 0.0) * pb.get(c, 0.0) for c in categories))
return None if pe >= 1.0 else (po - pe) / (1.0 - pe)

48
volve_dia/m2.py Normal file
View File

@@ -0,0 +1,48 @@
"""Shared paths and provenance helpers for the M2 validation runs."""
from __future__ import annotations
import hashlib
import json
from datetime import datetime, timedelta, timezone
from pathlib import Path
import yaml
from volve_dia import paths
CONFIG = paths.REPO_ROOT / "configs"
VALIDATION = CONFIG / "m2_validation.yaml"
PROTOCOL = CONFIG / "protocol_v1.yaml"
def directory() -> Path:
return paths.outputs_dir() / "audit" / "m2_300"
def spec() -> dict:
return yaml.safe_load(VALIDATION.read_text(encoding="utf-8"))
def repeatability_gap() -> timedelta:
protocol = yaml.safe_load(PROTOCOL.read_text(encoding="utf-8"))
return timedelta(days=protocol["validation"]["llm_raters"]["audit_1"]["second_pass_after_days"])
def digest(path: Path) -> str:
with path.open("rb") as stream:
return hashlib.file_digest(stream, "sha256").hexdigest()
def read_json(path: Path) -> dict:
return json.loads(path.read_text(encoding="utf-8"))
def write_json(path: Path, obj: dict) -> None:
tmp = path.with_suffix(".tmp")
tmp.write_text(json.dumps(obj, indent=2, ensure_ascii=False, allow_nan=False) + "\n", encoding="utf-8")
tmp.replace(path)
def utc_now() -> datetime:
return datetime.now(timezone.utc)