Files
Jyotisha/scripts/research/consult_evidence_card_time.py
T
jesse-ux d8d03b5a69
Independent Staging Quality Gate / validate (push) Failing after 6m40s
Independent Staging Quality Gate / publish (push) Skipped
research: consultation evidence-card inventory and draft
Measure the model-visible consultation payload on three public charts, draft per-domain cards, and record the Narayana/pratyantar projection gap as BUG-1054. No runtime behavior change.
2026-09-27 01:27:57 +08:00

89 lines
3.7 KiB
Python

"""Time local consultation layers on the real workflow path. No VedAstro network."""
from __future__ import annotations
import json
import os
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
sys.path[:0] = [str(ROOT), str(ROOT / "scripts"), str(ROOT / "scripts" / "research")]
from consult_evidence_card_lib import QUESTIONS, load_public_charts # noqa: E402
import consult_evidence_card_run as runner # noqa: E402
import jyotish_api_server as api # noqa: E402
def _wrap(bucket: dict[str, float], name: str, fn):
def inner(*args, **kwargs):
started = time.perf_counter()
try:
return fn(*args, **kwargs)
finally:
bucket[name] = round(bucket.get(name, 0.0) + time.perf_counter() - started, 4)
return inner
def main() -> int:
if os.environ.get("PYTHONHASHSEED") != "0":
raise SystemExit("Set PYTHONHASHSEED=0")
runner._block_external_vedastro()
charts = load_public_charts(ROOT)
question = QUESTIONS[0]
results = {}
originals = {
"compute_chart": api.JyotishAPIHandler._compute_chart,
"thematic": api.JyotishAPIHandler._compute_thematic_report,
"rectification": api.JyotishAPIHandler._compute_rectification_gate,
"attach": api._attach_local_consultation_layers,
"varga_spectrum": api._build_consultation_varga_spectrum,
"research_chart": api._custom_research_dn_chart,
"varga_full": api.JyotishAPIHandler._compute_varga_full,
}
for chart in charts:
bucket: dict[str, float] = {}
calls = {"research_chart": 0}
def counting_research(*args, **kwargs):
calls["research_chart"] += 1
return originals["research_chart"](*args, **kwargs)
api.JyotishAPIHandler._compute_chart = _wrap(bucket, "compute_chart", originals["compute_chart"])
api.JyotishAPIHandler._compute_thematic_report = _wrap(bucket, "thematic_report", originals["thematic"])
api.JyotishAPIHandler._compute_rectification_gate = _wrap(bucket, "rectification_gate", originals["rectification"])
api._attach_local_consultation_layers = _wrap(bucket, "attach_local_layers", originals["attach"])
api._build_consultation_varga_spectrum = _wrap(bucket, "varga_spectrum", originals["varga_spectrum"])
api._custom_research_dn_chart = _wrap(bucket, "research_dn_loop", counting_research)
api.JyotishAPIHandler._compute_varga_full = _wrap(bucket, "varga_full", originals["varga_full"])
started = time.perf_counter()
runner._run_workflow(runner._workflow_body(chart, question))
bucket["workflow_wall"] = round(time.perf_counter() - started, 4)
bucket["research_dn_calls"] = calls["research_chart"]
results[chart["id"]] = bucket
print(chart["id"], bucket, flush=True)
for name, fn in originals.items():
if name == "compute_chart":
api.JyotishAPIHandler._compute_chart = fn
elif name == "thematic":
api.JyotishAPIHandler._compute_thematic_report = fn
elif name == "rectification":
api.JyotishAPIHandler._compute_rectification_gate = fn
elif name == "attach":
api._attach_local_consultation_layers = fn
elif name == "varga_spectrum":
api._build_consultation_varga_spectrum = fn
elif name == "research_chart":
api._custom_research_dn_chart = fn
elif name == "varga_full":
api.JyotishAPIHandler._compute_varga_full = fn
out = ROOT / "docs" / "research" / "consult_evidence_card_timings_2026_09_27.json"
out.write_text(json.dumps(results, indent=2), encoding="utf-8")
print(f"wrote {out}")
return 0
if __name__ == "__main__":
raise SystemExit(main())