mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
Some checks failed
Wolfram Alpha Verification Check / wolfram-verification (push) Has been cancelled
benchmark.sh: fall back to when ATLAS_OPTIMIZE_TARGET unset score.py: track find_optimal_crossing and SA direct as separate scorecard examples with diagnostic context for reflector gate.sh: add positional-arg fallback for ATLAS_OPTIMIZE_TARGET Build: N/A (config & Python shims only)
73 lines
2.2 KiB
Python
Executable file
73 lines
2.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import argparse, json, os, re, sys
|
|
|
|
METRICS = {
|
|
"find_optimal_crossing": False,
|
|
"SA direct": False,
|
|
}
|
|
|
|
def parse(text):
|
|
results = {}
|
|
for name, higher in METRICS.items():
|
|
pat = re.compile(re.escape(name) + r"\s*[:=]?\s*([+-]?[0-9]*\.?[0-9]+)")
|
|
for m in pat.finditer(text):
|
|
raw = m.group(0).strip()
|
|
val = float(m.group(1))
|
|
line_before = text[max(0, m.start()-80):m.start()].split("\n")[-1].strip()
|
|
results[name] = (val, higher, raw, line_before)
|
|
return results
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--stdout", required=True)
|
|
args = ap.parse_args()
|
|
text = open(args.stdout, encoding="utf-8", errors="replace").read()
|
|
parsed = parse(text)
|
|
|
|
if "find_optimal_crossing" not in parsed:
|
|
sys.stderr.write(f"[score] could not find metric in output.\n")
|
|
sys.exit(3)
|
|
|
|
primary_name = "find_optimal_crossing"
|
|
primary_val, _, primary_raw, ctx = parsed[primary_name]
|
|
direction = "lower is better"
|
|
|
|
examples = [{
|
|
"id": primary_name,
|
|
"score": primary_val,
|
|
"pass": True,
|
|
"feedback": f"{primary_raw} | context: {ctx}" if ctx else primary_raw,
|
|
}]
|
|
|
|
if "SA direct" in parsed:
|
|
sa_val, _, sa_raw, sa_ctx = parsed["SA direct"]
|
|
examples.append({
|
|
"id": "SA direct",
|
|
"score": sa_val,
|
|
"pass": sa_val < 100,
|
|
"feedback": f"{sa_raw} | context: {sa_ctx}" if sa_ctx else sa_raw,
|
|
})
|
|
|
|
diag_lines = []
|
|
for line in text.strip().split("\n"):
|
|
stripped = line.strip()
|
|
if "find_optimal_crossing" in stripped or "SA direct" in stripped:
|
|
diag_lines.append(stripped)
|
|
diagnostic = "; ".join(diag_lines) if diag_lines else primary_raw
|
|
|
|
result = {
|
|
"score": primary_val,
|
|
"examples": examples,
|
|
"feedback": f"find_optimal_crossing={primary_val} ({direction}) | {diagnostic}",
|
|
}
|
|
|
|
out = os.environ.get("ATLAS_OPTIMIZE_RESULT")
|
|
payload = json.dumps(result)
|
|
if out:
|
|
with open(out, "w") as fh:
|
|
fh.write(payload)
|
|
else:
|
|
sys.stdout.write(payload)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|