Albert Gong commited on
Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/0008282/environment/task_meta.json +42 -1
- tasks/0008282/solution/solve.sh +56 -0
- tasks/0008282/tests/check_prediction.py +765 -0
- tasks/0008282/tests/expected.json +62 -0
- tasks/0008282/tests/test.sh +19 -0
- tasks/0304050/environment/task_meta.json +12 -1
- tasks/0304050/solution/solve.sh +20 -0
- tasks/0304050/tests/check_prediction.py +765 -0
- tasks/0304050/tests/expected.json +20 -0
- tasks/0304050/tests/test.sh +19 -0
- tasks/0310432/environment/task_meta.json +22 -1
- tasks/0310432/solution/solve.sh +32 -0
- tasks/0310432/tests/check_prediction.py +765 -0
- tasks/0310432/tests/expected.json +34 -0
- tasks/0310432/tests/test.sh +19 -0
- tasks/0411351/environment/task_meta.json +42 -1
- tasks/0411351/solution/solve.sh +56 -0
- tasks/0411351/tests/check_prediction.py +765 -0
- tasks/0411351/tests/expected.json +62 -0
- tasks/0411351/tests/test.sh +19 -0
- tasks/0601203/tests/expected.json +188 -0
- tasks/0611657/environment/task_meta.json +37 -1
- tasks/0611657/solution/solve.sh +50 -0
- tasks/0611657/tests/check_prediction.py +765 -0
- tasks/0701748/environment/task_meta.json +12 -1
- tasks/0701748/solution/solve.sh +20 -0
- tasks/0701748/tests/check_prediction.py +765 -0
- tasks/0701748/tests/expected.json +20 -0
- tasks/0701748/tests/test.sh +19 -0
- tasks/0709-4228/environment/task_meta.json +57 -1
- tasks/0709-4228/solution/solve.sh +74 -0
- tasks/0709-4228/tests/check_prediction.py +765 -0
- tasks/0709-4228/tests/expected.json +83 -0
- tasks/0709-4228/tests/test.sh +19 -0
- tasks/0909-1289/environment/task_meta.json +152 -1
- tasks/0909-1289/solution/solve.sh +188 -0
- tasks/0909-1289/tests/check_prediction.py +765 -0
- tasks/0909-1289/tests/expected.json +216 -0
- tasks/0909-1289/tests/test.sh +19 -0
- tasks/1303-0244/environment/task_meta.json +92 -1
- tasks/1303-0244/solution/solve.sh +116 -0
- tasks/1303-0244/tests/check_prediction.py +765 -0
- tasks/1303-0244/tests/expected.json +132 -0
- tasks/1303-0244/tests/test.sh +19 -0
- tasks/1310-4332/environment/task_meta.json +232 -1
- tasks/1310-4332/solution/solve.sh +284 -0
- tasks/1310-4332/tests/check_prediction.py +765 -0
- tasks/1310-4332/tests/expected.json +328 -0
- tasks/1310-4332/tests/test.sh +19 -0
- tasks/1405-4815/environment/task_meta.json +42 -1
tasks/0008282/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,46 @@
|
|
| 2 |
"refno": "0008282",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0008282",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "TaS3",
|
| 8 |
+
"property_name": "CDW transition temperature",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "K0.3MoO3",
|
| 13 |
+
"property_name": "CDW transition temperature",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "Ta2Se8I",
|
| 18 |
+
"property_name": "CDW transition temperature",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "TaSe2",
|
| 23 |
+
"property_name": "CDW transition temperature",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "La1.67Sr0.33NiO4",
|
| 28 |
+
"property_name": "CDW transition temperature",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "Half-filled Holstein model",
|
| 33 |
+
"property_name": "CDW transition temperature",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "Infinite-dimensional Holstein model",
|
| 38 |
+
"property_name": "CDW transition temperature",
|
| 39 |
+
"definition": ""
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"material": "half-filled Holstein model",
|
| 43 |
+
"property_name": "CDW transition temperature",
|
| 44 |
+
"definition": ""
|
| 45 |
+
}
|
| 46 |
+
]
|
| 47 |
}
|
tasks/0008282/solution/solve.sh
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "TaS3",
|
| 9 |
+
"property_name": "CDW transition temperature",
|
| 10 |
+
"pred_value": "\u2248 540 K",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "K0.3MoO3",
|
| 15 |
+
"property_name": "CDW transition temperature",
|
| 16 |
+
"pred_value": "\u2248 330 K",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "Ta2Se8I",
|
| 21 |
+
"property_name": "CDW transition temperature",
|
| 22 |
+
"pred_value": "\u2248 1040 K",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "TaSe2",
|
| 27 |
+
"property_name": "CDW transition temperature",
|
| 28 |
+
"pred_value": "\u2248 580 K",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "La1.67Sr0.33NiO4",
|
| 33 |
+
"property_name": "CDW transition temperature",
|
| 34 |
+
"pred_value": "750 K",
|
| 35 |
+
"pred_unit": ""
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"material": "Half-filled Holstein model",
|
| 39 |
+
"property_name": "CDW transition temperature",
|
| 40 |
+
"pred_value": "severely suppressed",
|
| 41 |
+
"pred_unit": ""
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"material": "Infinite-dimensional Holstein model",
|
| 45 |
+
"property_name": "CDW transition temperature",
|
| 46 |
+
"pred_value": "0.25",
|
| 47 |
+
"pred_unit": ""
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"material": "half-filled Holstein model",
|
| 51 |
+
"property_name": "CDW transition temperature",
|
| 52 |
+
"pred_value": "2t exp[-1/(2s+1)\u03bb]",
|
| 53 |
+
"pred_unit": ""
|
| 54 |
+
}
|
| 55 |
+
]
|
| 56 |
+
EOF
|
tasks/0008282/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/0008282/tests/expected.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0008282",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "TaS3",
|
| 7 |
+
"property_name": "CDW transition temperature",
|
| 8 |
+
"property_value": "\u2248 540 K",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "K0.3MoO3",
|
| 14 |
+
"property_name": "CDW transition temperature",
|
| 15 |
+
"property_value": "\u2248 330 K",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "Ta2Se8I",
|
| 21 |
+
"property_name": "CDW transition temperature",
|
| 22 |
+
"property_value": "\u2248 1040 K",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "TaSe2",
|
| 28 |
+
"property_name": "CDW transition temperature",
|
| 29 |
+
"property_value": "\u2248 580 K",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"material": "La1.67Sr0.33NiO4",
|
| 35 |
+
"property_name": "CDW transition temperature",
|
| 36 |
+
"property_value": "750 K",
|
| 37 |
+
"property_unit": "",
|
| 38 |
+
"rubric": "categorical"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"material": "Half-filled Holstein model",
|
| 42 |
+
"property_name": "CDW transition temperature",
|
| 43 |
+
"property_value": "severely suppressed",
|
| 44 |
+
"property_unit": "",
|
| 45 |
+
"rubric": "categorical"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"material": "Infinite-dimensional Holstein model",
|
| 49 |
+
"property_name": "CDW transition temperature",
|
| 50 |
+
"property_value": "0.25",
|
| 51 |
+
"property_unit": "",
|
| 52 |
+
"rubric": "categorical"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"material": "half-filled Holstein model",
|
| 56 |
+
"property_name": "CDW transition temperature",
|
| 57 |
+
"property_value": "2t exp[-1/(2s+1)\u03bb]",
|
| 58 |
+
"property_unit": "",
|
| 59 |
+
"rubric": "categorical"
|
| 60 |
+
}
|
| 61 |
+
]
|
| 62 |
+
}
|
tasks/0008282/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/0304050/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,16 @@
|
|
| 2 |
"refno": "0304050",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0304050",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "Charge Density Wave",
|
| 8 |
+
"property_name": "hysteresis width",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "Charge Density Wave",
|
| 13 |
+
"property_name": "CDW displacement pattern",
|
| 14 |
+
"definition": ""
|
| 15 |
+
}
|
| 16 |
+
]
|
| 17 |
}
|
tasks/0304050/solution/solve.sh
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "Charge Density Wave",
|
| 9 |
+
"property_name": "hysteresis width",
|
| 10 |
+
"pred_value": "2fc",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "Charge Density Wave",
|
| 15 |
+
"property_name": "CDW displacement pattern",
|
| 16 |
+
"pred_value": "parabolic displacement profile",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
}
|
| 19 |
+
]
|
| 20 |
+
EOF
|
tasks/0304050/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/0304050/tests/expected.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0304050",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "Charge Density Wave",
|
| 7 |
+
"property_name": "hysteresis width",
|
| 8 |
+
"property_value": "2fc",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "Charge Density Wave",
|
| 14 |
+
"property_name": "CDW displacement pattern",
|
| 15 |
+
"property_value": "parabolic displacement profile",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
}
|
| 19 |
+
]
|
| 20 |
+
}
|
tasks/0304050/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/0310432/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,26 @@
|
|
| 2 |
"refno": "0310432",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0310432",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "charge density waves",
|
| 8 |
+
"property_name": "resistivity",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "charge density waves",
|
| 13 |
+
"property_name": "conductivity",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "Spin Density Wave system",
|
| 18 |
+
"property_name": "q-vector",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "Charge Density Wave system",
|
| 23 |
+
"property_name": "q-vector",
|
| 24 |
+
"definition": ""
|
| 25 |
+
}
|
| 26 |
+
]
|
| 27 |
}
|
tasks/0310432/solution/solve.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "charge density waves",
|
| 9 |
+
"property_name": "resistivity",
|
| 10 |
+
"pred_value": "vanishes",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "charge density waves",
|
| 15 |
+
"property_name": "conductivity",
|
| 16 |
+
"pred_value": "ideal superconductors",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "Spin Density Wave system",
|
| 21 |
+
"property_name": "q-vector",
|
| 22 |
+
"pred_value": "2kF",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "Charge Density Wave system",
|
| 27 |
+
"property_name": "q-vector",
|
| 28 |
+
"pred_value": "2kF",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
}
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/0310432/tests/expected.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0310432",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "charge density waves",
|
| 7 |
+
"property_name": "resistivity",
|
| 8 |
+
"property_value": "vanishes",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "charge density waves",
|
| 14 |
+
"property_name": "conductivity",
|
| 15 |
+
"property_value": "ideal superconductors",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "Spin Density Wave system",
|
| 21 |
+
"property_name": "q-vector",
|
| 22 |
+
"property_value": "2kF",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "Charge Density Wave system",
|
| 28 |
+
"property_name": "q-vector",
|
| 29 |
+
"property_value": "2kF",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
}
|
| 33 |
+
]
|
| 34 |
+
}
|
tasks/0310432/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/0411351/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,46 @@
|
|
| 2 |
"refno": "0411351",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0411351",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "density wave phase",
|
| 8 |
+
"property_name": "q-vector",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "Theoretical Model",
|
| 13 |
+
"property_name": "q-vector",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "Theoretical Model",
|
| 18 |
+
"property_name": "q-vector components",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "Theoretical Model",
|
| 23 |
+
"property_name": "q-vector components",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "Theoretical Model",
|
| 28 |
+
"property_name": "crystal structure type",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "Theoretical Model",
|
| 33 |
+
"property_name": "q-vector",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "Theoretical Model",
|
| 38 |
+
"property_name": "q-vector components",
|
| 39 |
+
"definition": ""
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"material": "Theoretical Model",
|
| 43 |
+
"property_name": "q-vector components",
|
| 44 |
+
"definition": ""
|
| 45 |
+
}
|
| 46 |
+
]
|
| 47 |
}
|
tasks/0411351/solution/solve.sh
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "density wave phase",
|
| 9 |
+
"property_name": "q-vector",
|
| 10 |
+
"pred_value": "2Q",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "Theoretical Model",
|
| 15 |
+
"property_name": "q-vector",
|
| 16 |
+
"pred_value": "(\u03c0, \u03c0)",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "Theoretical Model",
|
| 21 |
+
"property_name": "q-vector components",
|
| 22 |
+
"pred_value": "(\u03c0, \u03c0)",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "Theoretical Model",
|
| 27 |
+
"property_name": "q-vector components",
|
| 28 |
+
"pred_value": "(\u221a2\u03c0, 0)",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "Theoretical Model",
|
| 33 |
+
"property_name": "crystal structure type",
|
| 34 |
+
"pred_value": "square lattice",
|
| 35 |
+
"pred_unit": ""
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"material": "Theoretical Model",
|
| 39 |
+
"property_name": "q-vector",
|
| 40 |
+
"pred_value": "(\u03c0, \u03c0)",
|
| 41 |
+
"pred_unit": ""
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"material": "Theoretical Model",
|
| 45 |
+
"property_name": "q-vector components",
|
| 46 |
+
"pred_value": "(\u03c0, \u03c0)",
|
| 47 |
+
"pred_unit": ""
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"material": "Theoretical Model",
|
| 51 |
+
"property_name": "q-vector components",
|
| 52 |
+
"pred_value": "(\u221a2\u03c0, 0)",
|
| 53 |
+
"pred_unit": ""
|
| 54 |
+
}
|
| 55 |
+
]
|
| 56 |
+
EOF
|
tasks/0411351/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/0411351/tests/expected.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0411351",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "density wave phase",
|
| 7 |
+
"property_name": "q-vector",
|
| 8 |
+
"property_value": "2Q",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "Theoretical Model",
|
| 14 |
+
"property_name": "q-vector",
|
| 15 |
+
"property_value": "(\u03c0, \u03c0)",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "Theoretical Model",
|
| 21 |
+
"property_name": "q-vector components",
|
| 22 |
+
"property_value": "(\u03c0, \u03c0)",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "Theoretical Model",
|
| 28 |
+
"property_name": "q-vector components",
|
| 29 |
+
"property_value": "(\u221a2\u03c0, 0)",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"material": "Theoretical Model",
|
| 35 |
+
"property_name": "crystal structure type",
|
| 36 |
+
"property_value": "square lattice",
|
| 37 |
+
"property_unit": "",
|
| 38 |
+
"rubric": "categorical"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"material": "Theoretical Model",
|
| 42 |
+
"property_name": "q-vector",
|
| 43 |
+
"property_value": "(\u03c0, \u03c0)",
|
| 44 |
+
"property_unit": "",
|
| 45 |
+
"rubric": "categorical"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"material": "Theoretical Model",
|
| 49 |
+
"property_name": "q-vector components",
|
| 50 |
+
"property_value": "(\u03c0, \u03c0)",
|
| 51 |
+
"property_unit": "",
|
| 52 |
+
"rubric": "categorical"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"material": "Theoretical Model",
|
| 56 |
+
"property_name": "q-vector components",
|
| 57 |
+
"property_value": "(\u221a2\u03c0, 0)",
|
| 58 |
+
"property_unit": "",
|
| 59 |
+
"rubric": "categorical"
|
| 60 |
+
}
|
| 61 |
+
]
|
| 62 |
+
}
|
tasks/0411351/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/0601203/tests/expected.json
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0601203",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "Sr14Cu24O41",
|
| 7 |
+
"property_name": "Raman mode frequency",
|
| 8 |
+
"property_value": "700-1300 cm-1",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "Sr14Cu24O41",
|
| 14 |
+
"property_name": "Raman mode frequency",
|
| 15 |
+
"property_value": "376 cm-1",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "Sr14Cu24O41",
|
| 21 |
+
"property_name": "Raman mode frequency",
|
| 22 |
+
"property_value": "391 cm-1",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "Sr14Cu24O41",
|
| 28 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 29 |
+
"property_value": "200 K",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"material": "Sr14Cu24O41",
|
| 35 |
+
"property_name": "Raman mode frequency",
|
| 36 |
+
"property_value": "269 cm-1",
|
| 37 |
+
"property_unit": "",
|
| 38 |
+
"rubric": "categorical"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"material": "Sr14Cu24O41",
|
| 42 |
+
"property_name": "Raman mode frequency",
|
| 43 |
+
"property_value": "496 cm-1",
|
| 44 |
+
"property_unit": "",
|
| 45 |
+
"rubric": "categorical"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"material": "Sr14Cu24O41",
|
| 49 |
+
"property_name": "Raman mode frequency",
|
| 50 |
+
"property_value": "569 cm-1",
|
| 51 |
+
"property_unit": "",
|
| 52 |
+
"rubric": "categorical"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"material": "Sr14Cu24O41",
|
| 56 |
+
"property_name": "pseudogap",
|
| 57 |
+
"property_value": "400 cm-1",
|
| 58 |
+
"property_unit": "",
|
| 59 |
+
"rubric": "categorical"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "Sr14Cu24O41",
|
| 63 |
+
"property_name": "Raman mode frequency",
|
| 64 |
+
"property_value": "249 cm-1",
|
| 65 |
+
"property_unit": "",
|
| 66 |
+
"rubric": "categorical"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"material": "Sr14Cu24O41",
|
| 70 |
+
"property_name": "Raman mode frequency",
|
| 71 |
+
"property_value": "305 cm-1",
|
| 72 |
+
"property_unit": "",
|
| 73 |
+
"rubric": "categorical"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"material": "Sr14Cu24O41",
|
| 77 |
+
"property_name": "phonon softening amplitude",
|
| 78 |
+
"property_value": "7 cm-1",
|
| 79 |
+
"property_unit": "",
|
| 80 |
+
"rubric": "categorical"
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"material": "Sr14Cu24O41",
|
| 84 |
+
"property_name": "Raman mode frequency",
|
| 85 |
+
"property_value": "294 cm-1",
|
| 86 |
+
"property_unit": "",
|
| 87 |
+
"rubric": "categorical"
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"material": "Sr14Cu24O41",
|
| 91 |
+
"property_name": "Raman mode frequency",
|
| 92 |
+
"property_value": "303 cm-1",
|
| 93 |
+
"property_unit": "",
|
| 94 |
+
"rubric": "categorical"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"material": "Sr2Ca12Cu24O41",
|
| 98 |
+
"property_name": "Raman mode frequency",
|
| 99 |
+
"property_value": "335 cm-1",
|
| 100 |
+
"property_unit": "",
|
| 101 |
+
"rubric": "categorical"
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"material": "Sr14-xCaxCu24O41",
|
| 105 |
+
"property_name": "Raman mode frequency",
|
| 106 |
+
"property_value": "249 cm-1",
|
| 107 |
+
"property_unit": "",
|
| 108 |
+
"rubric": "categorical"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"material": "Sr14-xCaxCu24O41",
|
| 112 |
+
"property_name": "Raman mode frequency",
|
| 113 |
+
"property_value": "237 cm-1",
|
| 114 |
+
"property_unit": "",
|
| 115 |
+
"rubric": "categorical"
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"material": "Sr14-xCaxCu24O41",
|
| 119 |
+
"property_name": "Raman mode frequency",
|
| 120 |
+
"property_value": "253 cm-1",
|
| 121 |
+
"property_unit": "",
|
| 122 |
+
"rubric": "categorical"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"material": "Sr2Ca12Cu24O41",
|
| 126 |
+
"property_name": "pseudogap",
|
| 127 |
+
"property_value": "disappears",
|
| 128 |
+
"property_unit": "",
|
| 129 |
+
"rubric": "categorical"
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"material": "Sr14-xCaxCu24O41",
|
| 133 |
+
"property_name": "Raman mode frequency",
|
| 134 |
+
"property_value": "312 cm-1",
|
| 135 |
+
"property_unit": "",
|
| 136 |
+
"rubric": "categorical"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"material": "Sr14-xCaxCu24O41",
|
| 140 |
+
"property_name": "Raman mode frequency",
|
| 141 |
+
"property_value": "305 cm-1",
|
| 142 |
+
"property_unit": "",
|
| 143 |
+
"rubric": "categorical"
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"material": "Sr14Cu24O41",
|
| 147 |
+
"property_name": "Raman mode frequency",
|
| 148 |
+
"property_value": "305 cm-1",
|
| 149 |
+
"property_unit": "",
|
| 150 |
+
"rubric": "categorical"
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"material": "Sr14Cu24O41",
|
| 154 |
+
"property_name": "Raman mode frequency",
|
| 155 |
+
"property_value": "249 cm-1",
|
| 156 |
+
"property_unit": "",
|
| 157 |
+
"rubric": "categorical"
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"material": "Sr14Cu24O41",
|
| 161 |
+
"property_name": "pseudogap",
|
| 162 |
+
"property_value": "observed",
|
| 163 |
+
"property_unit": "",
|
| 164 |
+
"rubric": "categorical"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"material": "Sr12Ca2Cu24O41",
|
| 168 |
+
"property_name": "pseudogap",
|
| 169 |
+
"property_value": "observed",
|
| 170 |
+
"property_unit": "",
|
| 171 |
+
"rubric": "categorical"
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"material": "Sr9Ca5Cu24O41",
|
| 175 |
+
"property_name": "pseudogap",
|
| 176 |
+
"property_value": "observed",
|
| 177 |
+
"property_unit": "",
|
| 178 |
+
"rubric": "categorical"
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"material": "Sr2Ca12Cu24O41",
|
| 182 |
+
"property_name": "pseudogap",
|
| 183 |
+
"property_value": "disappears",
|
| 184 |
+
"property_unit": "",
|
| 185 |
+
"rubric": "categorical"
|
| 186 |
+
}
|
| 187 |
+
]
|
| 188 |
+
}
|
tasks/0611657/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,41 @@
|
|
| 2 |
"refno": "0611657",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0611657",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "TiSe2",
|
| 8 |
+
"property_name": "CDW transition temperature",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "Cu0.04TiSe2",
|
| 13 |
+
"property_name": "CDW transition temperature",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "CuxTiSe2",
|
| 18 |
+
"property_name": "density of states at Fermi level",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "TiSe2",
|
| 23 |
+
"property_name": "Fermi surface reconstruction features",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "TiSe2",
|
| 28 |
+
"property_name": "crystal structure type",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "TiSe2",
|
| 33 |
+
"property_name": "CDW transition temperature",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "TiSe2",
|
| 38 |
+
"property_name": "CDW transition temperature",
|
| 39 |
+
"definition": ""
|
| 40 |
+
}
|
| 41 |
+
]
|
| 42 |
}
|
tasks/0611657/solution/solve.sh
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "TiSe2",
|
| 9 |
+
"property_name": "CDW transition temperature",
|
| 10 |
+
"pred_value": "~ 220K",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "Cu0.04TiSe2",
|
| 15 |
+
"property_name": "CDW transition temperature",
|
| 16 |
+
"pred_value": "~ 120K",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "CuxTiSe2",
|
| 21 |
+
"property_name": "density of states at Fermi level",
|
| 22 |
+
"pred_value": "raise",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "TiSe2",
|
| 27 |
+
"property_name": "Fermi surface reconstruction features",
|
| 28 |
+
"pred_value": "narrow electron pocket near the L-point",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "TiSe2",
|
| 33 |
+
"property_name": "crystal structure type",
|
| 34 |
+
"pred_value": "trigonal structure",
|
| 35 |
+
"pred_unit": ""
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"material": "TiSe2",
|
| 39 |
+
"property_name": "CDW transition temperature",
|
| 40 |
+
"pred_value": "220K",
|
| 41 |
+
"pred_unit": ""
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"material": "TiSe2",
|
| 45 |
+
"property_name": "CDW transition temperature",
|
| 46 |
+
"pred_value": "220K",
|
| 47 |
+
"pred_unit": ""
|
| 48 |
+
}
|
| 49 |
+
]
|
| 50 |
+
EOF
|
tasks/0611657/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/0701748/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,16 @@
|
|
| 2 |
"refno": "0701748",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0701748",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "NbSe3",
|
| 8 |
+
"property_name": "magnetoresistance",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "NbSe3",
|
| 13 |
+
"property_name": "magnetoresistance",
|
| 14 |
+
"definition": ""
|
| 15 |
+
}
|
| 16 |
+
]
|
| 17 |
}
|
tasks/0701748/solution/solve.sh
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "NbSe3",
|
| 9 |
+
"property_name": "magnetoresistance",
|
| 10 |
+
"pred_value": "Positive",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "NbSe3",
|
| 15 |
+
"property_name": "magnetoresistance",
|
| 16 |
+
"pred_value": "Positive",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
}
|
| 19 |
+
]
|
| 20 |
+
EOF
|
tasks/0701748/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/0701748/tests/expected.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0701748",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "NbSe3",
|
| 7 |
+
"property_name": "magnetoresistance",
|
| 8 |
+
"property_value": "Positive",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "NbSe3",
|
| 14 |
+
"property_name": "magnetoresistance",
|
| 15 |
+
"property_value": "Positive",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
}
|
| 19 |
+
]
|
| 20 |
+
}
|
tasks/0701748/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/0709-4228/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,61 @@
|
|
| 2 |
"refno": "0709.4228",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0709.4228",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "spinless Falicov-Kimball model",
|
| 8 |
+
"property_name": "q-vector",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "spinless Falicov-Kimball model",
|
| 13 |
+
"property_name": "q-vector",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "spinless Falicov-Kimball model",
|
| 18 |
+
"property_name": "electronic band gap",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "spinless Falicov-Kimball model",
|
| 23 |
+
"property_name": "electronic band gap",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "spinless Falicov-Kimball model",
|
| 28 |
+
"property_name": "partial gap size",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "spinless Falicov-Kimball model",
|
| 33 |
+
"property_name": "CDW transition temperature",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "spinless Falicov-Kimball model",
|
| 38 |
+
"property_name": "carrier concentration",
|
| 39 |
+
"definition": ""
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"material": "spinless Falicov-Kimball model",
|
| 43 |
+
"property_name": "electronic band gap",
|
| 44 |
+
"definition": ""
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"material": "spinless Falicov-Kimball model",
|
| 48 |
+
"property_name": "CDW transition temperature",
|
| 49 |
+
"definition": ""
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"material": "Spinless Falicov-Kimball Model",
|
| 53 |
+
"property_name": "CDW displacement pattern",
|
| 54 |
+
"definition": ""
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"material": "Spinless Falicov-Kimball Model",
|
| 58 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 59 |
+
"definition": ""
|
| 60 |
+
}
|
| 61 |
+
]
|
| 62 |
}
|
tasks/0709-4228/solution/solve.sh
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "spinless Falicov-Kimball model",
|
| 9 |
+
"property_name": "q-vector",
|
| 10 |
+
"pred_value": "(\u03c0, \u03c0, ...)",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "spinless Falicov-Kimball model",
|
| 15 |
+
"property_name": "q-vector",
|
| 16 |
+
"pred_value": "(\u03c0, \u03c0, \u03c0, .....)",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "spinless Falicov-Kimball model",
|
| 21 |
+
"property_name": "electronic band gap",
|
| 22 |
+
"pred_value": "U",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "spinless Falicov-Kimball model",
|
| 27 |
+
"property_name": "electronic band gap",
|
| 28 |
+
"pred_value": "0.25",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "spinless Falicov-Kimball model",
|
| 33 |
+
"property_name": "partial gap size",
|
| 34 |
+
"pred_value": "0.05",
|
| 35 |
+
"pred_unit": ""
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"material": "spinless Falicov-Kimball model",
|
| 39 |
+
"property_name": "CDW transition temperature",
|
| 40 |
+
"pred_value": "non-zero",
|
| 41 |
+
"pred_unit": ""
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"material": "spinless Falicov-Kimball model",
|
| 45 |
+
"property_name": "carrier concentration",
|
| 46 |
+
"pred_value": "1/2",
|
| 47 |
+
"pred_unit": ""
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"material": "spinless Falicov-Kimball model",
|
| 51 |
+
"property_name": "electronic band gap",
|
| 52 |
+
"pred_value": "0",
|
| 53 |
+
"pred_unit": ""
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"material": "spinless Falicov-Kimball model",
|
| 57 |
+
"property_name": "CDW transition temperature",
|
| 58 |
+
"pred_value": "0.17 t",
|
| 59 |
+
"pred_unit": ""
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "Spinless Falicov-Kimball Model",
|
| 63 |
+
"property_name": "CDW displacement pattern",
|
| 64 |
+
"pred_value": "placing b and l electrons on alternating nodes",
|
| 65 |
+
"pred_unit": ""
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"material": "Spinless Falicov-Kimball Model",
|
| 69 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 70 |
+
"pred_value": "reduction",
|
| 71 |
+
"pred_unit": ""
|
| 72 |
+
}
|
| 73 |
+
]
|
| 74 |
+
EOF
|
tasks/0709-4228/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/0709-4228/tests/expected.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0709.4228",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "spinless Falicov-Kimball model",
|
| 7 |
+
"property_name": "q-vector",
|
| 8 |
+
"property_value": "(\u03c0, \u03c0, ...)",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "spinless Falicov-Kimball model",
|
| 14 |
+
"property_name": "q-vector",
|
| 15 |
+
"property_value": "(\u03c0, \u03c0, \u03c0, .....)",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "spinless Falicov-Kimball model",
|
| 21 |
+
"property_name": "electronic band gap",
|
| 22 |
+
"property_value": "U",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "spinless Falicov-Kimball model",
|
| 28 |
+
"property_name": "electronic band gap",
|
| 29 |
+
"property_value": "0.25",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"material": "spinless Falicov-Kimball model",
|
| 35 |
+
"property_name": "partial gap size",
|
| 36 |
+
"property_value": "0.05",
|
| 37 |
+
"property_unit": "",
|
| 38 |
+
"rubric": "categorical"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"material": "spinless Falicov-Kimball model",
|
| 42 |
+
"property_name": "CDW transition temperature",
|
| 43 |
+
"property_value": "non-zero",
|
| 44 |
+
"property_unit": "",
|
| 45 |
+
"rubric": "categorical"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"material": "spinless Falicov-Kimball model",
|
| 49 |
+
"property_name": "carrier concentration",
|
| 50 |
+
"property_value": "1/2",
|
| 51 |
+
"property_unit": "",
|
| 52 |
+
"rubric": "categorical"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"material": "spinless Falicov-Kimball model",
|
| 56 |
+
"property_name": "electronic band gap",
|
| 57 |
+
"property_value": "0",
|
| 58 |
+
"property_unit": "",
|
| 59 |
+
"rubric": "categorical"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "spinless Falicov-Kimball model",
|
| 63 |
+
"property_name": "CDW transition temperature",
|
| 64 |
+
"property_value": "0.17 t",
|
| 65 |
+
"property_unit": "",
|
| 66 |
+
"rubric": "categorical"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"material": "Spinless Falicov-Kimball Model",
|
| 70 |
+
"property_name": "CDW displacement pattern",
|
| 71 |
+
"property_value": "placing b and l electrons on alternating nodes",
|
| 72 |
+
"property_unit": "",
|
| 73 |
+
"rubric": "categorical"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"material": "Spinless Falicov-Kimball Model",
|
| 77 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 78 |
+
"property_value": "reduction",
|
| 79 |
+
"property_unit": "",
|
| 80 |
+
"rubric": "categorical"
|
| 81 |
+
}
|
| 82 |
+
]
|
| 83 |
+
}
|
tasks/0709-4228/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/0909-1289/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,156 @@
|
|
| 2 |
"refno": "0909.1289",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "0909.1289",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "DyTe3",
|
| 8 |
+
"property_name": "CDW transition temperature",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "DyTe3",
|
| 13 |
+
"property_name": "CDW transition temperature",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "LaTe3",
|
| 18 |
+
"property_name": "CDW transition temperature",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "DyTe3",
|
| 23 |
+
"property_name": "Raman mode frequency",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "DyTe3",
|
| 28 |
+
"property_name": "Raman mode frequency",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "DyTe3",
|
| 33 |
+
"property_name": "Raman mode frequency",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "DyTe3",
|
| 38 |
+
"property_name": "Raman mode frequency",
|
| 39 |
+
"definition": ""
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"material": "LaTe3",
|
| 43 |
+
"property_name": "Raman mode frequency",
|
| 44 |
+
"definition": ""
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"material": "LaTe3",
|
| 48 |
+
"property_name": "Raman mode frequency",
|
| 49 |
+
"definition": ""
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"material": "DyTe3",
|
| 53 |
+
"property_name": "Raman mode frequency",
|
| 54 |
+
"definition": ""
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"material": "DyTe3",
|
| 58 |
+
"property_name": "Raman mode frequency",
|
| 59 |
+
"definition": ""
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "TbTe3",
|
| 63 |
+
"property_name": "q-vector components",
|
| 64 |
+
"definition": ""
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"material": "TbTe3",
|
| 68 |
+
"property_name": "q-vector components",
|
| 69 |
+
"definition": ""
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"material": "TbTe3",
|
| 73 |
+
"property_name": "q-vector components",
|
| 74 |
+
"definition": ""
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"material": "DyTe3",
|
| 78 |
+
"property_name": "Raman mode frequency",
|
| 79 |
+
"definition": ""
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"material": "DyTe3",
|
| 83 |
+
"property_name": "Raman mode frequency",
|
| 84 |
+
"definition": ""
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"material": "DyTe3",
|
| 88 |
+
"property_name": "Raman mode frequency",
|
| 89 |
+
"definition": ""
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"material": "DyTe3",
|
| 93 |
+
"property_name": "Raman mode frequency",
|
| 94 |
+
"definition": ""
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"material": "DyTe3",
|
| 98 |
+
"property_name": "Raman mode frequency",
|
| 99 |
+
"definition": ""
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"material": "DyTe3",
|
| 103 |
+
"property_name": "phonon softening amplitude",
|
| 104 |
+
"definition": ""
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"material": "LaTe3",
|
| 108 |
+
"property_name": "phonon softening amplitude",
|
| 109 |
+
"definition": ""
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"material": "DyTe3",
|
| 113 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 114 |
+
"definition": ""
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"material": "TmTe3",
|
| 118 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 119 |
+
"definition": ""
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"material": "TmTe3",
|
| 123 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 124 |
+
"definition": ""
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"material": "ErTe3",
|
| 128 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 129 |
+
"definition": ""
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"material": "HoTe3",
|
| 133 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 134 |
+
"definition": ""
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"material": "DyTe3",
|
| 138 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 139 |
+
"definition": ""
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
"material": "LaTe3",
|
| 143 |
+
"property_name": "q-vector",
|
| 144 |
+
"definition": ""
|
| 145 |
+
},
|
| 146 |
+
{
|
| 147 |
+
"material": "LaTe3",
|
| 148 |
+
"property_name": "crystal structure type",
|
| 149 |
+
"definition": ""
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"material": "LaTe3",
|
| 153 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 154 |
+
"definition": ""
|
| 155 |
+
}
|
| 156 |
+
]
|
| 157 |
}
|
tasks/0909-1289/solution/solve.sh
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "DyTe3",
|
| 9 |
+
"property_name": "CDW transition temperature",
|
| 10 |
+
"pred_value": "307 K",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "DyTe3",
|
| 15 |
+
"property_name": "CDW transition temperature",
|
| 16 |
+
"pred_value": "49 K",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "LaTe3",
|
| 21 |
+
"property_name": "CDW transition temperature",
|
| 22 |
+
"pred_value": "~ 260 K",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "DyTe3",
|
| 27 |
+
"property_name": "Raman mode frequency",
|
| 28 |
+
"pred_value": "~ 60 cm-1",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "DyTe3",
|
| 33 |
+
"property_name": "Raman mode frequency",
|
| 34 |
+
"pred_value": "~ 70 cm-1",
|
| 35 |
+
"pred_unit": ""
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"material": "DyTe3",
|
| 39 |
+
"property_name": "Raman mode frequency",
|
| 40 |
+
"pred_value": "113 cm-1",
|
| 41 |
+
"pred_unit": ""
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"material": "DyTe3",
|
| 45 |
+
"property_name": "Raman mode frequency",
|
| 46 |
+
"pred_value": "143 cm-1",
|
| 47 |
+
"pred_unit": ""
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"material": "LaTe3",
|
| 51 |
+
"property_name": "Raman mode frequency",
|
| 52 |
+
"pred_value": "close to 60 cm-1",
|
| 53 |
+
"pred_unit": ""
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"material": "LaTe3",
|
| 57 |
+
"property_name": "Raman mode frequency",
|
| 58 |
+
"pred_value": "around 70 cm-1",
|
| 59 |
+
"pred_unit": ""
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "DyTe3",
|
| 63 |
+
"property_name": "Raman mode frequency",
|
| 64 |
+
"pred_value": "113 cm-1",
|
| 65 |
+
"pred_unit": ""
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"material": "DyTe3",
|
| 69 |
+
"property_name": "Raman mode frequency",
|
| 70 |
+
"pred_value": "143 cm-1",
|
| 71 |
+
"pred_unit": ""
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"material": "TbTe3",
|
| 75 |
+
"property_name": "q-vector components",
|
| 76 |
+
"pred_value": "0.297",
|
| 77 |
+
"pred_unit": ""
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"material": "TbTe3",
|
| 81 |
+
"property_name": "q-vector components",
|
| 82 |
+
"pred_value": "0.292",
|
| 83 |
+
"pred_unit": ""
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"material": "TbTe3",
|
| 87 |
+
"property_name": "q-vector components",
|
| 88 |
+
"pred_value": "almost constant",
|
| 89 |
+
"pred_unit": ""
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"material": "DyTe3",
|
| 93 |
+
"property_name": "Raman mode frequency",
|
| 94 |
+
"pred_value": "23 cm^-1",
|
| 95 |
+
"pred_unit": ""
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"material": "DyTe3",
|
| 99 |
+
"property_name": "Raman mode frequency",
|
| 100 |
+
"pred_value": "below 50 cm^-1",
|
| 101 |
+
"pred_unit": ""
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"material": "DyTe3",
|
| 105 |
+
"property_name": "Raman mode frequency",
|
| 106 |
+
"pred_value": "23 cm^-1",
|
| 107 |
+
"pred_unit": ""
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"material": "DyTe3",
|
| 111 |
+
"property_name": "Raman mode frequency",
|
| 112 |
+
"pred_value": "113 cm^-1",
|
| 113 |
+
"pred_unit": ""
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"material": "DyTe3",
|
| 117 |
+
"property_name": "Raman mode frequency",
|
| 118 |
+
"pred_value": "143 cm^-1",
|
| 119 |
+
"pred_unit": ""
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"material": "DyTe3",
|
| 123 |
+
"property_name": "phonon softening amplitude",
|
| 124 |
+
"pred_value": "5 cm^-1",
|
| 125 |
+
"pred_unit": ""
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"material": "LaTe3",
|
| 129 |
+
"property_name": "phonon softening amplitude",
|
| 130 |
+
"pred_value": "4 cm^-1",
|
| 131 |
+
"pred_unit": ""
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"material": "DyTe3",
|
| 135 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 136 |
+
"pred_value": "50 K",
|
| 137 |
+
"pred_unit": ""
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"material": "TmTe3",
|
| 141 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 142 |
+
"pred_value": "180 K",
|
| 143 |
+
"pred_unit": ""
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"material": "TmTe3",
|
| 147 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 148 |
+
"pred_value": "below ~300 K",
|
| 149 |
+
"pred_unit": ""
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"material": "ErTe3",
|
| 153 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 154 |
+
"pred_value": "below ~300 K",
|
| 155 |
+
"pred_unit": ""
|
| 156 |
+
},
|
| 157 |
+
{
|
| 158 |
+
"material": "HoTe3",
|
| 159 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 160 |
+
"pred_value": "below ~300 K",
|
| 161 |
+
"pred_unit": ""
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
"material": "DyTe3",
|
| 165 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 166 |
+
"pred_value": "below ~300 K",
|
| 167 |
+
"pred_unit": ""
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"material": "LaTe3",
|
| 171 |
+
"property_name": "q-vector",
|
| 172 |
+
"pred_value": "(2/7)c*",
|
| 173 |
+
"pred_unit": ""
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"material": "LaTe3",
|
| 177 |
+
"property_name": "crystal structure type",
|
| 178 |
+
"pred_value": "orthorhombic pseudotetragonal (a = c)",
|
| 179 |
+
"pred_unit": ""
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"material": "LaTe3",
|
| 183 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 184 |
+
"pred_value": "well above room temperature",
|
| 185 |
+
"pred_unit": ""
|
| 186 |
+
}
|
| 187 |
+
]
|
| 188 |
+
EOF
|
tasks/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "0909.1289",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "DyTe3",
|
| 7 |
+
"property_name": "CDW transition temperature",
|
| 8 |
+
"property_value": "307 K",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "DyTe3",
|
| 14 |
+
"property_name": "CDW transition temperature",
|
| 15 |
+
"property_value": "49 K",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "LaTe3",
|
| 21 |
+
"property_name": "CDW transition temperature",
|
| 22 |
+
"property_value": "~ 260 K",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "DyTe3",
|
| 28 |
+
"property_name": "Raman mode frequency",
|
| 29 |
+
"property_value": "~ 60 cm-1",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"material": "DyTe3",
|
| 35 |
+
"property_name": "Raman mode frequency",
|
| 36 |
+
"property_value": "~ 70 cm-1",
|
| 37 |
+
"property_unit": "",
|
| 38 |
+
"rubric": "categorical"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"material": "DyTe3",
|
| 42 |
+
"property_name": "Raman mode frequency",
|
| 43 |
+
"property_value": "113 cm-1",
|
| 44 |
+
"property_unit": "",
|
| 45 |
+
"rubric": "categorical"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"material": "DyTe3",
|
| 49 |
+
"property_name": "Raman mode frequency",
|
| 50 |
+
"property_value": "143 cm-1",
|
| 51 |
+
"property_unit": "",
|
| 52 |
+
"rubric": "categorical"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"material": "LaTe3",
|
| 56 |
+
"property_name": "Raman mode frequency",
|
| 57 |
+
"property_value": "close to 60 cm-1",
|
| 58 |
+
"property_unit": "",
|
| 59 |
+
"rubric": "categorical"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "LaTe3",
|
| 63 |
+
"property_name": "Raman mode frequency",
|
| 64 |
+
"property_value": "around 70 cm-1",
|
| 65 |
+
"property_unit": "",
|
| 66 |
+
"rubric": "categorical"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"material": "DyTe3",
|
| 70 |
+
"property_name": "Raman mode frequency",
|
| 71 |
+
"property_value": "113 cm-1",
|
| 72 |
+
"property_unit": "",
|
| 73 |
+
"rubric": "categorical"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"material": "DyTe3",
|
| 77 |
+
"property_name": "Raman mode frequency",
|
| 78 |
+
"property_value": "143 cm-1",
|
| 79 |
+
"property_unit": "",
|
| 80 |
+
"rubric": "categorical"
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"material": "TbTe3",
|
| 84 |
+
"property_name": "q-vector components",
|
| 85 |
+
"property_value": "0.297",
|
| 86 |
+
"property_unit": "",
|
| 87 |
+
"rubric": "categorical"
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"material": "TbTe3",
|
| 91 |
+
"property_name": "q-vector components",
|
| 92 |
+
"property_value": "0.292",
|
| 93 |
+
"property_unit": "",
|
| 94 |
+
"rubric": "categorical"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"material": "TbTe3",
|
| 98 |
+
"property_name": "q-vector components",
|
| 99 |
+
"property_value": "almost constant",
|
| 100 |
+
"property_unit": "",
|
| 101 |
+
"rubric": "categorical"
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"material": "DyTe3",
|
| 105 |
+
"property_name": "Raman mode frequency",
|
| 106 |
+
"property_value": "23 cm^-1",
|
| 107 |
+
"property_unit": "",
|
| 108 |
+
"rubric": "categorical"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"material": "DyTe3",
|
| 112 |
+
"property_name": "Raman mode frequency",
|
| 113 |
+
"property_value": "below 50 cm^-1",
|
| 114 |
+
"property_unit": "",
|
| 115 |
+
"rubric": "categorical"
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"material": "DyTe3",
|
| 119 |
+
"property_name": "Raman mode frequency",
|
| 120 |
+
"property_value": "23 cm^-1",
|
| 121 |
+
"property_unit": "",
|
| 122 |
+
"rubric": "categorical"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"material": "DyTe3",
|
| 126 |
+
"property_name": "Raman mode frequency",
|
| 127 |
+
"property_value": "113 cm^-1",
|
| 128 |
+
"property_unit": "",
|
| 129 |
+
"rubric": "categorical"
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"material": "DyTe3",
|
| 133 |
+
"property_name": "Raman mode frequency",
|
| 134 |
+
"property_value": "143 cm^-1",
|
| 135 |
+
"property_unit": "",
|
| 136 |
+
"rubric": "categorical"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"material": "DyTe3",
|
| 140 |
+
"property_name": "phonon softening amplitude",
|
| 141 |
+
"property_value": "5 cm^-1",
|
| 142 |
+
"property_unit": "",
|
| 143 |
+
"rubric": "categorical"
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"material": "LaTe3",
|
| 147 |
+
"property_name": "phonon softening amplitude",
|
| 148 |
+
"property_value": "4 cm^-1",
|
| 149 |
+
"property_unit": "",
|
| 150 |
+
"rubric": "categorical"
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"material": "DyTe3",
|
| 154 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 155 |
+
"property_value": "50 K",
|
| 156 |
+
"property_unit": "",
|
| 157 |
+
"rubric": "categorical"
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"material": "TmTe3",
|
| 161 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 162 |
+
"property_value": "180 K",
|
| 163 |
+
"property_unit": "",
|
| 164 |
+
"rubric": "categorical"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"material": "TmTe3",
|
| 168 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 169 |
+
"property_value": "below ~300 K",
|
| 170 |
+
"property_unit": "",
|
| 171 |
+
"rubric": "categorical"
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"material": "ErTe3",
|
| 175 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 176 |
+
"property_value": "below ~300 K",
|
| 177 |
+
"property_unit": "",
|
| 178 |
+
"rubric": "categorical"
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"material": "HoTe3",
|
| 182 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 183 |
+
"property_value": "below ~300 K",
|
| 184 |
+
"property_unit": "",
|
| 185 |
+
"rubric": "categorical"
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"material": "DyTe3",
|
| 189 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 190 |
+
"property_value": "below ~300 K",
|
| 191 |
+
"property_unit": "",
|
| 192 |
+
"rubric": "categorical"
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"material": "LaTe3",
|
| 196 |
+
"property_name": "q-vector",
|
| 197 |
+
"property_value": "(2/7)c*",
|
| 198 |
+
"property_unit": "",
|
| 199 |
+
"rubric": "categorical"
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"material": "LaTe3",
|
| 203 |
+
"property_name": "crystal structure type",
|
| 204 |
+
"property_value": "orthorhombic pseudotetragonal (a = c)",
|
| 205 |
+
"property_unit": "",
|
| 206 |
+
"rubric": "categorical"
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"material": "LaTe3",
|
| 210 |
+
"property_name": "CDW transition temperature (T_CDW)",
|
| 211 |
+
"property_value": "well above room temperature",
|
| 212 |
+
"property_unit": "",
|
| 213 |
+
"rubric": "categorical"
|
| 214 |
+
}
|
| 215 |
+
]
|
| 216 |
+
}
|
tasks/0909-1289/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/1303-0244/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,96 @@
|
|
| 2 |
"refno": "1303.0244",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "1303.0244",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 8 |
+
"property_name": "modulation vector direction",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 13 |
+
"property_name": "modulation period",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 18 |
+
"property_name": "modulation period",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 23 |
+
"property_name": "modulation vector direction",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 28 |
+
"property_name": "modulation vector direction",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 33 |
+
"property_name": "stripe-like CDW",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 38 |
+
"property_name": "modulation period",
|
| 39 |
+
"definition": ""
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 43 |
+
"property_name": "stripe-like CDW",
|
| 44 |
+
"definition": ""
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 48 |
+
"property_name": "stripe-like CDW",
|
| 49 |
+
"definition": ""
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 53 |
+
"property_name": "modulation vector direction",
|
| 54 |
+
"definition": ""
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 58 |
+
"property_name": "modulation period",
|
| 59 |
+
"definition": ""
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 63 |
+
"property_name": "crystal structure type",
|
| 64 |
+
"definition": ""
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 68 |
+
"property_name": "stripe-like CDW",
|
| 69 |
+
"definition": ""
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 73 |
+
"property_name": "modulation period",
|
| 74 |
+
"definition": ""
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"material": "La1.28Sr1.72Mn2O7",
|
| 78 |
+
"property_name": "pseudogap",
|
| 79 |
+
"definition": ""
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"material": "La1.2Sr1.8Mn2O7",
|
| 83 |
+
"property_name": "pseudogap",
|
| 84 |
+
"definition": ""
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"material": "La1.28Sr1.72Mn2O7",
|
| 88 |
+
"property_name": "Fermi surface reconstruction features",
|
| 89 |
+
"definition": ""
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"material": "La1.2Sr1.8Mn2O7",
|
| 93 |
+
"property_name": "Fermi surface reconstruction features",
|
| 94 |
+
"definition": ""
|
| 95 |
+
}
|
| 96 |
+
]
|
| 97 |
}
|
tasks/1303-0244/solution/solve.sh
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 9 |
+
"property_name": "modulation vector direction",
|
| 10 |
+
"pred_value": "along the tetragonal a axis",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 15 |
+
"property_name": "modulation period",
|
| 16 |
+
"pred_value": "about 16 \u00c5",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 21 |
+
"property_name": "modulation period",
|
| 22 |
+
"pred_value": "16 \u00c5",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 27 |
+
"property_name": "modulation vector direction",
|
| 28 |
+
"pred_value": "Mn-O-Mn bonding directions",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 33 |
+
"property_name": "modulation vector direction",
|
| 34 |
+
"pred_value": "along the a or b crystal axes",
|
| 35 |
+
"pred_unit": ""
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 39 |
+
"property_name": "stripe-like CDW",
|
| 40 |
+
"pred_value": "charge stripe",
|
| 41 |
+
"pred_unit": ""
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 45 |
+
"property_name": "modulation period",
|
| 46 |
+
"pred_value": "16-\u00c5",
|
| 47 |
+
"pred_unit": ""
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 51 |
+
"property_name": "stripe-like CDW",
|
| 52 |
+
"pred_value": "stripe-like modulations",
|
| 53 |
+
"pred_unit": ""
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 57 |
+
"property_name": "stripe-like CDW",
|
| 58 |
+
"pred_value": "stripe-like modulations",
|
| 59 |
+
"pred_unit": ""
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 63 |
+
"property_name": "modulation vector direction",
|
| 64 |
+
"pred_value": "along a tetragonal a axis",
|
| 65 |
+
"pred_unit": ""
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 69 |
+
"property_name": "modulation period",
|
| 70 |
+
"pred_value": "about 16 \u00c5",
|
| 71 |
+
"pred_unit": ""
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 75 |
+
"property_name": "crystal structure type",
|
| 76 |
+
"pred_value": "tetragonal Ruddlesden-Popper A3M2O7 structure",
|
| 77 |
+
"pred_unit": ""
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 81 |
+
"property_name": "stripe-like CDW",
|
| 82 |
+
"pred_value": "Stripe-like modulations",
|
| 83 |
+
"pred_unit": ""
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 87 |
+
"property_name": "modulation period",
|
| 88 |
+
"pred_value": "16 \u00c5",
|
| 89 |
+
"pred_unit": ""
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"material": "La1.28Sr1.72Mn2O7",
|
| 93 |
+
"property_name": "pseudogap",
|
| 94 |
+
"pred_value": "at the Fermi energy EF",
|
| 95 |
+
"pred_unit": ""
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"material": "La1.2Sr1.8Mn2O7",
|
| 99 |
+
"property_name": "pseudogap",
|
| 100 |
+
"pred_value": "at the Fermi energy EF",
|
| 101 |
+
"pred_unit": ""
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"material": "La1.28Sr1.72Mn2O7",
|
| 105 |
+
"property_name": "Fermi surface reconstruction features",
|
| 106 |
+
"pred_value": "nesting",
|
| 107 |
+
"pred_unit": ""
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"material": "La1.2Sr1.8Mn2O7",
|
| 111 |
+
"property_name": "Fermi surface reconstruction features",
|
| 112 |
+
"pred_value": "nesting",
|
| 113 |
+
"pred_unit": ""
|
| 114 |
+
}
|
| 115 |
+
]
|
| 116 |
+
EOF
|
tasks/1303-0244/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/1303-0244/tests/expected.json
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "1303.0244",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 7 |
+
"property_name": "modulation vector direction",
|
| 8 |
+
"property_value": "along the tetragonal a axis",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 14 |
+
"property_name": "modulation period",
|
| 15 |
+
"property_value": "about 16 \u00c5",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 21 |
+
"property_name": "modulation period",
|
| 22 |
+
"property_value": "16 \u00c5",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 28 |
+
"property_name": "modulation vector direction",
|
| 29 |
+
"property_value": "Mn-O-Mn bonding directions",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 35 |
+
"property_name": "modulation vector direction",
|
| 36 |
+
"property_value": "along the a or b crystal axes",
|
| 37 |
+
"property_unit": "",
|
| 38 |
+
"rubric": "categorical"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 42 |
+
"property_name": "stripe-like CDW",
|
| 43 |
+
"property_value": "charge stripe",
|
| 44 |
+
"property_unit": "",
|
| 45 |
+
"rubric": "categorical"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 49 |
+
"property_name": "modulation period",
|
| 50 |
+
"property_value": "16-\u00c5",
|
| 51 |
+
"property_unit": "",
|
| 52 |
+
"rubric": "categorical"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 56 |
+
"property_name": "stripe-like CDW",
|
| 57 |
+
"property_value": "stripe-like modulations",
|
| 58 |
+
"property_unit": "",
|
| 59 |
+
"rubric": "categorical"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 63 |
+
"property_name": "stripe-like CDW",
|
| 64 |
+
"property_value": "stripe-like modulations",
|
| 65 |
+
"property_unit": "",
|
| 66 |
+
"rubric": "categorical"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 70 |
+
"property_name": "modulation vector direction",
|
| 71 |
+
"property_value": "along a tetragonal a axis",
|
| 72 |
+
"property_unit": "",
|
| 73 |
+
"rubric": "categorical"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 77 |
+
"property_name": "modulation period",
|
| 78 |
+
"property_value": "about 16 \u00c5",
|
| 79 |
+
"property_unit": "",
|
| 80 |
+
"rubric": "categorical"
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 84 |
+
"property_name": "crystal structure type",
|
| 85 |
+
"property_value": "tetragonal Ruddlesden-Popper A3M2O7 structure",
|
| 86 |
+
"property_unit": "",
|
| 87 |
+
"rubric": "categorical"
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 91 |
+
"property_name": "stripe-like CDW",
|
| 92 |
+
"property_value": "Stripe-like modulations",
|
| 93 |
+
"property_unit": "",
|
| 94 |
+
"rubric": "categorical"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"material": "La1.36Sr1.64Mn2O7",
|
| 98 |
+
"property_name": "modulation period",
|
| 99 |
+
"property_value": "16 \u00c5",
|
| 100 |
+
"property_unit": "",
|
| 101 |
+
"rubric": "categorical"
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"material": "La1.28Sr1.72Mn2O7",
|
| 105 |
+
"property_name": "pseudogap",
|
| 106 |
+
"property_value": "at the Fermi energy EF",
|
| 107 |
+
"property_unit": "",
|
| 108 |
+
"rubric": "categorical"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"material": "La1.2Sr1.8Mn2O7",
|
| 112 |
+
"property_name": "pseudogap",
|
| 113 |
+
"property_value": "at the Fermi energy EF",
|
| 114 |
+
"property_unit": "",
|
| 115 |
+
"rubric": "categorical"
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"material": "La1.28Sr1.72Mn2O7",
|
| 119 |
+
"property_name": "Fermi surface reconstruction features",
|
| 120 |
+
"property_value": "nesting",
|
| 121 |
+
"property_unit": "",
|
| 122 |
+
"rubric": "categorical"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"material": "La1.2Sr1.8Mn2O7",
|
| 126 |
+
"property_name": "Fermi surface reconstruction features",
|
| 127 |
+
"property_value": "nesting",
|
| 128 |
+
"property_unit": "",
|
| 129 |
+
"rubric": "categorical"
|
| 130 |
+
}
|
| 131 |
+
]
|
| 132 |
+
}
|
tasks/1303-0244/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
ex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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "1310.4332",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "spinless Falicov-Kimball model",
|
| 8 |
+
"property_name": "CDW displacement pattern",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "spinless Falicov-Kimball model",
|
| 13 |
+
"property_name": "electronic band gap",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "spinless Falicov-Kimball model",
|
| 18 |
+
"property_name": "electronic band gap",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "spinless Falicov-Kimball model",
|
| 23 |
+
"property_name": "density of states at Fermi level",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "spinless Falicov-Kimball model",
|
| 28 |
+
"property_name": "CDW transition temperature",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "Falicov-Kimball model",
|
| 33 |
+
"property_name": "electronic band gap",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "Falicov-Kimball model",
|
| 38 |
+
"property_name": "checkerboard CDW",
|
| 39 |
+
"definition": ""
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"material": "Falicov-Kimball model",
|
| 43 |
+
"property_name": "electronic band gap",
|
| 44 |
+
"definition": ""
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"material": "Falicov-Kimball model",
|
| 48 |
+
"property_name": "electronic band gap",
|
| 49 |
+
"definition": ""
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"material": "spinless Falicov-Kimball model",
|
| 53 |
+
"property_name": "density of states at Fermi level",
|
| 54 |
+
"definition": ""
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"material": "spinless Falicov-Kimball model",
|
| 58 |
+
"property_name": "density of states at Fermi level",
|
| 59 |
+
"definition": ""
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "spinless Falicov-Kimball model",
|
| 63 |
+
"property_name": "order of CDW transition",
|
| 64 |
+
"definition": ""
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"material": "spinless Falicov-Kimball model",
|
| 68 |
+
"property_name": "density of states at Fermi level",
|
| 69 |
+
"definition": ""
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"material": "spinless Falicov-Kimball model",
|
| 73 |
+
"property_name": "CDW displacement pattern",
|
| 74 |
+
"definition": ""
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"material": "spinless Falicov-Kimball model",
|
| 78 |
+
"property_name": "electronic band gap",
|
| 79 |
+
"definition": ""
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"material": "spinless Falicov-Kimball model",
|
| 83 |
+
"property_name": "density of states at Fermi level",
|
| 84 |
+
"definition": ""
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"material": "spinless Falicov-Kimball model",
|
| 88 |
+
"property_name": "CDW transition temperature",
|
| 89 |
+
"definition": ""
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"material": "spinless Falicov-Kimball model",
|
| 93 |
+
"property_name": "electronic band gap",
|
| 94 |
+
"definition": ""
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"material": "spinless Falicov-Kimball model",
|
| 98 |
+
"property_name": "electronic band gap",
|
| 99 |
+
"definition": ""
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"material": "spinless Falicov-Kimball model",
|
| 103 |
+
"property_name": "CDW transition temperature",
|
| 104 |
+
"definition": ""
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"material": "spinless Falicov-Kimball model",
|
| 108 |
+
"property_name": "electronic band gap",
|
| 109 |
+
"definition": ""
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
"material": "spinless Falicov-Kimball model",
|
| 113 |
+
"property_name": "CDW transition temperature",
|
| 114 |
+
"definition": ""
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"material": "spinless Falicov-Kimball model",
|
| 118 |
+
"property_name": "density of states at Fermi level",
|
| 119 |
+
"definition": ""
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"material": "spinless Falicov-Kimball model",
|
| 123 |
+
"property_name": "density of states at Fermi level",
|
| 124 |
+
"definition": ""
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"material": "Falicov-Kimball model",
|
| 128 |
+
"property_name": "density of states at Fermi level",
|
| 129 |
+
"definition": ""
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"material": "Falicov-Kimball model",
|
| 133 |
+
"property_name": "electronic band gap",
|
| 134 |
+
"definition": ""
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"material": "Falicov-Kimball model",
|
| 138 |
+
"property_name": "electronic band gap",
|
| 139 |
+
"definition": ""
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
"material": "Falicov-Kimball model",
|
| 143 |
+
"property_name": "electronic band gap",
|
| 144 |
+
"definition": ""
|
| 145 |
+
},
|
| 146 |
+
{
|
| 147 |
+
"material": "Falicov-Kimball model",
|
| 148 |
+
"property_name": "electronic band gap",
|
| 149 |
+
"definition": ""
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"material": "Falicov-Kimball model",
|
| 153 |
+
"property_name": "electronic band gap",
|
| 154 |
+
"definition": ""
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"material": "Falicov-Kimball model",
|
| 158 |
+
"property_name": "electronic band gap",
|
| 159 |
+
"definition": ""
|
| 160 |
+
},
|
| 161 |
+
{
|
| 162 |
+
"material": "Falicov-Kimball model",
|
| 163 |
+
"property_name": "electronic band gap",
|
| 164 |
+
"definition": ""
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"material": "Falicov-Kimball model",
|
| 168 |
+
"property_name": "electronic band gap",
|
| 169 |
+
"definition": ""
|
| 170 |
+
},
|
| 171 |
+
{
|
| 172 |
+
"material": "Falicov-Kimball model",
|
| 173 |
+
"property_name": "electronic band gap",
|
| 174 |
+
"definition": ""
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"material": "Falicov-Kimball model",
|
| 178 |
+
"property_name": "electronic band gap",
|
| 179 |
+
"definition": ""
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"material": "Falicov-Kimball model",
|
| 183 |
+
"property_name": "electronic band gap",
|
| 184 |
+
"definition": ""
|
| 185 |
+
},
|
| 186 |
+
{
|
| 187 |
+
"material": "Falicov-Kimball model",
|
| 188 |
+
"property_name": "conductivity",
|
| 189 |
+
"definition": ""
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"material": "Falicov-Kimball model",
|
| 193 |
+
"property_name": "conductivity",
|
| 194 |
+
"definition": ""
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"material": "Falicov-Kimball model",
|
| 198 |
+
"property_name": "density of states at Fermi level",
|
| 199 |
+
"definition": ""
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"material": "Falicov-Kimball model",
|
| 203 |
+
"property_name": "electronic band gap",
|
| 204 |
+
"definition": ""
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"material": "Spinless Falicov-Kimball model",
|
| 208 |
+
"property_name": "electronic band gap",
|
| 209 |
+
"definition": ""
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"material": "spinless Falicov-Kimball model",
|
| 213 |
+
"property_name": "carrier concentration",
|
| 214 |
+
"definition": ""
|
| 215 |
+
},
|
| 216 |
+
{
|
| 217 |
+
"material": "spinless Falicov-Kimball model",
|
| 218 |
+
"property_name": "checkerboard CDW",
|
| 219 |
+
"definition": ""
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"material": "spinless Falicov-Kimball model",
|
| 223 |
+
"property_name": "modulation amplitude",
|
| 224 |
+
"definition": ""
|
| 225 |
+
},
|
| 226 |
+
{
|
| 227 |
+
"material": "spinless Falicov-Kimball model",
|
| 228 |
+
"property_name": "modulation amplitude",
|
| 229 |
+
"definition": ""
|
| 230 |
+
},
|
| 231 |
+
{
|
| 232 |
+
"material": "spinless Falicov-Kimball model",
|
| 233 |
+
"property_name": "atomic sites that modulate",
|
| 234 |
+
"definition": ""
|
| 235 |
+
}
|
| 236 |
+
]
|
| 237 |
}
|
tasks/1310-4332/solution/solve.sh
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
mkdir -p /app/output
|
| 5 |
+
cat > /app/output/predictions.json <<'EOF'
|
| 6 |
+
[
|
| 7 |
+
{
|
| 8 |
+
"material": "spinless Falicov-Kimball model",
|
| 9 |
+
"property_name": "CDW displacement pattern",
|
| 10 |
+
"pred_value": "checkerboard pattern",
|
| 11 |
+
"pred_unit": ""
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"material": "spinless Falicov-Kimball model",
|
| 15 |
+
"property_name": "electronic band gap",
|
| 16 |
+
"pred_value": "proportional to the interaction constant U",
|
| 17 |
+
"pred_unit": ""
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "spinless Falicov-Kimball model",
|
| 21 |
+
"property_name": "electronic band gap",
|
| 22 |
+
"pred_value": "persists for any T (then \u0394 > 0)",
|
| 23 |
+
"pred_unit": ""
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"material": "spinless Falicov-Kimball model",
|
| 27 |
+
"property_name": "density of states at Fermi level",
|
| 28 |
+
"pred_value": "positive",
|
| 29 |
+
"pred_unit": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "spinless Falicov-Kimball model",
|
| 33 |
+
"property_name": "CDW transition temperature",
|
| 34 |
+
"pred_value": "T_O-DO",
|
| 35 |
+
"pred_unit": ""
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"material": "Falicov-Kimball model",
|
| 39 |
+
"property_name": "electronic band gap",
|
| 40 |
+
"pred_value": "gapless",
|
| 41 |
+
"pred_unit": ""
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"material": "Falicov-Kimball model",
|
| 45 |
+
"property_name": "checkerboard CDW",
|
| 46 |
+
"pred_value": "checkerboard-type",
|
| 47 |
+
"pred_unit": ""
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"material": "Falicov-Kimball model",
|
| 51 |
+
"property_name": "electronic band gap",
|
| 52 |
+
"pred_value": "exists",
|
| 53 |
+
"pred_unit": ""
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"material": "Falicov-Kimball model",
|
| 57 |
+
"property_name": "electronic band gap",
|
| 58 |
+
"pred_value": "closing",
|
| 59 |
+
"pred_unit": ""
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "spinless Falicov-Kimball model",
|
| 63 |
+
"property_name": "density of states at Fermi level",
|
| 64 |
+
"pred_value": "begins to rise with temperature, starting from zero and reaching a maximum value at T_O-DO",
|
| 65 |
+
"pred_unit": ""
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"material": "spinless Falicov-Kimball model",
|
| 69 |
+
"property_name": "density of states at Fermi level",
|
| 70 |
+
"pred_value": "increases",
|
| 71 |
+
"pred_unit": ""
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"material": "spinless Falicov-Kimball model",
|
| 75 |
+
"property_name": "order of CDW transition",
|
| 76 |
+
"pred_value": "typical order-disorder phase transition",
|
| 77 |
+
"pred_unit": ""
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"material": "spinless Falicov-Kimball model",
|
| 81 |
+
"property_name": "density of states at Fermi level",
|
| 82 |
+
"pred_value": "1/\u03c0 * Im(sqrt(4d^2 - 4U^2 + U^4) / (2U))",
|
| 83 |
+
"pred_unit": ""
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"material": "spinless Falicov-Kimball model",
|
| 87 |
+
"property_name": "CDW displacement pattern",
|
| 88 |
+
"pred_value": "checkerboard phase",
|
| 89 |
+
"pred_unit": ""
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"material": "spinless Falicov-Kimball model",
|
| 93 |
+
"property_name": "electronic band gap",
|
| 94 |
+
"pred_value": "has a gap at the Fermi level",
|
| 95 |
+
"pred_unit": ""
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"material": "spinless Falicov-Kimball model",
|
| 99 |
+
"property_name": "density of states at Fermi level",
|
| 100 |
+
"pred_value": "positive",
|
| 101 |
+
"pred_unit": ""
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"material": "spinless Falicov-Kimball model",
|
| 105 |
+
"property_name": "CDW transition temperature",
|
| 106 |
+
"pred_value": "T_O-DO",
|
| 107 |
+
"pred_unit": ""
|
| 108 |
+
},
|
| 109 |
+
{
|
| 110 |
+
"material": "spinless Falicov-Kimball model",
|
| 111 |
+
"property_name": "electronic band gap",
|
| 112 |
+
"pred_value": "disappears only at T_O-DO",
|
| 113 |
+
"pred_unit": ""
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"material": "spinless Falicov-Kimball model",
|
| 117 |
+
"property_name": "electronic band gap",
|
| 118 |
+
"pred_value": "exists",
|
| 119 |
+
"pred_unit": ""
|
| 120 |
+
},
|
| 121 |
+
{
|
| 122 |
+
"material": "spinless Falicov-Kimball model",
|
| 123 |
+
"property_name": "CDW transition temperature",
|
| 124 |
+
"pred_value": "T_O-DO",
|
| 125 |
+
"pred_unit": ""
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"material": "spinless Falicov-Kimball model",
|
| 129 |
+
"property_name": "electronic band gap",
|
| 130 |
+
"pred_value": "U",
|
| 131 |
+
"pred_unit": ""
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"material": "spinless Falicov-Kimball model",
|
| 135 |
+
"property_name": "CDW transition temperature",
|
| 136 |
+
"pred_value": "approx 0.0662",
|
| 137 |
+
"pred_unit": ""
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"material": "spinless Falicov-Kimball model",
|
| 141 |
+
"property_name": "density of states at Fermi level",
|
| 142 |
+
"pred_value": "0",
|
| 143 |
+
"pred_unit": ""
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"material": "spinless Falicov-Kimball model",
|
| 147 |
+
"property_name": "density of states at Fermi level",
|
| 148 |
+
"pred_value": "positive",
|
| 149 |
+
"pred_unit": ""
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"material": "Falicov-Kimball model",
|
| 153 |
+
"property_name": "density of states at Fermi level",
|
| 154 |
+
"pred_value": "sqrt(4 - U^2) / (2\u03c0)",
|
| 155 |
+
"pred_unit": ""
|
| 156 |
+
},
|
| 157 |
+
{
|
| 158 |
+
"material": "Falicov-Kimball model",
|
| 159 |
+
"property_name": "electronic band gap",
|
| 160 |
+
"pred_value": "U",
|
| 161 |
+
"pred_unit": ""
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
"material": "Falicov-Kimball model",
|
| 165 |
+
"property_name": "electronic band gap",
|
| 166 |
+
"pred_value": "|(sqrt(1 + 4U^2) - U^2 - 1) / U|",
|
| 167 |
+
"pred_unit": ""
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"material": "Falicov-Kimball model",
|
| 171 |
+
"property_name": "electronic band gap",
|
| 172 |
+
"pred_value": "0",
|
| 173 |
+
"pred_unit": ""
|
| 174 |
+
},
|
| 175 |
+
{
|
| 176 |
+
"material": "Falicov-Kimball model",
|
| 177 |
+
"property_name": "electronic band gap",
|
| 178 |
+
"pred_value": "sqrt(10 + U^2 - 2 * (1 + sqrt((1+2U^2)^3)) / U^2)",
|
| 179 |
+
"pred_unit": ""
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"material": "Falicov-Kimball model",
|
| 183 |
+
"property_name": "electronic band gap",
|
| 184 |
+
"pred_value": "0.33675",
|
| 185 |
+
"pred_unit": ""
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"material": "Falicov-Kimball model",
|
| 189 |
+
"property_name": "electronic band gap",
|
| 190 |
+
"pred_value": "0",
|
| 191 |
+
"pred_unit": ""
|
| 192 |
+
},
|
| 193 |
+
{
|
| 194 |
+
"material": "Falicov-Kimball model",
|
| 195 |
+
"property_name": "electronic band gap",
|
| 196 |
+
"pred_value": "0",
|
| 197 |
+
"pred_unit": ""
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"material": "Falicov-Kimball model",
|
| 201 |
+
"property_name": "electronic band gap",
|
| 202 |
+
"pred_value": "no gap",
|
| 203 |
+
"pred_unit": ""
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"material": "Falicov-Kimball model",
|
| 207 |
+
"property_name": "electronic band gap",
|
| 208 |
+
"pred_value": "finite gap",
|
| 209 |
+
"pred_unit": ""
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"material": "Falicov-Kimball model",
|
| 213 |
+
"property_name": "electronic band gap",
|
| 214 |
+
"pred_value": "persists",
|
| 215 |
+
"pred_unit": ""
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"material": "Falicov-Kimball model",
|
| 219 |
+
"property_name": "electronic band gap",
|
| 220 |
+
"pred_value": "disappears",
|
| 221 |
+
"pred_unit": ""
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"material": "Falicov-Kimball model",
|
| 225 |
+
"property_name": "conductivity",
|
| 226 |
+
"pred_value": "conductor",
|
| 227 |
+
"pred_unit": ""
|
| 228 |
+
},
|
| 229 |
+
{
|
| 230 |
+
"material": "Falicov-Kimball model",
|
| 231 |
+
"property_name": "conductivity",
|
| 232 |
+
"pred_value": "insulator",
|
| 233 |
+
"pred_unit": ""
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"material": "Falicov-Kimball model",
|
| 237 |
+
"property_name": "density of states at Fermi level",
|
| 238 |
+
"pred_value": "finite",
|
| 239 |
+
"pred_unit": ""
|
| 240 |
+
},
|
| 241 |
+
{
|
| 242 |
+
"material": "Falicov-Kimball model",
|
| 243 |
+
"property_name": "electronic band gap",
|
| 244 |
+
"pred_value": "finite",
|
| 245 |
+
"pred_unit": ""
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"material": "Spinless Falicov-Kimball model",
|
| 249 |
+
"property_name": "electronic band gap",
|
| 250 |
+
"pred_value": "U",
|
| 251 |
+
"pred_unit": ""
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"material": "spinless Falicov-Kimball model",
|
| 255 |
+
"property_name": "carrier concentration",
|
| 256 |
+
"pred_value": "1/2",
|
| 257 |
+
"pred_unit": ""
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"material": "spinless Falicov-Kimball model",
|
| 261 |
+
"property_name": "checkerboard CDW",
|
| 262 |
+
"pred_value": "checkerboard-type structure",
|
| 263 |
+
"pred_unit": ""
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"material": "spinless Falicov-Kimball model",
|
| 267 |
+
"property_name": "modulation amplitude",
|
| 268 |
+
"pred_value": "1",
|
| 269 |
+
"pred_unit": ""
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"material": "spinless Falicov-Kimball model",
|
| 273 |
+
"property_name": "modulation amplitude",
|
| 274 |
+
"pred_value": "0",
|
| 275 |
+
"pred_unit": ""
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"material": "spinless Falicov-Kimball model",
|
| 279 |
+
"property_name": "atomic sites that modulate",
|
| 280 |
+
"pred_value": "sublattices + and -",
|
| 281 |
+
"pred_unit": ""
|
| 282 |
+
}
|
| 283 |
+
]
|
| 284 |
+
EOF
|
tasks/1310-4332/tests/check_prediction.py
ADDED
|
@@ -0,0 +1,765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import traceback
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from json import JSONDecoder
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@dataclass(frozen=True)
|
| 15 |
+
class RowKey:
|
| 16 |
+
"""Key used to group ground-truth rows by (material, property_name)."""
|
| 17 |
+
|
| 18 |
+
material: str
|
| 19 |
+
property_name: str
|
| 20 |
+
|
| 21 |
+
@staticmethod
|
| 22 |
+
def from_strings(material: str, property_name: str) -> "RowKey":
|
| 23 |
+
"""Build a normalized key from raw strings."""
|
| 24 |
+
return RowKey(
|
| 25 |
+
str(material or "").strip().lower(),
|
| 26 |
+
str(property_name or "").strip().lower(),
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_SUPERSCRIPT_MAP = str.maketrans(
|
| 31 |
+
{
|
| 32 |
+
"⁰": "0",
|
| 33 |
+
"¹": "1",
|
| 34 |
+
"²": "2",
|
| 35 |
+
"³": "3",
|
| 36 |
+
"⁴": "4",
|
| 37 |
+
"⁵": "5",
|
| 38 |
+
"⁶": "6",
|
| 39 |
+
"⁷": "7",
|
| 40 |
+
"⁸": "8",
|
| 41 |
+
"⁹": "9",
|
| 42 |
+
"⁺": "+",
|
| 43 |
+
"⁻": "-",
|
| 44 |
+
}
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _normalize_ws(text: str) -> str:
|
| 49 |
+
"""Collapse whitespace for more robust string matching."""
|
| 50 |
+
return re.sub(r"\s+", " ", str(text or "")).strip()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _normalize_unicode(text: str) -> str:
|
| 54 |
+
"""Normalize common unicode variants (dashes, superscripts, delta)."""
|
| 55 |
+
s = str(text or "")
|
| 56 |
+
s = (
|
| 57 |
+
s.replace("\u2010", "-")
|
| 58 |
+
.replace("\u2011", "-")
|
| 59 |
+
.replace("\u2012", "-")
|
| 60 |
+
.replace("\u2013", "-")
|
| 61 |
+
.replace("\u2014", "-")
|
| 62 |
+
.replace("\u2212", "-")
|
| 63 |
+
)
|
| 64 |
+
s = s.replace("δ", "d").replace("Δ", "d")
|
| 65 |
+
s = s.translate(_SUPERSCRIPT_MAP)
|
| 66 |
+
return s
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def _normalize_categorical(value: str) -> str:
|
| 70 |
+
"""Normalize a categorical string for comparison."""
|
| 71 |
+
return _normalize_unicode(_normalize_ws(value)).lower()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _load_json(path: Path) -> Any:
|
| 75 |
+
"""Load JSON from disk."""
|
| 76 |
+
with path.open() as f:
|
| 77 |
+
return json.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_numeric_candidates(value: str) -> list[float]:
|
| 81 |
+
"""Extract numeric candidates from a free-form value string (units allowed)."""
|
| 82 |
+
if value is None:
|
| 83 |
+
return []
|
| 84 |
+
|
| 85 |
+
value_str = _normalize_unicode(str(value)).strip()
|
| 86 |
+
if value_str.upper() == "NOT_FOUND" or value_str == "":
|
| 87 |
+
return []
|
| 88 |
+
|
| 89 |
+
value_str = re.sub(r"\(\d+\)", "", value_str)
|
| 90 |
+
|
| 91 |
+
candidates: list[float] = []
|
| 92 |
+
|
| 93 |
+
sci_pattern = re.compile(
|
| 94 |
+
r"(?P<base>[-+]?\d*\.?\d+)\s*(?:x|×)\s*10(?:\s*\^)?\s*(?P<exp>[-+]?\d+)",
|
| 95 |
+
re.IGNORECASE,
|
| 96 |
+
)
|
| 97 |
+
for match in sci_pattern.finditer(value_str):
|
| 98 |
+
try:
|
| 99 |
+
base = float(match.group("base"))
|
| 100 |
+
exp = int(match.group("exp"))
|
| 101 |
+
candidates.append(base * (10**exp))
|
| 102 |
+
except Exception:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
num_pattern = re.compile(r"[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?")
|
| 106 |
+
for match in num_pattern.finditer(value_str):
|
| 107 |
+
try:
|
| 108 |
+
candidates.append(float(match.group(0)))
|
| 109 |
+
except Exception:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
seen: set[str] = set()
|
| 113 |
+
unique: list[float] = []
|
| 114 |
+
for num in candidates:
|
| 115 |
+
key = f"{num:.12g}"
|
| 116 |
+
if key in seen:
|
| 117 |
+
continue
|
| 118 |
+
seen.add(key)
|
| 119 |
+
unique.append(num)
|
| 120 |
+
|
| 121 |
+
return unique
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _si_match(
|
| 125 |
+
pred_num: float, answer_num: float, *, rel_tol: float = 0.001
|
| 126 |
+
) -> tuple[float, float]:
|
| 127 |
+
"""Return (score, rel_error) for a numeric match under relative tolerance."""
|
| 128 |
+
if answer_num == 0:
|
| 129 |
+
return (1.0, 0.0) if pred_num == 0 else (0.0, float("inf"))
|
| 130 |
+
rel_err = abs(pred_num - answer_num) / abs(answer_num)
|
| 131 |
+
return (1.0, rel_err) if rel_err <= rel_tol else (0.0, rel_err)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _strip_purity_annotations(text: str) -> str:
|
| 135 |
+
"""Strip purity suffixes like '(4N)' from element tokens."""
|
| 136 |
+
return re.sub(r"\(\s*\d+\s*N\s*\)", "", text, flags=re.IGNORECASE).strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _parse_simple_formula(formula: str) -> dict[str, float] | None:
|
| 140 |
+
"""Parse a simple chemical formula into element->count (conservative)."""
|
| 141 |
+
cleaned = _normalize_unicode(formula).strip()
|
| 142 |
+
cleaned = _strip_purity_annotations(cleaned)
|
| 143 |
+
cleaned = cleaned.replace(" ", "")
|
| 144 |
+
if not cleaned:
|
| 145 |
+
return None
|
| 146 |
+
if "," in cleaned or "(" in cleaned or ")" in cleaned:
|
| 147 |
+
return None
|
| 148 |
+
|
| 149 |
+
pos = 0
|
| 150 |
+
comp: dict[str, float] = {}
|
| 151 |
+
token = re.compile(r"([A-Z][a-z]?)(\d*\.?\d*)")
|
| 152 |
+
while pos < len(cleaned):
|
| 153 |
+
match = token.match(cleaned, pos)
|
| 154 |
+
if not match:
|
| 155 |
+
return None
|
| 156 |
+
element = match.group(1)
|
| 157 |
+
count_str = match.group(2)
|
| 158 |
+
count = float(count_str) if count_str else 1.0
|
| 159 |
+
comp[element] = comp.get(element, 0.0) + count
|
| 160 |
+
pos = match.end()
|
| 161 |
+
return comp
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def _normalize_formula(formula: str) -> str | None:
|
| 165 |
+
"""Convert a parsed formula into a canonical alphabetical string."""
|
| 166 |
+
comp = _parse_simple_formula(formula)
|
| 167 |
+
if comp is None:
|
| 168 |
+
return None
|
| 169 |
+
parts: list[str] = []
|
| 170 |
+
for element in sorted(comp.keys()):
|
| 171 |
+
count = comp[element]
|
| 172 |
+
if abs(count - 1.0) < 1e-12:
|
| 173 |
+
parts.append(element)
|
| 174 |
+
elif abs(count - round(count)) < 1e-12:
|
| 175 |
+
parts.append(f"{element}{int(round(count))}")
|
| 176 |
+
else:
|
| 177 |
+
parts.append(f"{element}{count:g}")
|
| 178 |
+
return "".join(parts)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def _normalize_formula_set(value: str) -> set[str] | None:
|
| 182 |
+
"""Normalize a single formula or a delimiter-separated list of formulas."""
|
| 183 |
+
raw = _normalize_unicode(_normalize_ws(value))
|
| 184 |
+
raw = _strip_purity_annotations(raw)
|
| 185 |
+
if not raw:
|
| 186 |
+
return None
|
| 187 |
+
|
| 188 |
+
parts = [p.strip() for p in re.split(r"[;,]", raw) if p.strip()]
|
| 189 |
+
if not parts:
|
| 190 |
+
return None
|
| 191 |
+
|
| 192 |
+
normalized: set[str] = set()
|
| 193 |
+
for part in parts:
|
| 194 |
+
norm = _normalize_formula(part)
|
| 195 |
+
if norm is None:
|
| 196 |
+
return None
|
| 197 |
+
normalized.add(norm)
|
| 198 |
+
return normalized
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def score_value(pred_value: str, answer_value: str, rubric: str | None) -> float:
|
| 202 |
+
"""Score one predicted value against one ground-truth value using a rubric."""
|
| 203 |
+
if rubric == "0.1% SI":
|
| 204 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 205 |
+
if not answer_nums:
|
| 206 |
+
return 0.0
|
| 207 |
+
answer_num = answer_nums[0]
|
| 208 |
+
for num in parse_numeric_candidates(pred_value):
|
| 209 |
+
score, _ = _si_match(num, answer_num)
|
| 210 |
+
if score == 1.0:
|
| 211 |
+
return 1.0
|
| 212 |
+
return 0.0
|
| 213 |
+
|
| 214 |
+
if rubric == "pymatgen":
|
| 215 |
+
pred_norm = _normalize_formula_set(pred_value)
|
| 216 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 217 |
+
if pred_norm is not None and ans_norm is not None:
|
| 218 |
+
return 1.0 if pred_norm == ans_norm else 0.0
|
| 219 |
+
return (
|
| 220 |
+
1.0
|
| 221 |
+
if _normalize_categorical(pred_value)
|
| 222 |
+
== _normalize_categorical(answer_value)
|
| 223 |
+
else 0.0
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
return (
|
| 227 |
+
1.0
|
| 228 |
+
if _normalize_categorical(pred_value) == _normalize_categorical(answer_value)
|
| 229 |
+
else 0.0
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def _extract_first_json_array(text: str) -> list[dict[str, Any]] | None:
|
| 234 |
+
"""Extract the first JSON array from mixed text (handles fenced blocks)."""
|
| 235 |
+
|
| 236 |
+
def looks_like_predictions_array(obj: Any) -> bool:
|
| 237 |
+
if not isinstance(obj, list) or not obj:
|
| 238 |
+
return False
|
| 239 |
+
first = obj[0]
|
| 240 |
+
if not isinstance(first, dict):
|
| 241 |
+
return False
|
| 242 |
+
return "property_name" in first and (
|
| 243 |
+
"material" in first or "material_or_system" in first
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
fence_match = re.search(r"```(?:json)?\s*(\[[\s\S]*?\])\s*```", text, re.IGNORECASE)
|
| 247 |
+
if fence_match:
|
| 248 |
+
try:
|
| 249 |
+
obj = json.loads(fence_match.group(1))
|
| 250 |
+
if looks_like_predictions_array(obj):
|
| 251 |
+
return obj
|
| 252 |
+
except Exception:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
decoder = JSONDecoder()
|
| 256 |
+
for match in re.finditer(r"\[", text):
|
| 257 |
+
try:
|
| 258 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 259 |
+
except Exception:
|
| 260 |
+
continue
|
| 261 |
+
if looks_like_predictions_array(obj):
|
| 262 |
+
return obj
|
| 263 |
+
return None
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def _extract_first_json_object(text: str) -> dict[str, Any] | None:
|
| 267 |
+
"""Extract the first JSON object from mixed text (handles fenced blocks)."""
|
| 268 |
+
|
| 269 |
+
def looks_like_properties_object(obj: Any) -> bool:
|
| 270 |
+
if not isinstance(obj, dict):
|
| 271 |
+
return False
|
| 272 |
+
props = obj.get("properties")
|
| 273 |
+
if not isinstance(props, list) or not props:
|
| 274 |
+
return False
|
| 275 |
+
first = props[0]
|
| 276 |
+
if not isinstance(first, dict):
|
| 277 |
+
return False
|
| 278 |
+
return "property_name" in first and (
|
| 279 |
+
"material_or_system" in first or "material" in first
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
fence_match = re.search(r"```(?:json)?\s*(\{[\s\S]*?\})\s*```", text, re.IGNORECASE)
|
| 283 |
+
if fence_match:
|
| 284 |
+
try:
|
| 285 |
+
obj = json.loads(fence_match.group(1))
|
| 286 |
+
if looks_like_properties_object(obj):
|
| 287 |
+
return obj
|
| 288 |
+
except Exception:
|
| 289 |
+
pass
|
| 290 |
+
|
| 291 |
+
decoder = JSONDecoder()
|
| 292 |
+
for match in re.finditer(r"\{", text):
|
| 293 |
+
try:
|
| 294 |
+
obj, _ = decoder.raw_decode(text[match.start() :])
|
| 295 |
+
except Exception:
|
| 296 |
+
continue
|
| 297 |
+
if looks_like_properties_object(obj):
|
| 298 |
+
return obj
|
| 299 |
+
return None
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _extract_text_from_jsonlines_log(text: str) -> str | None:
|
| 303 |
+
"""Decode assistant output embedded in JSONL agent logs (e.g., Claude Code)."""
|
| 304 |
+
decoded_parts: list[str] = []
|
| 305 |
+
any_json = False
|
| 306 |
+
|
| 307 |
+
for raw_line in text.splitlines():
|
| 308 |
+
line = raw_line.strip()
|
| 309 |
+
if not line:
|
| 310 |
+
continue
|
| 311 |
+
if not line.startswith("{"):
|
| 312 |
+
return None
|
| 313 |
+
try:
|
| 314 |
+
obj = json.loads(line)
|
| 315 |
+
except Exception:
|
| 316 |
+
return None
|
| 317 |
+
any_json = True
|
| 318 |
+
|
| 319 |
+
if isinstance(obj, dict):
|
| 320 |
+
message = obj.get("message")
|
| 321 |
+
if isinstance(message, dict):
|
| 322 |
+
content = message.get("content")
|
| 323 |
+
if isinstance(content, list):
|
| 324 |
+
for block in content:
|
| 325 |
+
if isinstance(block, dict) and isinstance(
|
| 326 |
+
block.get("text"), str
|
| 327 |
+
):
|
| 328 |
+
decoded_parts.append(block["text"])
|
| 329 |
+
|
| 330 |
+
result_text = obj.get("result")
|
| 331 |
+
if isinstance(result_text, str):
|
| 332 |
+
decoded_parts.append(result_text)
|
| 333 |
+
|
| 334 |
+
if not any_json:
|
| 335 |
+
return None
|
| 336 |
+
|
| 337 |
+
combined = "\n\n".join(
|
| 338 |
+
part.strip() for part in decoded_parts if part and part.strip()
|
| 339 |
+
)
|
| 340 |
+
return combined or None
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
@dataclass(frozen=True)
|
| 344 |
+
class Prediction:
|
| 345 |
+
"""Normalized view of one predicted property record."""
|
| 346 |
+
|
| 347 |
+
material: str
|
| 348 |
+
property_name: str
|
| 349 |
+
pred_value: str
|
| 350 |
+
pred_unit: str
|
| 351 |
+
raw: dict[str, Any]
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def _coerce_predictions_payload(payload: Any) -> list[dict[str, Any]]:
|
| 355 |
+
"""Coerce multiple supported prediction JSON shapes into a list[dict]."""
|
| 356 |
+
if isinstance(payload, dict) and isinstance(payload.get("properties"), list):
|
| 357 |
+
return [p for p in payload["properties"] if isinstance(p, dict)]
|
| 358 |
+
if isinstance(payload, list):
|
| 359 |
+
return [p for p in payload if isinstance(p, dict)]
|
| 360 |
+
if isinstance(payload, dict):
|
| 361 |
+
values = list(payload.values())
|
| 362 |
+
if values and all(isinstance(v, dict) for v in values):
|
| 363 |
+
return [v for v in values if isinstance(v, dict)]
|
| 364 |
+
raise ValueError("Unrecognized predictions JSON format")
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
def _as_prediction(raw: dict[str, Any]) -> Prediction:
|
| 368 |
+
"""Map a raw property dict to a normalized Prediction."""
|
| 369 |
+
material = raw.get("material")
|
| 370 |
+
if material is None:
|
| 371 |
+
material = (
|
| 372 |
+
raw.get("material_or_system")
|
| 373 |
+
or raw.get("material_system")
|
| 374 |
+
or raw.get("system")
|
| 375 |
+
)
|
| 376 |
+
property_name = raw.get("property_name") or raw.get("name")
|
| 377 |
+
|
| 378 |
+
pred_value = (
|
| 379 |
+
raw.get("pred_value")
|
| 380 |
+
or raw.get("value")
|
| 381 |
+
or raw.get("value_string")
|
| 382 |
+
or raw.get("property_value")
|
| 383 |
+
or ""
|
| 384 |
+
)
|
| 385 |
+
pred_unit = (
|
| 386 |
+
raw.get("pred_unit") or raw.get("unit") or raw.get("property_unit") or ""
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
return Prediction(
|
| 390 |
+
material=str(material or ""),
|
| 391 |
+
property_name=str(property_name or ""),
|
| 392 |
+
pred_value=str(pred_value or ""),
|
| 393 |
+
pred_unit=str(pred_unit or ""),
|
| 394 |
+
raw=raw,
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def load_predictions(predictions_path: Path) -> list[Prediction]:
|
| 399 |
+
"""Load predictions from disk or fall back to parsing agent logs."""
|
| 400 |
+
if predictions_path.exists():
|
| 401 |
+
payload = _load_json(predictions_path)
|
| 402 |
+
return [_as_prediction(p) for p in _coerce_predictions_payload(payload)]
|
| 403 |
+
|
| 404 |
+
agent_logs_dir = Path("/logs/agent")
|
| 405 |
+
if agent_logs_dir.exists():
|
| 406 |
+
for log_path in sorted(agent_logs_dir.glob("*.txt")):
|
| 407 |
+
try:
|
| 408 |
+
content = log_path.read_text()
|
| 409 |
+
except Exception:
|
| 410 |
+
continue
|
| 411 |
+
decoded = _extract_text_from_jsonlines_log(content)
|
| 412 |
+
text = decoded or content
|
| 413 |
+
|
| 414 |
+
extracted_obj = _extract_first_json_object(text)
|
| 415 |
+
if extracted_obj is not None:
|
| 416 |
+
return [
|
| 417 |
+
_as_prediction(p)
|
| 418 |
+
for p in _coerce_predictions_payload(extracted_obj)
|
| 419 |
+
]
|
| 420 |
+
|
| 421 |
+
extracted_arr = _extract_first_json_array(text)
|
| 422 |
+
if extracted_arr is not None:
|
| 423 |
+
return [
|
| 424 |
+
_as_prediction(p)
|
| 425 |
+
for p in _coerce_predictions_payload(extracted_arr)
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
raise FileNotFoundError(
|
| 429 |
+
f"Missing predictions file at {predictions_path} and could not parse JSON from /logs/agent/*.txt"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
_STOPWORDS = {
|
| 434 |
+
"a",
|
| 435 |
+
"an",
|
| 436 |
+
"and",
|
| 437 |
+
"as",
|
| 438 |
+
"at",
|
| 439 |
+
"by",
|
| 440 |
+
"for",
|
| 441 |
+
"from",
|
| 442 |
+
"in",
|
| 443 |
+
"is",
|
| 444 |
+
"of",
|
| 445 |
+
"on",
|
| 446 |
+
"or",
|
| 447 |
+
"sample",
|
| 448 |
+
"the",
|
| 449 |
+
"this",
|
| 450 |
+
"to",
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
def _tokens(text: str) -> set[str]:
|
| 455 |
+
"""Tokenize text for fuzzy property-name matching."""
|
| 456 |
+
return {
|
| 457 |
+
t
|
| 458 |
+
for t in re.findall(r"[a-z0-9]+", _normalize_categorical(text))
|
| 459 |
+
if t not in _STOPWORDS
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
def _is_tc_like_truth(truth_property_name: str, task_name: str | None) -> bool:
|
| 464 |
+
"""Detect whether the ground-truth property is Tc-like (critical temperature)."""
|
| 465 |
+
if task_name and task_name.strip().lower() == "tc":
|
| 466 |
+
return True
|
| 467 |
+
toks = _tokens(truth_property_name)
|
| 468 |
+
return "tc" in toks or "t_c" in toks
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def _property_name_match(
|
| 472 |
+
*, truth_property_name: str, pred_property_name: str, task_name: str | None
|
| 473 |
+
) -> bool:
|
| 474 |
+
"""Return True if a prediction's property_name matches the ground-truth name."""
|
| 475 |
+
truth_norm = _normalize_categorical(truth_property_name)
|
| 476 |
+
pred_norm = _normalize_categorical(pred_property_name)
|
| 477 |
+
if not pred_norm:
|
| 478 |
+
return False
|
| 479 |
+
|
| 480 |
+
if _is_tc_like_truth(truth_property_name, task_name):
|
| 481 |
+
if re.search(r"\btc\b", pred_norm) or re.search(
|
| 482 |
+
r"\bt\s*[_-]?\s*c\b", pred_norm
|
| 483 |
+
):
|
| 484 |
+
return True
|
| 485 |
+
if "critical temperature" in pred_norm:
|
| 486 |
+
return True
|
| 487 |
+
if "transition temperature" in pred_norm:
|
| 488 |
+
return True
|
| 489 |
+
if "superconduct" in pred_norm and "temperature" in pred_norm:
|
| 490 |
+
return True
|
| 491 |
+
return False
|
| 492 |
+
|
| 493 |
+
if truth_norm == pred_norm:
|
| 494 |
+
return True
|
| 495 |
+
if truth_norm and (truth_norm in pred_norm or pred_norm in truth_norm):
|
| 496 |
+
return True
|
| 497 |
+
|
| 498 |
+
truth_toks = _tokens(truth_property_name)
|
| 499 |
+
pred_toks = _tokens(pred_property_name)
|
| 500 |
+
if not truth_toks or not pred_toks:
|
| 501 |
+
return False
|
| 502 |
+
overlap = len(truth_toks & pred_toks) / max(1, len(truth_toks))
|
| 503 |
+
return overlap >= 0.6
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def _normalize_material(material: str) -> str:
|
| 507 |
+
"""Normalize a material/system string for loose matching."""
|
| 508 |
+
s = _normalize_unicode(_normalize_ws(material)).lower()
|
| 509 |
+
s = s.replace(" ", "")
|
| 510 |
+
s = re.sub(r"([a-z\)])1(?=([a-z\(\)\-]|$))", r"\1", s)
|
| 511 |
+
return s
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def _is_generic_material(material: str) -> bool:
|
| 515 |
+
"""Return True for generic/non-identifying material strings."""
|
| 516 |
+
norm = _normalize_material(material)
|
| 517 |
+
return norm in {
|
| 518 |
+
"",
|
| 519 |
+
"material",
|
| 520 |
+
"sample",
|
| 521 |
+
"specimen",
|
| 522 |
+
"film",
|
| 523 |
+
"thinfilm",
|
| 524 |
+
"thinfilms",
|
| 525 |
+
"crystal",
|
| 526 |
+
"singlecrystal",
|
| 527 |
+
"polycrystal",
|
| 528 |
+
"superconductor",
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
def _material_match(*, truth_material: str, pred_material: str) -> bool:
|
| 533 |
+
"""Loose material match (substring match after normalization)."""
|
| 534 |
+
if _is_generic_material(pred_material):
|
| 535 |
+
return False
|
| 536 |
+
truth_norm = _normalize_material(truth_material)
|
| 537 |
+
pred_norm = _normalize_material(pred_material)
|
| 538 |
+
if not truth_norm or not pred_norm:
|
| 539 |
+
return False
|
| 540 |
+
return truth_norm in pred_norm or pred_norm in truth_norm
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
def main() -> None:
|
| 544 |
+
"""Entry point: load expected + predictions, score, write reward/details."""
|
| 545 |
+
parser = argparse.ArgumentParser(
|
| 546 |
+
description="Harbor verifier for property extraction."
|
| 547 |
+
)
|
| 548 |
+
parser.add_argument("--expected", type=str, default="/tests/expected.json")
|
| 549 |
+
parser.add_argument(
|
| 550 |
+
"--predictions", type=str, default="/app/output/predictions.json"
|
| 551 |
+
)
|
| 552 |
+
parser.add_argument("--reward", type=str, default="/logs/verifier/reward.txt")
|
| 553 |
+
parser.add_argument("--details", type=str, default="/logs/verifier/details.json")
|
| 554 |
+
args = parser.parse_args()
|
| 555 |
+
|
| 556 |
+
expected_path = Path(args.expected)
|
| 557 |
+
predictions_path = Path(args.predictions)
|
| 558 |
+
reward_path = Path(args.reward)
|
| 559 |
+
details_path = Path(args.details)
|
| 560 |
+
|
| 561 |
+
try:
|
| 562 |
+
expected = _load_json(expected_path)
|
| 563 |
+
ground_truth = list(expected.get("ground_truth") or [])
|
| 564 |
+
if not isinstance(ground_truth, list):
|
| 565 |
+
raise TypeError("expected.json ground_truth must be a list")
|
| 566 |
+
|
| 567 |
+
task_name = str(expected.get("task") or "").strip().lower() or None
|
| 568 |
+
unique_truth_materials = sorted(
|
| 569 |
+
{str(t.get("material") or "") for t in ground_truth}
|
| 570 |
+
)
|
| 571 |
+
require_material_match = len([m for m in unique_truth_materials if m]) > 1
|
| 572 |
+
|
| 573 |
+
predictions = load_predictions(predictions_path)
|
| 574 |
+
|
| 575 |
+
grouped_truth: dict[RowKey, list[dict[str, Any]]] = {}
|
| 576 |
+
for truth in ground_truth:
|
| 577 |
+
key = RowKey.from_strings(truth.get("material"), truth.get("property_name"))
|
| 578 |
+
grouped_truth.setdefault(key, []).append(truth)
|
| 579 |
+
|
| 580 |
+
results: list[dict[str, Any]] = []
|
| 581 |
+
total = 0
|
| 582 |
+
correct = 0
|
| 583 |
+
|
| 584 |
+
for key, truths in grouped_truth.items():
|
| 585 |
+
truth_material = str(truths[0].get("material") or "")
|
| 586 |
+
truth_prop_name = str(truths[0].get("property_name") or "")
|
| 587 |
+
rubric = truths[0].get("rubric")
|
| 588 |
+
|
| 589 |
+
candidate_preds = [
|
| 590 |
+
pred
|
| 591 |
+
for pred in predictions
|
| 592 |
+
if _property_name_match(
|
| 593 |
+
truth_property_name=truth_prop_name,
|
| 594 |
+
pred_property_name=pred.property_name,
|
| 595 |
+
task_name=task_name,
|
| 596 |
+
)
|
| 597 |
+
and (
|
| 598 |
+
not require_material_match
|
| 599 |
+
or _material_match(
|
| 600 |
+
truth_material=truth_material, pred_material=pred.material
|
| 601 |
+
)
|
| 602 |
+
)
|
| 603 |
+
]
|
| 604 |
+
|
| 605 |
+
pool: list[dict[str, Any]] = []
|
| 606 |
+
if rubric == "0.1% SI":
|
| 607 |
+
for pred in candidate_preds:
|
| 608 |
+
for num in parse_numeric_candidates(pred.pred_value):
|
| 609 |
+
pool.append({"pred": pred, "num": num})
|
| 610 |
+
elif rubric == "pymatgen":
|
| 611 |
+
for pred in candidate_preds:
|
| 612 |
+
pool.append(
|
| 613 |
+
{"pred": pred, "norm": _normalize_formula_set(pred.pred_value)}
|
| 614 |
+
)
|
| 615 |
+
else:
|
| 616 |
+
for pred in candidate_preds:
|
| 617 |
+
pool.append(
|
| 618 |
+
{"pred": pred, "norm": _normalize_categorical(pred.pred_value)}
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
for truth in truths:
|
| 622 |
+
answer_value = str(truth.get("property_value") or "")
|
| 623 |
+
answer_unit = str(truth.get("property_unit") or "")
|
| 624 |
+
rubric_row = truth.get("rubric")
|
| 625 |
+
|
| 626 |
+
chosen_pred: Prediction | None = None
|
| 627 |
+
chosen_value: str = ""
|
| 628 |
+
chosen_score = 0.0
|
| 629 |
+
|
| 630 |
+
best_idx: int | None = None
|
| 631 |
+
best_score = -1.0
|
| 632 |
+
best_tie: float = float("inf")
|
| 633 |
+
|
| 634 |
+
if rubric_row == "0.1% SI":
|
| 635 |
+
answer_nums = parse_numeric_candidates(answer_value)
|
| 636 |
+
answer_num = answer_nums[0] if answer_nums else None
|
| 637 |
+
for idx, item in enumerate(pool):
|
| 638 |
+
pred = item["pred"]
|
| 639 |
+
pred_num = item.get("num")
|
| 640 |
+
if answer_num is None or pred_num is None:
|
| 641 |
+
continue
|
| 642 |
+
score, tie = _si_match(float(pred_num), float(answer_num))
|
| 643 |
+
if score > best_score or (
|
| 644 |
+
score == best_score and tie < best_tie
|
| 645 |
+
):
|
| 646 |
+
best_score = score
|
| 647 |
+
best_tie = tie
|
| 648 |
+
best_idx = idx
|
| 649 |
+
chosen_pred = pred
|
| 650 |
+
chosen_value = str(pred_num)
|
| 651 |
+
chosen_score = float(score)
|
| 652 |
+
if best_score == 1.0 and best_tie == 0.0:
|
| 653 |
+
break
|
| 654 |
+
elif rubric_row == "pymatgen":
|
| 655 |
+
ans_norm = _normalize_formula_set(answer_value)
|
| 656 |
+
for idx, item in enumerate(pool):
|
| 657 |
+
pred = item["pred"]
|
| 658 |
+
pred_norm = item.get("norm")
|
| 659 |
+
score = 0.0
|
| 660 |
+
if pred_norm is not None and ans_norm is not None:
|
| 661 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 662 |
+
else:
|
| 663 |
+
score = (
|
| 664 |
+
1.0
|
| 665 |
+
if _normalize_categorical(pred.pred_value)
|
| 666 |
+
== _normalize_categorical(answer_value)
|
| 667 |
+
else 0.0
|
| 668 |
+
)
|
| 669 |
+
if score > best_score:
|
| 670 |
+
best_score = score
|
| 671 |
+
best_idx = idx
|
| 672 |
+
chosen_pred = pred
|
| 673 |
+
chosen_value = pred.pred_value
|
| 674 |
+
chosen_score = float(score)
|
| 675 |
+
if best_score == 1.0:
|
| 676 |
+
break
|
| 677 |
+
else:
|
| 678 |
+
ans_norm = _normalize_categorical(answer_value)
|
| 679 |
+
for idx, item in enumerate(pool):
|
| 680 |
+
pred = item["pred"]
|
| 681 |
+
pred_norm = item.get("norm")
|
| 682 |
+
score = 1.0 if pred_norm == ans_norm else 0.0
|
| 683 |
+
if score > best_score:
|
| 684 |
+
best_score = score
|
| 685 |
+
best_idx = idx
|
| 686 |
+
chosen_pred = pred
|
| 687 |
+
chosen_value = pred.pred_value
|
| 688 |
+
chosen_score = float(score)
|
| 689 |
+
if best_score == 1.0:
|
| 690 |
+
break
|
| 691 |
+
|
| 692 |
+
if best_idx is not None and chosen_score == 1.0:
|
| 693 |
+
pool.pop(best_idx)
|
| 694 |
+
|
| 695 |
+
results.append(
|
| 696 |
+
{
|
| 697 |
+
"material": truth_material,
|
| 698 |
+
"property_name": truth_prop_name,
|
| 699 |
+
"rubric": rubric_row,
|
| 700 |
+
"answer_value": answer_value,
|
| 701 |
+
"answer_unit": answer_unit,
|
| 702 |
+
"pred_value": chosen_value,
|
| 703 |
+
"pred_unit": chosen_pred.pred_unit if chosen_pred else "",
|
| 704 |
+
"pred_property_name": chosen_pred.property_name
|
| 705 |
+
if chosen_pred
|
| 706 |
+
else "",
|
| 707 |
+
"pred_material": chosen_pred.material if chosen_pred else "",
|
| 708 |
+
"pred_raw": chosen_pred.raw if chosen_pred else None,
|
| 709 |
+
"score": chosen_score,
|
| 710 |
+
}
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
total += 1
|
| 714 |
+
correct += int(chosen_score == 1.0)
|
| 715 |
+
|
| 716 |
+
reward = (correct / total) if total else 0.0
|
| 717 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 718 |
+
reward_path.write_text(str(reward))
|
| 719 |
+
|
| 720 |
+
details_path.write_text(
|
| 721 |
+
json.dumps(
|
| 722 |
+
{
|
| 723 |
+
"reward": reward,
|
| 724 |
+
"correct": correct,
|
| 725 |
+
"total": total,
|
| 726 |
+
"n_predictions": len(predictions),
|
| 727 |
+
"task": expected.get("task"),
|
| 728 |
+
"refno": expected.get("refno"),
|
| 729 |
+
"require_material_match": require_material_match,
|
| 730 |
+
"rows": results,
|
| 731 |
+
},
|
| 732 |
+
indent=2,
|
| 733 |
+
)
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
if reward < 1.0:
|
| 737 |
+
print("Prediction check completed with mismatches.")
|
| 738 |
+
for row in results:
|
| 739 |
+
if row["score"] != 1.0:
|
| 740 |
+
print(
|
| 741 |
+
f"- {row['material']} {row['property_name']}: "
|
| 742 |
+
f"pred='{row['pred_value']}' answer='{row['answer_value']}' rubric='{row['rubric']}'"
|
| 743 |
+
)
|
| 744 |
+
sys.exit(1)
|
| 745 |
+
|
| 746 |
+
print("All predictions correct.")
|
| 747 |
+
except Exception as exc:
|
| 748 |
+
reward_path.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
reward_path.write_text("0.0")
|
| 750 |
+
details_path.write_text(
|
| 751 |
+
json.dumps(
|
| 752 |
+
{
|
| 753 |
+
"reward": 0.0,
|
| 754 |
+
"error": f"{type(exc).__name__}: {exc}",
|
| 755 |
+
"traceback": traceback.format_exc(),
|
| 756 |
+
},
|
| 757 |
+
indent=2,
|
| 758 |
+
)
|
| 759 |
+
)
|
| 760 |
+
print(f"Verifier error: {type(exc).__name__}: {exc}")
|
| 761 |
+
sys.exit(1)
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
if __name__ == "__main__":
|
| 765 |
+
main()
|
tasks/1310-4332/tests/expected.json
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"task": "all",
|
| 3 |
+
"refno": "1310.4332",
|
| 4 |
+
"ground_truth": [
|
| 5 |
+
{
|
| 6 |
+
"material": "spinless Falicov-Kimball model",
|
| 7 |
+
"property_name": "CDW displacement pattern",
|
| 8 |
+
"property_value": "checkerboard pattern",
|
| 9 |
+
"property_unit": "",
|
| 10 |
+
"rubric": "categorical"
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"material": "spinless Falicov-Kimball model",
|
| 14 |
+
"property_name": "electronic band gap",
|
| 15 |
+
"property_value": "proportional to the interaction constant U",
|
| 16 |
+
"property_unit": "",
|
| 17 |
+
"rubric": "categorical"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"material": "spinless Falicov-Kimball model",
|
| 21 |
+
"property_name": "electronic band gap",
|
| 22 |
+
"property_value": "persists for any T (then \u0394 > 0)",
|
| 23 |
+
"property_unit": "",
|
| 24 |
+
"rubric": "categorical"
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "spinless Falicov-Kimball model",
|
| 28 |
+
"property_name": "density of states at Fermi level",
|
| 29 |
+
"property_value": "positive",
|
| 30 |
+
"property_unit": "",
|
| 31 |
+
"rubric": "categorical"
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"material": "spinless Falicov-Kimball model",
|
| 35 |
+
"property_name": "CDW transition temperature",
|
| 36 |
+
"property_value": "T_O-DO",
|
| 37 |
+
"property_unit": "",
|
| 38 |
+
"rubric": "categorical"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"material": "Falicov-Kimball model",
|
| 42 |
+
"property_name": "electronic band gap",
|
| 43 |
+
"property_value": "gapless",
|
| 44 |
+
"property_unit": "",
|
| 45 |
+
"rubric": "categorical"
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"material": "Falicov-Kimball model",
|
| 49 |
+
"property_name": "checkerboard CDW",
|
| 50 |
+
"property_value": "checkerboard-type",
|
| 51 |
+
"property_unit": "",
|
| 52 |
+
"rubric": "categorical"
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"material": "Falicov-Kimball model",
|
| 56 |
+
"property_name": "electronic band gap",
|
| 57 |
+
"property_value": "exists",
|
| 58 |
+
"property_unit": "",
|
| 59 |
+
"rubric": "categorical"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"material": "Falicov-Kimball model",
|
| 63 |
+
"property_name": "electronic band gap",
|
| 64 |
+
"property_value": "closing",
|
| 65 |
+
"property_unit": "",
|
| 66 |
+
"rubric": "categorical"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"material": "spinless Falicov-Kimball model",
|
| 70 |
+
"property_name": "density of states at Fermi level",
|
| 71 |
+
"property_value": "begins to rise with temperature, starting from zero and reaching a maximum value at T_O-DO",
|
| 72 |
+
"property_unit": "",
|
| 73 |
+
"rubric": "categorical"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"material": "spinless Falicov-Kimball model",
|
| 77 |
+
"property_name": "density of states at Fermi level",
|
| 78 |
+
"property_value": "increases",
|
| 79 |
+
"property_unit": "",
|
| 80 |
+
"rubric": "categorical"
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"material": "spinless Falicov-Kimball model",
|
| 84 |
+
"property_name": "order of CDW transition",
|
| 85 |
+
"property_value": "typical order-disorder phase transition",
|
| 86 |
+
"property_unit": "",
|
| 87 |
+
"rubric": "categorical"
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"material": "spinless Falicov-Kimball model",
|
| 91 |
+
"property_name": "density of states at Fermi level",
|
| 92 |
+
"property_value": "1/\u03c0 * Im(sqrt(4d^2 - 4U^2 + U^4) / (2U))",
|
| 93 |
+
"property_unit": "",
|
| 94 |
+
"rubric": "categorical"
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"material": "spinless Falicov-Kimball model",
|
| 98 |
+
"property_name": "CDW displacement pattern",
|
| 99 |
+
"property_value": "checkerboard phase",
|
| 100 |
+
"property_unit": "",
|
| 101 |
+
"rubric": "categorical"
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"material": "spinless Falicov-Kimball model",
|
| 105 |
+
"property_name": "electronic band gap",
|
| 106 |
+
"property_value": "has a gap at the Fermi level",
|
| 107 |
+
"property_unit": "",
|
| 108 |
+
"rubric": "categorical"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"material": "spinless Falicov-Kimball model",
|
| 112 |
+
"property_name": "density of states at Fermi level",
|
| 113 |
+
"property_value": "positive",
|
| 114 |
+
"property_unit": "",
|
| 115 |
+
"rubric": "categorical"
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"material": "spinless Falicov-Kimball model",
|
| 119 |
+
"property_name": "CDW transition temperature",
|
| 120 |
+
"property_value": "T_O-DO",
|
| 121 |
+
"property_unit": "",
|
| 122 |
+
"rubric": "categorical"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"material": "spinless Falicov-Kimball model",
|
| 126 |
+
"property_name": "electronic band gap",
|
| 127 |
+
"property_value": "disappears only at T_O-DO",
|
| 128 |
+
"property_unit": "",
|
| 129 |
+
"rubric": "categorical"
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"material": "spinless Falicov-Kimball model",
|
| 133 |
+
"property_name": "electronic band gap",
|
| 134 |
+
"property_value": "exists",
|
| 135 |
+
"property_unit": "",
|
| 136 |
+
"rubric": "categorical"
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"material": "spinless Falicov-Kimball model",
|
| 140 |
+
"property_name": "CDW transition temperature",
|
| 141 |
+
"property_value": "T_O-DO",
|
| 142 |
+
"property_unit": "",
|
| 143 |
+
"rubric": "categorical"
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"material": "spinless Falicov-Kimball model",
|
| 147 |
+
"property_name": "electronic band gap",
|
| 148 |
+
"property_value": "U",
|
| 149 |
+
"property_unit": "",
|
| 150 |
+
"rubric": "categorical"
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"material": "spinless Falicov-Kimball model",
|
| 154 |
+
"property_name": "CDW transition temperature",
|
| 155 |
+
"property_value": "approx 0.0662",
|
| 156 |
+
"property_unit": "",
|
| 157 |
+
"rubric": "categorical"
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"material": "spinless Falicov-Kimball model",
|
| 161 |
+
"property_name": "density of states at Fermi level",
|
| 162 |
+
"property_value": "0",
|
| 163 |
+
"property_unit": "",
|
| 164 |
+
"rubric": "categorical"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"material": "spinless Falicov-Kimball model",
|
| 168 |
+
"property_name": "density of states at Fermi level",
|
| 169 |
+
"property_value": "positive",
|
| 170 |
+
"property_unit": "",
|
| 171 |
+
"rubric": "categorical"
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"material": "Falicov-Kimball model",
|
| 175 |
+
"property_name": "density of states at Fermi level",
|
| 176 |
+
"property_value": "sqrt(4 - U^2) / (2\u03c0)",
|
| 177 |
+
"property_unit": "",
|
| 178 |
+
"rubric": "categorical"
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"material": "Falicov-Kimball model",
|
| 182 |
+
"property_name": "electronic band gap",
|
| 183 |
+
"property_value": "U",
|
| 184 |
+
"property_unit": "",
|
| 185 |
+
"rubric": "categorical"
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"material": "Falicov-Kimball model",
|
| 189 |
+
"property_name": "electronic band gap",
|
| 190 |
+
"property_value": "|(sqrt(1 + 4U^2) - U^2 - 1) / U|",
|
| 191 |
+
"property_unit": "",
|
| 192 |
+
"rubric": "categorical"
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"material": "Falicov-Kimball model",
|
| 196 |
+
"property_name": "electronic band gap",
|
| 197 |
+
"property_value": "0",
|
| 198 |
+
"property_unit": "",
|
| 199 |
+
"rubric": "categorical"
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"material": "Falicov-Kimball model",
|
| 203 |
+
"property_name": "electronic band gap",
|
| 204 |
+
"property_value": "sqrt(10 + U^2 - 2 * (1 + sqrt((1+2U^2)^3)) / U^2)",
|
| 205 |
+
"property_unit": "",
|
| 206 |
+
"rubric": "categorical"
|
| 207 |
+
},
|
| 208 |
+
{
|
| 209 |
+
"material": "Falicov-Kimball model",
|
| 210 |
+
"property_name": "electronic band gap",
|
| 211 |
+
"property_value": "0.33675",
|
| 212 |
+
"property_unit": "",
|
| 213 |
+
"rubric": "categorical"
|
| 214 |
+
},
|
| 215 |
+
{
|
| 216 |
+
"material": "Falicov-Kimball model",
|
| 217 |
+
"property_name": "electronic band gap",
|
| 218 |
+
"property_value": "0",
|
| 219 |
+
"property_unit": "",
|
| 220 |
+
"rubric": "categorical"
|
| 221 |
+
},
|
| 222 |
+
{
|
| 223 |
+
"material": "Falicov-Kimball model",
|
| 224 |
+
"property_name": "electronic band gap",
|
| 225 |
+
"property_value": "0",
|
| 226 |
+
"property_unit": "",
|
| 227 |
+
"rubric": "categorical"
|
| 228 |
+
},
|
| 229 |
+
{
|
| 230 |
+
"material": "Falicov-Kimball model",
|
| 231 |
+
"property_name": "electronic band gap",
|
| 232 |
+
"property_value": "no gap",
|
| 233 |
+
"property_unit": "",
|
| 234 |
+
"rubric": "categorical"
|
| 235 |
+
},
|
| 236 |
+
{
|
| 237 |
+
"material": "Falicov-Kimball model",
|
| 238 |
+
"property_name": "electronic band gap",
|
| 239 |
+
"property_value": "finite gap",
|
| 240 |
+
"property_unit": "",
|
| 241 |
+
"rubric": "categorical"
|
| 242 |
+
},
|
| 243 |
+
{
|
| 244 |
+
"material": "Falicov-Kimball model",
|
| 245 |
+
"property_name": "electronic band gap",
|
| 246 |
+
"property_value": "persists",
|
| 247 |
+
"property_unit": "",
|
| 248 |
+
"rubric": "categorical"
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"material": "Falicov-Kimball model",
|
| 252 |
+
"property_name": "electronic band gap",
|
| 253 |
+
"property_value": "disappears",
|
| 254 |
+
"property_unit": "",
|
| 255 |
+
"rubric": "categorical"
|
| 256 |
+
},
|
| 257 |
+
{
|
| 258 |
+
"material": "Falicov-Kimball model",
|
| 259 |
+
"property_name": "conductivity",
|
| 260 |
+
"property_value": "conductor",
|
| 261 |
+
"property_unit": "",
|
| 262 |
+
"rubric": "categorical"
|
| 263 |
+
},
|
| 264 |
+
{
|
| 265 |
+
"material": "Falicov-Kimball model",
|
| 266 |
+
"property_name": "conductivity",
|
| 267 |
+
"property_value": "insulator",
|
| 268 |
+
"property_unit": "",
|
| 269 |
+
"rubric": "categorical"
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"material": "Falicov-Kimball model",
|
| 273 |
+
"property_name": "density of states at Fermi level",
|
| 274 |
+
"property_value": "finite",
|
| 275 |
+
"property_unit": "",
|
| 276 |
+
"rubric": "categorical"
|
| 277 |
+
},
|
| 278 |
+
{
|
| 279 |
+
"material": "Falicov-Kimball model",
|
| 280 |
+
"property_name": "electronic band gap",
|
| 281 |
+
"property_value": "finite",
|
| 282 |
+
"property_unit": "",
|
| 283 |
+
"rubric": "categorical"
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"material": "Spinless Falicov-Kimball model",
|
| 287 |
+
"property_name": "electronic band gap",
|
| 288 |
+
"property_value": "U",
|
| 289 |
+
"property_unit": "",
|
| 290 |
+
"rubric": "categorical"
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"material": "spinless Falicov-Kimball model",
|
| 294 |
+
"property_name": "carrier concentration",
|
| 295 |
+
"property_value": "1/2",
|
| 296 |
+
"property_unit": "",
|
| 297 |
+
"rubric": "categorical"
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"material": "spinless Falicov-Kimball model",
|
| 301 |
+
"property_name": "checkerboard CDW",
|
| 302 |
+
"property_value": "checkerboard-type structure",
|
| 303 |
+
"property_unit": "",
|
| 304 |
+
"rubric": "categorical"
|
| 305 |
+
},
|
| 306 |
+
{
|
| 307 |
+
"material": "spinless Falicov-Kimball model",
|
| 308 |
+
"property_name": "modulation amplitude",
|
| 309 |
+
"property_value": "1",
|
| 310 |
+
"property_unit": "",
|
| 311 |
+
"rubric": "categorical"
|
| 312 |
+
},
|
| 313 |
+
{
|
| 314 |
+
"material": "spinless Falicov-Kimball model",
|
| 315 |
+
"property_name": "modulation amplitude",
|
| 316 |
+
"property_value": "0",
|
| 317 |
+
"property_unit": "",
|
| 318 |
+
"rubric": "categorical"
|
| 319 |
+
},
|
| 320 |
+
{
|
| 321 |
+
"material": "spinless Falicov-Kimball model",
|
| 322 |
+
"property_name": "atomic sites that modulate",
|
| 323 |
+
"property_value": "sublattices + and -",
|
| 324 |
+
"property_unit": "",
|
| 325 |
+
"rubric": "categorical"
|
| 326 |
+
}
|
| 327 |
+
]
|
| 328 |
+
}
|
tasks/1310-4332/tests/test.sh
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
set +e
|
| 5 |
+
python /tests/check_prediction.py 2>&1 | tee /logs/verifier/log.txt
|
| 6 |
+
status=${PIPESTATUS[0]}
|
| 7 |
+
set -e
|
| 8 |
+
|
| 9 |
+
# Preserve *all* agent-written outputs even on verifier failure (Harbor deletes containers).
|
| 10 |
+
if [[ -d /app/output ]]; then
|
| 11 |
+
mkdir -p /logs/verifier/app_output
|
| 12 |
+
cp -R /app/output/. /logs/verifier/app_output/ 2>/dev/null || true
|
| 13 |
+
fi
|
| 14 |
+
|
| 15 |
+
if [[ -f /app/task_meta.json ]]; then
|
| 16 |
+
cp /app/task_meta.json /logs/verifier/task_meta.json 2>/dev/null || true
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
exit $status
|
tasks/1405-4815/environment/task_meta.json
CHANGED
|
@@ -2,5 +2,46 @@
|
|
| 2 |
"refno": "1405.4815",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
-
"questions": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
|
|
|
| 2 |
"refno": "1405.4815",
|
| 3 |
"pdf_path": "/app/paper.pdf",
|
| 4 |
"predictions_path": "/app/output/predictions.json",
|
| 5 |
+
"questions": [
|
| 6 |
+
{
|
| 7 |
+
"material": "1D quantum wire with CDW instability",
|
| 8 |
+
"property_name": "electronic band gap",
|
| 9 |
+
"definition": ""
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"material": "Pb",
|
| 13 |
+
"property_name": "CDW transition temperature",
|
| 14 |
+
"definition": ""
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"material": "C20H24Se8PF6",
|
| 18 |
+
"property_name": "spin density wave",
|
| 19 |
+
"definition": ""
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"material": "C16H8AuN2S12",
|
| 23 |
+
"property_name": "spin density wave",
|
| 24 |
+
"definition": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"material": "C22H20AuN2S8Se4",
|
| 28 |
+
"property_name": "spin density wave",
|
| 29 |
+
"definition": ""
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"material": "Au",
|
| 33 |
+
"property_name": "spin density wave",
|
| 34 |
+
"definition": ""
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"material": "In",
|
| 38 |
+
"property_name": "spin density wave",
|
| 39 |
+
"definition": ""
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"material": "Ge",
|
| 43 |
+
"property_name": "spin density wave",
|
| 44 |
+
"definition": ""
|
| 45 |
+
}
|
| 46 |
+
]
|
| 47 |
}
|