diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..93b446a58869f2dbef907483f61148a2cd7004ea --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L01,54,40,4 +L02,30,61,2 +L00,65,35,4 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0000/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0000/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-e0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0000/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0000/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-e0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0000/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0000/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-e0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0000/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..f8081d0a37e42072ba8c08ae06f26c782f6f2020 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L00,26,33,1 +L02,49,38,1 +L01,27,24,4 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0012/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0012/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-e0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0012/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0012/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-e0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0012/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-e0012/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-e0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-e0012/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..f7fd70a1b892ce9e9a485aab9e2e01aa6b782060 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L02,39,37,2 +L00,42,63,4 +L01,19,28,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0000/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0000/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-t0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0000/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0000/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-t0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0000/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0000/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-t0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0000/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..8e220f0959b70658cb875c25483581b7a4883e68 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L00,19,70,4 +L01,28,17,4 +L02,36,74,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0012/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0012/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-t0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0012/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0012/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-t0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0012/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0012/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-t0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0012/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..3bc2276fc175840097854100b70b2bd4d105a423 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L02,55,68,2 +L00,61,67,2 +L01,30,23,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0024/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0024/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-t0024/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0024/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0024/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-t0024/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0024/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0024/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-t0024/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0024/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..dd0be1525c8ce0be8368616e205eb5f7aac43ea3 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L01,13,24,3 +L00,29,57,2 +L02,39,55,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0036/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0036/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-t0036/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0036/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0036/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-t0036/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0036/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0036/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-t0036/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0036/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..7cdb0d841d80c2f3c3921a7a9cc67c4b480e66e4 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L00,49,14,2 +L01,14,19,2 +L02,14,21,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0048/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0048/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-t0048/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0048/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0048/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-t0048/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0048/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0048/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-t0048/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0048/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..b481c242a5cffb03df5a2f7979925566e66abf55 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L00,48,12,4 +L01,32,50,2 +L02,26,35,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0060/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0060/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-t0060/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0060/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0060/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-t0060/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0060/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0060/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-t0060/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0060/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..2bf5f14ef1c567eb8178b1f87f312c435120a766 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/workdir/plots.csv @@ -0,0 +1,4 @@ +plot_id,width_m,depth_m,storeys +L00,30,67,2 +L01,21,45,2 +L02,41,14,3 diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0072/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0072/instruction.md b/tasks/zoning-check/zoning-check-capacity-d1-t0072/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0072/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0072/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d1-t0072/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0072/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d1-t0072/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d1-t0072/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d1-t0072/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..afaf506ba376c8218f91fc3b17d0ad62be8c9981 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L01,53,45,1 +L00,55,65,2 +L02,61,33,1 +L03,47,60,4 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0004/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0004/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-e0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0004/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0004/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-e0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0004/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0004/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-e0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0004/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..9f3eb148e1f3cedbf721f67a419e017cb102a977 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L02,17,71,1 +L00,16,50,1 +L03,52,33,4 +L01,27,25,4 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0016/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0016/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-e0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0016/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0016/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-e0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0016/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-e0016/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-e0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-e0016/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..883e09d4e68cccc199d4e0f7fc562e0a0f477439 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L03,13,18,4 +L01,65,48,4 +L02,53,23,2 +L00,42,46,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0004/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0004/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-t0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0004/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0004/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-t0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0004/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0004/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-t0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0004/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..74d51d847d348c2a3968e7a76684f47f96e31fd5 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L03,57,44,1 +L02,30,13,3 +L01,40,13,1 +L00,64,12,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0016/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0016/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-t0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0016/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0016/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-t0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0016/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0016/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-t0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0016/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..1aef43d11d1e519ee5ac11bff825eef62645bdc1 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L00,30,74,4 +L03,49,73,1 +L01,41,19,2 +L02,52,23,4 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0028/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0028/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-t0028/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0028/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0028/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-t0028/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0028/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0028/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-t0028/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0028/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..27fd0a36695fa8d37bd1d2dd3c205f2f52dc7cbf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L00,39,52,2 +L03,40,37,4 +L02,40,29,4 +L01,34,73,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0040/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0040/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-t0040/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0040/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0040/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-t0040/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0040/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0040/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-t0040/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0040/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..38fe33e7bc745bede1729ee524728d12f6b0f233 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L03,20,27,4 +L02,23,57,4 +L01,60,41,1 +L00,37,20,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0052/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0052/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-t0052/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0052/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0052/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-t0052/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0052/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0052/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-t0052/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0052/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..1c769ee4911499c68a6285639f469af952d66b03 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L01,53,15,3 +L00,18,67,4 +L03,17,15,1 +L02,29,20,4 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0064/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0064/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-t0064/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0064/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0064/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-t0064/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0064/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0064/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-t0064/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0064/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..8587ead30cc1e94e6228599d7e1da94a74eab5fd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/workdir/plots.csv @@ -0,0 +1,5 @@ +plot_id,width_m,depth_m,storeys +L00,25,54,2 +L01,41,28,2 +L03,22,50,1 +L02,43,71,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0076/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0076/instruction.md b/tasks/zoning-check/zoning-check-capacity-d2-t0076/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0076/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0076/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d2-t0076/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0076/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d2-t0076/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d2-t0076/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d2-t0076/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..19733982fdda77d751b4f2dd9ce3cd5ecda1be36 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L02,42,68,2 +L03,39,43,4 +L01,53,65,1 +L00,14,12,2 +L04,26,60,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0008/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0008/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-e0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0008/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0008/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-e0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0008/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0008/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-e0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0008/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..1fc2e1a008c04455d530a0dcb352a59ed46e98f5 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L01,31,65,1 +L04,38,44,2 +L02,50,64,1 +L00,61,50,2 +L03,27,34,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0020/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0020/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-e0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0020/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0020/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-e0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0020/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-e0020/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-e0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-e0020/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..a40711db2d3e0d9795aee3ec896e964e90434204 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L02,43,51,4 +L04,38,36,2 +L00,43,32,1 +L01,20,61,1 +L03,44,66,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0008/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0008/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-t0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0008/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0008/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-t0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0008/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0008/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-t0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0008/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..837210344c38a97605bbfb873d625ca279ae19da --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L01,22,62,1 +L00,33,38,2 +L02,33,27,2 +L03,40,32,1 +L04,59,30,2 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0020/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0020/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-t0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0020/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0020/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-t0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0020/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0020/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-t0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0020/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..59c961bd7cb2cf6ef6a0742c028fd34160ef4d95 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L00,29,53,4 +L03,51,48,1 +L04,55,12,1 +L02,60,58,2 +L01,42,38,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0032/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0032/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-t0032/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0032/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0032/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-t0032/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0032/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0032/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-t0032/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0032/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..4a208534934e290b2ae196c870140621c82c61f8 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L03,16,51,2 +L04,53,36,2 +L00,15,15,1 +L01,33,43,1 +L02,20,21,3 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0044/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0044/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-t0044/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0044/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0044/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-t0044/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0044/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0044/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-t0044/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0044/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..6b6c23f0873fa6455bf8e88f2d6b2211e8069382 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L00,20,39,1 +L01,55,59,2 +L03,13,58,4 +L02,43,23,2 +L04,21,65,4 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0056/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0056/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-t0056/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0056/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0056/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-t0056/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0056/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0056/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-t0056/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0056/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..99b5d520e024677b362d9f8407bddce4aab31295 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L01,45,18,1 +L02,47,56,2 +L00,17,28,3 +L04,45,73,4 +L03,23,75,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0068/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0068/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-t0068/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0068/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0068/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-t0068/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0068/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0068/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-t0068/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0068/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/Dockerfile b/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/workdir/plots.csv b/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/workdir/plots.csv new file mode 100644 index 0000000000000000000000000000000000000000..418911bb24d47a3d437a2c4b952b3fc564f84717 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/workdir/plots.csv @@ -0,0 +1,6 @@ +plot_id,width_m,depth_m,storeys +L04,33,64,4 +L02,65,33,4 +L03,60,68,4 +L00,31,41,4 +L01,49,26,1 diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0080/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0080/instruction.md b/tasks/zoning-check/zoning-check-capacity-d3-t0080/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4051b76f36234c5e651dc0b768e4ff5e1dfab56c --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0080/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: capacity + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. Find the largest gross floor area for each rectangular plot with the stated number of storeys. Ignore parking and height in this exercise. Floor area cannot exceed any of: site area times max_far; site area times max_coverage times storeys; or max(0,width-2*setback) times max(0,depth-2*setback) times storeys. The smallest is binding; no ties occur. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id. Each value has `max_floor_m2`, `binding` (`far`, `coverage` or `setbacks`), and the three limits `far_limit_m2`, `coverage_limit_m2`, `setbacks_limit_m2`, all areas in square metres. diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0080/solution/oracle.py b/tasks/zoning-check/zoning-check-capacity-d3-t0080/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0080/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-capacity-d3-t0080/tests/verify.py b/tasks/zoning-check/zoning-check-capacity-d3-t0080/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-capacity-d3-t0080/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..153a2ba6710c37392259b0f63e2eec6cda6a14a5 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,53,64,3392,848.0,21,5,8,9,3,Studio Ash +P00,53,44,1865.6,1399.2,12,2,6,5,7,Studio Ash +P02,54,53,4006.8,858.6,18,7,6,5,6,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0001/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0001/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-e0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0001/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0001/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-e0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0001/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0001/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-e0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0001/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..49ed6aa31b49b46242e140f1420a0e2f1c80a2f1 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P00,40,53,2120,530.0,12,2,8,2,3,Studio Ash +P01,31,64,1984,496.0,9,5,8,9,6,Studio Ash +P02,22,48,1056,316.8,9,2,3,2,7,Studio Oak diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0013/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0013/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-e0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0013/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0013/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-e0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0013/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-e0013/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-e0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-e0013/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..60687e588e29206e70af22e3cf25f5055630f0c6 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P02,20,52,1456.0,624.0,9,7,6,9,7,Studio Elm +P00,35,49,1372.0,514.5,18,7,6,9,6,Studio Elm +P01,21,70,2352.0,441.0,18,5,3,5,6,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0001/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0001/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-t0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0001/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0001/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-t0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0001/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0001/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-t0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0001/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..8a16ef24461536dab0acf30e8e818ea7ede0db03 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P02,57,61,2781.6,1738.5,21,5,3,9,6,Studio Oak +P00,49,26,1274,318.5,9,5,8,2,7,Studio Ash +P01,28,49,1097.6,343.0,12,2,3,2,7,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0013/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0013/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-t0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0013/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0013/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-t0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0013/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0013/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-t0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0013/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..cc47f609ffbc2e9ce20df7d8f6d90c321bc64f1e --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P02,48,42,1612.8,1008.0,12,7,6,5,3,Studio Elm +P00,57,52,2964,1482.0,18,7,8,5,6,Studio Oak +P01,45,60,2700,675.0,12,5,6,2,7,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0025/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0025/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-t0025/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0025/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0025/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-t0025/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0025/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0025/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-t0025/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0025/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..0ea8c6ea395a3e32430b6fddc76d443154d5c772 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,53,37,1568.8,490.25,12,5,8,2,6,Studio Elm +P02,60,34,1632.0,612.0,12,2,8,9,6,Studio Oak +P00,53,33,1399.2,524.7,9,5,6,2,3,Studio Oak diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0037/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0037/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-t0037/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0037/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0037/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-t0037/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0037/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0037/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-t0037/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0037/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..6ee48d1f51c7b6c120628fc6eee0cbf8f1d7789a --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,54,67,5788.8,1809.0,12,7,8,2,3,Studio Oak +P00,28,52,1164.8,873.6,12,7,6,9,6,Studio Ash +P02,47,56,4211.2,789.6,21,2,3,2,6,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0049/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0049/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-t0049/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0049/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0049/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-t0049/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0049/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0049/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-t0049/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0049/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..cc1ebc64b2145b68d838270fedab676c67163500 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,32,67,3430.4,643.2,21,5,8,9,3,Studio Ash +P02,26,37,1539.2,481.0,9,5,3,5,6,Studio Ash +P00,25,44,1540.0,330.0,12,7,3,5,6,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0061/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0061/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-t0061/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0061/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0061/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-t0061/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0061/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0061/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-t0061/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0061/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..0f69eb504bc42cf7d837cbacba89ad14b8aa0b58 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/workdir/proposals.csv @@ -0,0 +1,4 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P00,35,68,2380,714.0,21,2,3,2,6,Studio Oak +P02,42,45,1890,472.5,9,2,6,5,7,Studio Elm +P01,31,62,1537.6,576.6,21,2,6,2,7,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0073/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0073/instruction.md b/tasks/zoning-check/zoning-check-compliance-d1-t0073/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0073/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0073/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d1-t0073/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0073/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d1-t0073/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d1-t0073/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d1-t0073/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..1c56a09680c0ed67d96e356b3301e2b7e564e857 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,31,69,3422.4,534.75,21,5,6,9,3,Studio Elm +P02,43,27,928.8,348.3,9,5,8,5,7,Studio Oak +P01,46,26,1674.4,598.0,21,5,3,5,6,Studio Oak +P00,30,46,1380,345.0,12,7,3,9,3,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0005/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0005/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-e0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0005/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0005/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-e0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0005/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0005/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-e0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0005/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..3f2e605bbd8c33e1957a04c3fa3630f2b6777f1e --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P00,55,59,5192.0,1947.0,21,5,6,9,3,Studio Elm +P03,35,53,2968.0,556.5,9,5,3,5,3,Studio Oak +P01,44,69,2428.8,1821.6,18,5,6,9,7,Studio Ash +P02,37,54,2797.2,1198.8,12,5,8,5,7,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0017/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0017/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-e0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0017/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0017/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-e0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0017/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-e0017/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-e0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-e0017/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..6c24f9bce62a033fb72fa3745e6c31ebfa83914e --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,43,51,3070.2,1315.8,18,5,3,2,6,Studio Elm +P02,24,29,556.8,417.6,18,2,3,9,6,Studio Oak +P01,53,61,4526.2,969.9,9,5,6,2,3,Studio Oak +P00,58,70,3248.0,1218.0,21,7,8,9,3,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0005/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0005/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-t0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0005/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0005/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-t0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0005/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0005/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-t0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0005/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..0a11aa21e42f46e2350e81f91e48616b36989612 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,49,57,2234.4,1675.8,9,5,6,9,6,Studio Oak +P00,31,35,1736.0,542.5,18,7,3,2,3,Studio Elm +P03,43,53,2279,683.7,9,5,3,9,7,Studio Elm +P02,59,39,2301,575.25,21,7,8,9,7,Studio Oak diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0017/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0017/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-t0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0017/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0017/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-t0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0017/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0017/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-t0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0017/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..bb25dce31cb6d1446e074cc01309c17aa40360e6 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,51,31,1264.8,790.5,12,7,3,9,6,Studio Ash +P01,45,60,2700,1620.0,9,5,6,2,3,Studio Elm +P02,55,68,2992.0,1870.0,9,2,3,5,6,Studio Ash +P00,55,52,4004.0,715.0,9,7,6,2,7,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0029/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0029/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-t0029/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0029/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0029/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-t0029/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0029/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0029/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-t0029/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0029/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..469dfdae34e177e78df3c67cf7befd5dd04a1966 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,36,25,1260.0,540.0,9,5,8,5,7,Studio Ash +P01,22,65,2002.0,858.0,18,7,3,9,6,Studio Elm +P02,23,27,993.6,155.25,21,7,3,2,7,Studio Oak +P00,39,65,4056.0,760.5,9,2,8,9,3,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0041/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0041/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-t0041/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0041/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0041/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-t0041/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0041/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0041/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-t0041/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0041/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..a8d8f6a74dbb1fa815a13dfe74c8361752bbf347 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,38,44,1337.6,836.0,21,2,3,5,6,Studio Oak +P00,53,41,3042.2,1086.5,9,7,3,2,3,Studio Ash +P03,28,29,1136.8,243.6,18,5,8,2,7,Studio Ash +P02,22,59,1038.4,389.4,18,2,8,2,6,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0053/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0053/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-t0053/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0053/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0053/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-t0053/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0053/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0053/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-t0053/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0053/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..b0a71ebabf474d04eff42fd20769420c11204474 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,35,49,1715,514.5,18,7,6,9,6,Studio Ash +P03,40,37,1480,444.0,12,2,6,9,7,Studio Oak +P02,44,32,2252.8,704.0,12,7,3,9,7,Studio Ash +P00,22,34,1196.8,187.0,9,5,6,9,7,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0065/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0065/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-t0065/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0065/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0065/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-t0065/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0065/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0065/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-t0065/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0065/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..3ecada19eac2c39dc49c3957518350c1e36c8470 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/workdir/proposals.csv @@ -0,0 +1,5 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,58,26,1508,377.0,18,2,3,5,7,Studio Oak +P00,23,36,828,248.4,21,7,3,2,6,Studio Oak +P01,34,50,1700,850.0,18,2,8,2,7,Studio Ash +P02,42,59,2478,1239.0,21,5,8,2,6,Studio Oak diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0077/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0077/instruction.md b/tasks/zoning-check/zoning-check-compliance-d2-t0077/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0077/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0077/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d2-t0077/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0077/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d2-t0077/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d2-t0077/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d2-t0077/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..ed127bd367c1431ca95fefbe70f6a739e221b870 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P04,30,25,1200.0,450.0,9,5,6,2,6,Studio Ash +P00,34,46,2502.4,938.4,21,7,6,2,7,Studio Elm +P02,41,29,1902.4,297.25,12,5,8,9,7,Studio Elm +P01,32,67,3430.4,1286.4,18,5,6,5,7,Studio Elm +P03,45,43,3096.0,580.5,9,7,3,5,3,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0009/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0009/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-e0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0009/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0009/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-e0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0009/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0009/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-e0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0009/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..9d98080f75d23c2b037121abce824184af0b1c00 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P02,25,51,1785.0,318.75,9,5,3,2,7,Studio Elm +P00,32,43,1926.4,412.8,18,2,6,5,3,Studio Ash +P01,51,46,2346,1407.6,12,5,6,5,7,Studio Elm +P04,42,52,3057.6,546.0,21,5,8,2,7,Studio Ash +P03,41,47,3083.2,578.1,18,5,8,9,7,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0021/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0021/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-e0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0021/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0021/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-e0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0021/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-e0021/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-e0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-e0021/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..efcf3ce9f07bac354172bf854900b8aa67e8a75d --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,51,35,2499.0,1071.0,12,5,8,2,6,Studio Ash +P01,57,58,2644.8,991.8,21,5,8,9,3,Studio Ash +P02,57,60,2736.0,1026.0,9,7,3,2,3,Studio Oak +P04,60,43,2064.0,1548.0,21,2,8,9,7,Studio Ash +P00,30,36,1512.0,540.0,12,7,6,2,7,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0009/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0009/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-t0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0009/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0009/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-t0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0009/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0009/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-t0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0009/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..28c72b4eca1a0fc7740a5648fed68b59b474c352 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P00,51,51,2080.8,1560.6,12,5,6,2,7,Studio Elm +P03,40,60,3360.0,600.0,9,7,3,5,3,Studio Oak +P01,31,67,3323.2,1246.2,18,2,8,9,6,Studio Oak +P04,20,47,940,564.0,21,7,3,5,3,Studio Ash +P02,35,42,1470,367.5,12,7,8,9,7,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0021/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0021/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-t0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0021/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0021/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-t0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0021/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0021/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-t0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0021/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..05291545c0505e25be87919127b781c15a3577b8 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,44,36,2217.6,950.4,9,5,6,2,6,Studio Oak +P01,26,26,946.4,169.0,9,2,6,2,7,Studio Ash +P02,45,36,1296.0,486.0,12,2,6,2,7,Studio Elm +P04,24,35,840,252.0,12,2,6,2,7,Studio Oak +P00,51,32,1305.6,489.6,21,5,8,9,6,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0033/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0033/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-t0033/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0033/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0033/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-t0033/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0033/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0033/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-t0033/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0033/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..03372b2e7fd26ad335752b94bea9de3943a463f5 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P04,55,64,3520,880.0,18,2,8,9,7,Studio Elm +P03,49,42,3292.8,514.5,9,7,3,5,6,Studio Oak +P02,44,57,2508,752.4,12,2,3,2,3,Studio Ash +P00,60,28,2688.0,504.0,21,5,8,2,6,Studio Oak +P01,58,35,2842.0,1015.0,18,5,6,9,6,Studio Ash diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0045/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0045/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-t0045/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0045/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0045/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-t0045/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0045/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0045/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-t0045/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0045/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..6488ac403a0a4ae95c57f59f3d36480faf5edec5 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P03,58,44,3572.8,638.0,18,7,8,2,7,Studio Oak +P04,59,46,4342.4,814.2,9,5,8,5,6,Studio Ash +P02,44,54,3801.6,1188.0,18,2,3,2,6,Studio Oak +P00,57,25,2280.0,712.5,21,5,8,5,7,Studio Elm +P01,46,51,2346,703.8,9,7,6,2,3,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0057/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0057/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-t0057/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0057/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0057/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-t0057/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0057/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0057/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-t0057/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0057/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..b2d8e74cfb833b2c8e9a08ab502ea0731dfd4580 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P01,50,25,1750.0,750.0,9,5,8,5,7,Studio Elm +P03,33,26,1372.8,429.0,21,5,3,5,3,Studio Elm +P00,27,40,1080,324.0,21,5,6,5,3,Studio Oak +P02,59,25,2065.0,885.0,18,5,6,9,6,Studio Ash +P04,23,66,1518,910.8,18,5,8,9,6,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0069/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0069/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-t0069/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0069/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0069/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-t0069/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0069/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0069/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-t0069/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0069/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/Dockerfile b/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/workdir/proposals.csv b/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/workdir/proposals.csv new file mode 100644 index 0000000000000000000000000000000000000000..47ce25ab63fd58707eced31fe1a8463be46bba81 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/workdir/proposals.csv @@ -0,0 +1,6 @@ +proposal_id,width_m,depth_m,gross_floor_m2,footprint_m2,height_m,front_m,rear_m,left_m,right_m,architect +P00,24,50,1680.0,300.0,9,7,6,5,6,Studio Elm +P04,25,35,700.0,525.0,12,2,6,9,3,Studio Ash +P01,46,64,2944,1766.4,9,7,6,5,3,Studio Ash +P02,25,30,750,375.0,9,5,8,2,7,Studio Ash +P03,33,50,2310.0,495.0,18,7,8,5,3,Studio Elm diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0081/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0081/instruction.md b/tasks/zoning-check/zoning-check-compliance-d3-t0081/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb572f2cbae12d119131e4d0a8ae899a1289ac97 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0081/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: compliance + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `proposals.csv` lists rectangular plots and proposed buildings. Gross floor area includes every storey. Limits are inclusive: equality passes. Flag a setback violation if any of the four setbacks is too small. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `site_m2` (width times depth), `far` (gross floor area divided by site area), `coverage_percent` (100 times footprint divided by site area), and `violations` (distinct strings from `far`, `coverage`, `setback`, `height`, or an empty list). diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0081/solution/oracle.py b/tasks/zoning-check/zoning-check-compliance-d3-t0081/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0081/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-compliance-d3-t0081/tests/verify.py b/tasks/zoning-check/zoning-check-compliance-d3-t0081/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-compliance-d3-t0081/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..c4caea0f0124cd9b0d30adc19f89abd10ff5edb7 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 17, + -4 + ], + [ + 76, + -4 + ], + [ + 76, + 25 + ], + [ + 17, + 25 + ] + ], + "G01": [ + [ + -27, + -20 + ], + [ + 7, + -20 + ], + [ + 7, + 11 + ], + [ + -27, + 11 + ] + ], + "G02": [ + [ + 22, + -15 + ], + [ + 46, + -15 + ], + [ + 46, + 24 + ], + [ + 22, + 24 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..678239cca38c978bf98ca8eec0b0bca24b24c416 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,517,169 +G01,246,291 +G02,173,120 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0002/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0002/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-e0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0002/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0002/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-e0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0002/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0002/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-e0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0002/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..e99fd91bf776b2bbbf9e9b5d6021e477a0f486f4 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 16, + -5 + ], + [ + 37, + -5 + ], + [ + 37, + 54 + ], + [ + 16, + 54 + ] + ], + "G01": [ + [ + -7, + 4 + ], + [ + 40, + 4 + ], + [ + 40, + 70 + ], + [ + -7, + 70 + ] + ], + "G02": [ + [ + 18, + -4 + ], + [ + 52, + -4 + ], + [ + 52, + 33 + ], + [ + 18, + 33 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..4e54d4fcafd7128d9cae860f11b4edca0bc4b395 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,796,109 +G01,699,108 +G02,509,222 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0014/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0014/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-e0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0014/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0014/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-e0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0014/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-e0014/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-e0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-e0014/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..17a773d799f8234abdc537f2cc3edd7b70b45200 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 11, + 3 + ], + [ + 38, + 3 + ], + [ + 38, + 61 + ], + [ + 11, + 61 + ] + ], + "G01": [ + [ + 2, + -7 + ], + [ + 22, + -7 + ], + [ + 22, + 28 + ], + [ + 2, + 28 + ] + ], + "G02": [ + [ + 14, + 5 + ], + [ + 79, + 5 + ], + [ + 79, + 72 + ], + [ + 14, + 72 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..b783b9afb095361f56f0c05415bb436edb1c4f63 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,765,142 +G01,786,203 +G02,762,261 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0002/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0002/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-t0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0002/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0002/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-t0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0002/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0002/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-t0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0002/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..73fde54019bc6f18ac63374fa4319d714661004e --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 27, + 4 + ], + [ + 85, + 4 + ], + [ + 85, + 61 + ], + [ + 27, + 61 + ] + ], + "G01": [ + [ + -23, + 13 + ], + [ + 23, + 13 + ], + [ + 23, + 71 + ], + [ + -23, + 71 + ] + ], + "G02": [ + [ + 7, + -17 + ], + [ + 36, + -17 + ], + [ + 36, + 24 + ], + [ + 7, + 24 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..d6050b3af9771e61f972f8fc2246bd1bb49e7c83 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,165,101 +G01,301,244 +G02,319,278 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0014/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0014/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-t0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0014/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0014/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-t0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0014/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0014/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-t0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0014/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..832581018becf344feeb1be614970f2563b0a30b --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + -5, + -19 + ], + [ + 44, + -19 + ], + [ + 44, + 24 + ], + [ + -5, + 24 + ] + ], + "G01": [ + [ + 26, + 16 + ], + [ + 69, + 16 + ], + [ + 69, + 81 + ], + [ + 26, + 81 + ] + ], + "G02": [ + [ + -11, + -20 + ], + [ + 34, + -20 + ], + [ + 34, + 35 + ], + [ + -11, + 35 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..a873f6807639f70506b580fa86ea46524ae1f22a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,272,161 +G01,175,295 +G02,764,254 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0026/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0026/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-t0026/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0026/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0026/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-t0026/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0026/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0026/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-t0026/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0026/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..6c0627ccb018a9f96b0207bf7cb1f96eb62dc6a0 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 3, + 30 + ], + [ + 67, + 30 + ], + [ + 67, + 94 + ], + [ + 3, + 94 + ] + ], + "G01": [ + [ + -7, + 30 + ], + [ + 39, + 30 + ], + [ + 39, + 68 + ], + [ + -7, + 68 + ] + ], + "G02": [ + [ + 6, + 13 + ], + [ + 36, + 13 + ], + [ + 36, + 43 + ], + [ + 6, + 43 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..e8495428da1d714da82e3bf32b6858eb74ccfaf1 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,400,288 +G01,862,201 +G02,867,280 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0038/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0038/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-t0038/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0038/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0038/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-t0038/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0038/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0038/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-t0038/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0038/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..0d9dd6f49c912054cd416cb473307f30ccbaa49c --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 29, + -11 + ], + [ + 51, + -11 + ], + [ + 51, + 19 + ], + [ + 29, + 19 + ] + ], + "G01": [ + [ + 20, + -22 + ], + [ + 58, + -22 + ], + [ + 58, + 34 + ], + [ + 20, + 34 + ] + ], + "G02": [ + [ + 7, + 20 + ], + [ + 70, + 20 + ], + [ + 70, + 90 + ], + [ + 7, + 90 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..122ddf4ba4aa46755f5b4ec95e13daf071ce071e --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,248,122 +G01,868,209 +G02,284,189 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0050/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0050/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-t0050/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0050/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0050/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-t0050/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0050/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0050/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-t0050/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0050/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..fdf38bb152f1ee193548d1addf42c8bd8cba2c3e --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 4, + 26 + ], + [ + 49, + 26 + ], + [ + 49, + 61 + ], + [ + 4, + 61 + ] + ], + "G01": [ + [ + -24, + 27 + ], + [ + 28, + 27 + ], + [ + 28, + 80 + ], + [ + -24, + 80 + ] + ], + "G02": [ + [ + -12, + 0 + ], + [ + 21, + 0 + ], + [ + 21, + 35 + ], + [ + -12, + 35 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..151feb75fc7291dfc2f6689757b2f7dc90fe24e8 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,423,116 +G01,454,185 +G02,638,268 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0062/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0062/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-t0062/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0062/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0062/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-t0062/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0062/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0062/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-t0062/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0062/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..a7ad040bc485650389bd67d3519586d03d139cc4 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/boundaries.json @@ -0,0 +1,56 @@ +{ + "G00": [ + [ + 3, + 23 + ], + [ + 56, + 23 + ], + [ + 56, + 75 + ], + [ + 3, + 75 + ] + ], + "G01": [ + [ + 27, + 21 + ], + [ + 64, + 21 + ], + [ + 64, + 85 + ], + [ + 27, + 85 + ] + ], + "G02": [ + [ + -12, + 1 + ], + [ + 15, + 1 + ], + [ + 15, + 41 + ], + [ + -12, + 41 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..f57e211f3272ebd35b18c6179043f105a63c618d --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/buildings.csv @@ -0,0 +1,4 @@ +plot_id,floor_m2,footprint_m2 +G00,127,210 +G01,564,107 +G02,675,245 diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0074/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0074/instruction.md b/tasks/zoning-check/zoning-check-geometry-d1-t0074/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0074/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0074/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d1-t0074/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0074/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d1-t0074/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d1-t0074/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d1-t0074/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..fe96902bc7349a1ce475a5d988e2bbb21c339742 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + 21, + 29 + ], + [ + 44, + 29 + ], + [ + 44, + 33 + ], + [ + 26, + 33 + ], + [ + 26, + 61 + ], + [ + 21, + 61 + ] + ], + "G01": [ + [ + -3, + -2 + ], + [ + 57, + -2 + ], + [ + 57, + 12 + ], + [ + 14, + 12 + ], + [ + 14, + 35 + ], + [ + -3, + 35 + ] + ], + "G02": [ + [ + -6, + -26 + ], + [ + 37, + -26 + ], + [ + 37, + -18 + ], + [ + 13, + -18 + ], + [ + 13, + 17 + ], + [ + -6, + 17 + ] + ], + "G03": [ + [ + -28, + -15 + ], + [ + 12, + -15 + ], + [ + 12, + 11 + ], + [ + -19, + 11 + ], + [ + -19, + 40 + ], + [ + -28, + 40 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..de64292d02c4dd4ff6cbc5bf1b403f1850c29bf6 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,146,246 +G01,366,281 +G02,600,166 +G03,496,187 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0006/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0006/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-e0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0006/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0006/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-e0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0006/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0006/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-e0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0006/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..1636d7a276bcc3c150c8e4496e81d346953d7d36 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + 3, + -16 + ], + [ + 60, + -16 + ], + [ + 60, + -12 + ], + [ + 27, + -12 + ], + [ + 27, + 13 + ], + [ + 3, + 13 + ] + ], + "G01": [ + [ + -5, + -16 + ], + [ + 15, + -16 + ], + [ + 15, + 18 + ], + [ + -1, + 18 + ], + [ + -1, + 54 + ], + [ + -5, + 54 + ] + ], + "G02": [ + [ + 12, + -1 + ], + [ + 35, + -1 + ], + [ + 35, + 11 + ], + [ + 20, + 11 + ], + [ + 20, + 26 + ], + [ + 12, + 26 + ] + ], + "G03": [ + [ + -22, + -15 + ], + [ + 4, + -15 + ], + [ + 4, + 11 + ], + [ + -13, + 11 + ], + [ + -13, + 54 + ], + [ + -22, + 54 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..063b9c3b09f09c8757e6e089856ad00e07e7e294 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,131,283 +G01,704,241 +G02,603,131 +G03,874,162 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0018/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0018/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-e0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0018/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0018/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-e0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0018/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-e0018/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-e0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-e0018/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..a21ef4e837d4502af9006e322290ad8bea0ff0f0 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + -27, + -21 + ], + [ + 40, + -21 + ], + [ + 40, + -13 + ], + [ + -13, + -13 + ], + [ + -13, + 20 + ], + [ + -27, + 20 + ] + ], + "G01": [ + [ + -11, + -2 + ], + [ + 35, + -2 + ], + [ + 35, + 15 + ], + [ + 12, + 15 + ], + [ + 12, + 65 + ], + [ + -11, + 65 + ] + ], + "G02": [ + [ + 23, + 5 + ], + [ + 58, + 5 + ], + [ + 58, + 39 + ], + [ + 27, + 39 + ], + [ + 27, + 75 + ], + [ + 23, + 75 + ] + ], + "G03": [ + [ + -27, + -18 + ], + [ + 30, + -18 + ], + [ + 30, + -3 + ], + [ + -10, + -3 + ], + [ + -10, + 24 + ], + [ + -27, + 24 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..27da3937e48cb0cc7546b8858c1e1ff8f7d55463 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,797,127 +G01,817,287 +G02,315,153 +G03,184,243 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0006/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0006/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-t0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0006/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0006/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-t0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0006/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0006/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-t0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0006/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..9cba7a14e6819b862a2d79ea7f883200df813f21 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + -2, + -25 + ], + [ + 62, + -25 + ], + [ + 62, + -5 + ], + [ + 19, + -5 + ], + [ + 19, + 29 + ], + [ + -2, + 29 + ] + ], + "G01": [ + [ + 11, + 22 + ], + [ + 74, + 22 + ], + [ + 74, + 31 + ], + [ + 39, + 31 + ], + [ + 39, + 52 + ], + [ + 11, + 52 + ] + ], + "G02": [ + [ + 24, + 2 + ], + [ + 53, + 2 + ], + [ + 53, + 8 + ], + [ + 34, + 8 + ], + [ + 34, + 27 + ], + [ + 24, + 27 + ] + ], + "G03": [ + [ + 22, + -14 + ], + [ + 86, + -14 + ], + [ + 86, + 13 + ], + [ + 41, + 13 + ], + [ + 41, + 48 + ], + [ + 22, + 48 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..fba245ac7e07a3d8a0f4a04b4df39feef4eb5e64 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,223,234 +G01,271,138 +G02,226,184 +G03,517,131 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0018/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0018/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-t0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0018/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0018/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-t0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0018/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0018/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-t0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0018/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..65ddba60e1782cb36fb56d5f230e8682f0273599 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + -9, + 30 + ], + [ + 13, + 30 + ], + [ + 13, + 49 + ], + [ + 1, + 49 + ], + [ + 1, + 72 + ], + [ + -9, + 72 + ] + ], + "G01": [ + [ + 4, + 15 + ], + [ + 25, + 15 + ], + [ + 25, + 31 + ], + [ + 14, + 31 + ], + [ + 14, + 67 + ], + [ + 4, + 67 + ] + ], + "G02": [ + [ + 8, + -22 + ], + [ + 56, + -22 + ], + [ + 56, + -10 + ], + [ + 27, + -10 + ], + [ + 27, + 32 + ], + [ + 8, + 32 + ] + ], + "G03": [ + [ + -28, + 21 + ], + [ + 19, + 21 + ], + [ + 19, + 52 + ], + [ + -5, + 52 + ], + [ + -5, + 86 + ], + [ + -28, + 86 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..4cf86df5aef5cd4f721099c7717d3810fb8e72aa --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,502,182 +G01,267,206 +G02,882,175 +G03,527,240 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0030/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0030/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-t0030/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0030/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0030/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-t0030/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0030/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0030/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-t0030/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0030/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..00ef86291fe4830964094d500628c5b0a3b5519d --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + -28, + 12 + ], + [ + 25, + 12 + ], + [ + 25, + 20 + ], + [ + -9, + 20 + ], + [ + -9, + 43 + ], + [ + -28, + 43 + ] + ], + "G01": [ + [ + -19, + 1 + ], + [ + 48, + 1 + ], + [ + 48, + 22 + ], + [ + -12, + 22 + ], + [ + -12, + 49 + ], + [ + -19, + 49 + ] + ], + "G02": [ + [ + -19, + -8 + ], + [ + 9, + -8 + ], + [ + 9, + 9 + ], + [ + -13, + 9 + ], + [ + -13, + 62 + ], + [ + -19, + 62 + ] + ], + "G03": [ + [ + -22, + 26 + ], + [ + 0, + 26 + ], + [ + 0, + 30 + ], + [ + -12, + 30 + ], + [ + -12, + 47 + ], + [ + -22, + 47 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..faf28cffc51c9a01e4a83d4bf5ddb098bf912311 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,890,102 +G01,403,210 +G02,164,223 +G03,837,231 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0042/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0042/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-t0042/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0042/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0042/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-t0042/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0042/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0042/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-t0042/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0042/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..535dc420a02ab7c61758970bbd769e3f68e4f294 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + -14, + -16 + ], + [ + 11, + -16 + ], + [ + 11, + -7 + ], + [ + -5, + -7 + ], + [ + -5, + 11 + ], + [ + -14, + 11 + ] + ], + "G01": [ + [ + 24, + -11 + ], + [ + 93, + -11 + ], + [ + 93, + 14 + ], + [ + 48, + 14 + ], + [ + 48, + 39 + ], + [ + 24, + 39 + ] + ], + "G02": [ + [ + 16, + -24 + ], + [ + 41, + -24 + ], + [ + 41, + -2 + ], + [ + 27, + -2 + ], + [ + 27, + 26 + ], + [ + 16, + 26 + ] + ], + "G03": [ + [ + -23, + 21 + ], + [ + 14, + 21 + ], + [ + 14, + 38 + ], + [ + -18, + 38 + ], + [ + -18, + 67 + ], + [ + -23, + 67 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..3dc8bd3c17fc2ab3f60f62ae20997938b92b92ed --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,802,184 +G01,352,273 +G02,325,239 +G03,839,231 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0054/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0054/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-t0054/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0054/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0054/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-t0054/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0054/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0054/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-t0054/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0054/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..fbb030ff35a23affc2a8ecb94fb4ef68da213732 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + 22, + 3 + ], + [ + 92, + 3 + ], + [ + 92, + 10 + ], + [ + 32, + 10 + ], + [ + 32, + 23 + ], + [ + 22, + 23 + ] + ], + "G01": [ + [ + -29, + -27 + ], + [ + 34, + -27 + ], + [ + 34, + -2 + ], + [ + -21, + -2 + ], + [ + -21, + 24 + ], + [ + -29, + 24 + ] + ], + "G02": [ + [ + -18, + 18 + ], + [ + 35, + 18 + ], + [ + 35, + 31 + ], + [ + 2, + 31 + ], + [ + 2, + 56 + ], + [ + -18, + 56 + ] + ], + "G03": [ + [ + -7, + -3 + ], + [ + 52, + -3 + ], + [ + 52, + 9 + ], + [ + 9, + 9 + ], + [ + 9, + 28 + ], + [ + -7, + 28 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..cdf3b61b19fd60ad43c5f054853cae78c40b6cf1 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,542,267 +G01,271,230 +G02,524,241 +G03,300,180 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0066/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0066/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-t0066/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0066/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0066/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-t0066/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0066/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0066/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-t0066/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0066/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..08ef9b7d3d3bbce78a4a6a1d9c388954a53a53ee --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/boundaries.json @@ -0,0 +1,106 @@ +{ + "G00": [ + [ + -5, + -12 + ], + [ + 28, + -12 + ], + [ + 28, + 15 + ], + [ + 7, + 15 + ], + [ + 7, + 49 + ], + [ + -5, + 49 + ] + ], + "G01": [ + [ + -23, + -5 + ], + [ + 6, + -5 + ], + [ + 6, + 6 + ], + [ + -19, + 6 + ], + [ + -19, + 31 + ], + [ + -23, + 31 + ] + ], + "G02": [ + [ + -9, + 16 + ], + [ + 24, + 16 + ], + [ + 24, + 24 + ], + [ + -1, + 24 + ], + [ + -1, + 41 + ], + [ + -9, + 41 + ] + ], + "G03": [ + [ + -19, + 3 + ], + [ + 50, + 3 + ], + [ + 50, + 12 + ], + [ + 0, + 12 + ], + [ + 0, + 48 + ], + [ + -19, + 48 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..877ee3b6e4d0337e3b2d86afa5abf7abc0531829 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/buildings.csv @@ -0,0 +1,5 @@ +plot_id,floor_m2,footprint_m2 +G00,112,167 +G01,823,133 +G02,365,111 +G03,619,286 diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0078/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0078/instruction.md b/tasks/zoning-check/zoning-check-geometry-d2-t0078/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0078/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0078/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d2-t0078/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0078/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d2-t0078/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d2-t0078/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d2-t0078/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..3496eae5ca7fdb1b772f75bd0b1000385e8656e3 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + 3, + 25 + ], + [ + 15, + 25 + ], + [ + 15, + 5 + ], + [ + 43, + 5 + ], + [ + 43, + -9 + ], + [ + 3, + -9 + ] + ], + "G01": [ + [ + -27, + 25 + ], + [ + -23, + 25 + ], + [ + -23, + -14 + ], + [ + -6, + -14 + ], + [ + -6, + -18 + ], + [ + -27, + -18 + ] + ], + "G02": [ + [ + 8, + 46 + ], + [ + 17, + 46 + ], + [ + 17, + 2 + ], + [ + 46, + 2 + ], + [ + 46, + -13 + ], + [ + 8, + -13 + ] + ], + "G03": [ + [ + -9, + 16 + ], + [ + 15, + 16 + ], + [ + 15, + -7 + ], + [ + 40, + -7 + ], + [ + 40, + -11 + ], + [ + -9, + -11 + ] + ], + "G04": [ + [ + -15, + 61 + ], + [ + -11, + 61 + ], + [ + -11, + 26 + ], + [ + 28, + 26 + ], + [ + 28, + 17 + ], + [ + -15, + 17 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..030db5e921d02b3a2abc215f7f0615afdaef57f9 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,139,206 +G01,700,163 +G02,285,232 +G03,891,253 +G04,409,152 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0010/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0010/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-e0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0010/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0010/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-e0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0010/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0010/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-e0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0010/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..300fdf15bf2a620765348d837bcedccf6bdff2dc --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + -23, + 28 + ], + [ + -13, + 28 + ], + [ + -13, + 14 + ], + [ + 15, + 14 + ], + [ + 15, + 5 + ], + [ + -23, + 5 + ] + ], + "G01": [ + [ + -24, + 66 + ], + [ + -13, + 66 + ], + [ + -13, + 32 + ], + [ + 8, + 32 + ], + [ + 8, + 23 + ], + [ + -24, + 23 + ] + ], + "G02": [ + [ + -18, + 79 + ], + [ + -1, + 79 + ], + [ + -1, + 43 + ], + [ + 39, + 43 + ], + [ + 39, + 16 + ], + [ + -18, + 16 + ] + ], + "G03": [ + [ + -15, + 64 + ], + [ + -5, + 64 + ], + [ + -5, + 43 + ], + [ + 35, + 43 + ], + [ + 35, + 26 + ], + [ + -15, + 26 + ] + ], + "G04": [ + [ + 15, + 50 + ], + [ + 23, + 50 + ], + [ + 23, + 0 + ], + [ + 83, + 0 + ], + [ + 83, + -6 + ], + [ + 15, + -6 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..6e8f5e5b6abe46d9503351e12aff754559202ee7 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,512,198 +G01,193,286 +G02,471,130 +G03,189,123 +G04,898,183 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0022/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0022/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-e0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0022/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0022/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-e0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0022/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-e0022/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-e0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-e0022/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..a002704a26429c99e3d519a73ddd15c8854c9e3b --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + -25, + 48 + ], + [ + -10, + 48 + ], + [ + -10, + 8 + ], + [ + 10, + 8 + ], + [ + 10, + -3 + ], + [ + -25, + -3 + ] + ], + "G01": [ + [ + 15, + 51 + ], + [ + 37, + 51 + ], + [ + 37, + -7 + ], + [ + 65, + -7 + ], + [ + 65, + -12 + ], + [ + 15, + -12 + ] + ], + "G02": [ + [ + 20, + 35 + ], + [ + 27, + 35 + ], + [ + 27, + 0 + ], + [ + 59, + 0 + ], + [ + 59, + -17 + ], + [ + 20, + -17 + ] + ], + "G03": [ + [ + 22, + 18 + ], + [ + 29, + 18 + ], + [ + 29, + 2 + ], + [ + 43, + 2 + ], + [ + 43, + -14 + ], + [ + 22, + -14 + ] + ], + "G04": [ + [ + -20, + 16 + ], + [ + -13, + 16 + ], + [ + -13, + -13 + ], + [ + 2, + -13 + ], + [ + 2, + -30 + ], + [ + -20, + -30 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..7d98c4f13abfad0286e511cd34a99dd679260454 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,686,124 +G01,340,198 +G02,683,216 +G03,350,109 +G04,734,278 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0010/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0010/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-t0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0010/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0010/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-t0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0010/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0010/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-t0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0010/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..285a5c7dae1658d1b75680c1a057d2cdace8d1d1 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + -15, + 21 + ], + [ + -3, + 21 + ], + [ + -3, + -16 + ], + [ + 43, + -16 + ], + [ + 43, + -26 + ], + [ + -15, + -26 + ] + ], + "G01": [ + [ + 20, + 43 + ], + [ + 30, + 43 + ], + [ + 30, + 21 + ], + [ + 44, + 21 + ], + [ + 44, + 16 + ], + [ + 20, + 16 + ] + ], + "G02": [ + [ + -15, + 5 + ], + [ + 4, + 5 + ], + [ + 4, + -12 + ], + [ + 42, + -12 + ], + [ + 42, + -16 + ], + [ + -15, + -16 + ] + ], + "G03": [ + [ + 29, + 7 + ], + [ + 41, + 7 + ], + [ + 41, + -10 + ], + [ + 84, + -10 + ], + [ + 84, + -25 + ], + [ + 29, + -25 + ] + ], + "G04": [ + [ + 5, + 62 + ], + [ + 9, + 62 + ], + [ + 9, + 31 + ], + [ + 69, + 31 + ], + [ + 69, + 22 + ], + [ + 5, + 22 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..e4ed4d56168a1b6d778487a43b1c32c3ca90dadc --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,791,198 +G01,619,157 +G02,360,268 +G03,759,217 +G04,473,281 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0022/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0022/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-t0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0022/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0022/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-t0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0022/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0022/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-t0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0022/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..ab48eb5aba84704c78451909b7915035c3754770 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + -24, + 27 + ], + [ + -9, + 27 + ], + [ + -9, + 10 + ], + [ + 40, + 10 + ], + [ + 40, + 1 + ], + [ + -24, + 1 + ] + ], + "G01": [ + [ + -13, + 49 + ], + [ + 2, + 49 + ], + [ + 2, + 35 + ], + [ + 25, + 35 + ], + [ + 25, + 28 + ], + [ + -13, + 28 + ] + ], + "G02": [ + [ + 23, + 53 + ], + [ + 44, + 53 + ], + [ + 44, + 31 + ], + [ + 75, + 31 + ], + [ + 75, + 18 + ], + [ + 23, + 18 + ] + ], + "G03": [ + [ + -1, + 49 + ], + [ + 13, + 49 + ], + [ + 13, + 15 + ], + [ + 63, + 15 + ], + [ + 63, + 0 + ], + [ + -1, + 0 + ] + ], + "G04": [ + [ + -19, + 15 + ], + [ + -15, + 15 + ], + [ + -15, + -12 + ], + [ + 1, + -12 + ], + [ + 1, + -19 + ], + [ + -19, + -19 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..ad3422c79f9f075a8557c67efaa3e470553ebc08 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,138,194 +G01,836,233 +G02,358,165 +G03,446,206 +G04,839,286 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0034/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0034/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-t0034/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0034/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0034/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-t0034/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0034/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0034/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-t0034/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0034/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..06455f48ce2832645f866a70e0ac156c5505ddde --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + 10, + 83 + ], + [ + 37, + 83 + ], + [ + 37, + 50 + ], + [ + 70, + 50 + ], + [ + 70, + 27 + ], + [ + 10, + 27 + ] + ], + "G01": [ + [ + 16, + 68 + ], + [ + 28, + 68 + ], + [ + 28, + 34 + ], + [ + 47, + 34 + ], + [ + 47, + 0 + ], + [ + 16, + 0 + ] + ], + "G02": [ + [ + -6, + 66 + ], + [ + 19, + 66 + ], + [ + 19, + 41 + ], + [ + 50, + 41 + ], + [ + 50, + 21 + ], + [ + -6, + 21 + ] + ], + "G03": [ + [ + 9, + 84 + ], + [ + 17, + 84 + ], + [ + 17, + 57 + ], + [ + 34, + 57 + ], + [ + 34, + 30 + ], + [ + 9, + 30 + ] + ], + "G04": [ + [ + -13, + 44 + ], + [ + -9, + 44 + ], + [ + -9, + 6 + ], + [ + 12, + 6 + ], + [ + 12, + -4 + ], + [ + -13, + -4 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..6d6d1d4aa6fc3e997b9ab9d6295e0020ef03c8a8 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,542,224 +G01,623,172 +G02,217,290 +G03,305,282 +G04,326,274 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0046/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0046/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-t0046/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0046/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0046/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-t0046/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0046/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0046/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-t0046/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0046/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..bcecfd0cf4986340082424fdd662d2dccd2c9f5b --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + -13, + 39 + ], + [ + -7, + 39 + ], + [ + -7, + 6 + ], + [ + 12, + 6 + ], + [ + 12, + -22 + ], + [ + -13, + -22 + ] + ], + "G01": [ + [ + 25, + 12 + ], + [ + 37, + 12 + ], + [ + 37, + -3 + ], + [ + 55, + -3 + ], + [ + 55, + -16 + ], + [ + 25, + -16 + ] + ], + "G02": [ + [ + -3, + 59 + ], + [ + 12, + 59 + ], + [ + 12, + 40 + ], + [ + 31, + 40 + ], + [ + 31, + 21 + ], + [ + -3, + 21 + ] + ], + "G03": [ + [ + -4, + 52 + ], + [ + 18, + 52 + ], + [ + 18, + 1 + ], + [ + 40, + 1 + ], + [ + 40, + -7 + ], + [ + -4, + -7 + ] + ], + "G04": [ + [ + 7, + 16 + ], + [ + 25, + 16 + ], + [ + 25, + -7 + ], + [ + 43, + -7 + ], + [ + 43, + -25 + ], + [ + 7, + -25 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..6fcb4527eb99146ef3174d076c5654ee09bb9c21 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,490,170 +G01,745,204 +G02,274,230 +G03,505,200 +G04,285,154 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0058/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0058/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-t0058/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0058/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0058/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-t0058/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0058/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0058/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-t0058/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0058/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..eb45c16257de45b89190465de6992fcdb350747d --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + 19, + 80 + ], + [ + 25, + 80 + ], + [ + 25, + 36 + ], + [ + 40, + 36 + ], + [ + 40, + 28 + ], + [ + 19, + 28 + ] + ], + "G01": [ + [ + -29, + 49 + ], + [ + -19, + 49 + ], + [ + -19, + 34 + ], + [ + 26, + 34 + ], + [ + 26, + 28 + ], + [ + -29, + 28 + ] + ], + "G02": [ + [ + 6, + 83 + ], + [ + 14, + 83 + ], + [ + 14, + 29 + ], + [ + 31, + 29 + ], + [ + 31, + 15 + ], + [ + 6, + 15 + ] + ], + "G03": [ + [ + -20, + 61 + ], + [ + -6, + 61 + ], + [ + -6, + 39 + ], + [ + 10, + 39 + ], + [ + 10, + 18 + ], + [ + -20, + 18 + ] + ], + "G04": [ + [ + -23, + 26 + ], + [ + -19, + 26 + ], + [ + -19, + -12 + ], + [ + 2, + -12 + ], + [ + 2, + -23 + ], + [ + -23, + -23 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..71773ca15b01360b986c19707bea53ec946a0422 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,798,176 +G01,696,179 +G02,741,257 +G03,846,132 +G04,245,124 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0070/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0070/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-t0070/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0070/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0070/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-t0070/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0070/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0070/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-t0070/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0070/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/Dockerfile b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/boundaries.json b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/boundaries.json new file mode 100644 index 0000000000000000000000000000000000000000..185ca71b4a3d0edeb6fb2b4869ba70ebc87a15ed --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/boundaries.json @@ -0,0 +1,132 @@ +{ + "G00": [ + [ + 3, + 18 + ], + [ + 7, + 18 + ], + [ + 7, + -21 + ], + [ + 37, + -21 + ], + [ + 37, + -25 + ], + [ + 3, + -25 + ] + ], + "G01": [ + [ + 10, + 60 + ], + [ + 25, + 60 + ], + [ + 25, + 2 + ], + [ + 55, + 2 + ], + [ + 55, + -10 + ], + [ + 10, + -10 + ] + ], + "G02": [ + [ + -13, + 5 + ], + [ + 6, + 5 + ], + [ + 6, + -10 + ], + [ + 27, + -10 + ], + [ + 27, + -19 + ], + [ + -13, + -19 + ] + ], + "G03": [ + [ + -23, + 30 + ], + [ + -11, + 30 + ], + [ + -11, + -14 + ], + [ + 19, + -14 + ], + [ + 19, + -24 + ], + [ + -23, + -24 + ] + ], + "G04": [ + [ + -12, + 56 + ], + [ + 2, + 56 + ], + [ + 2, + 24 + ], + [ + 38, + 24 + ], + [ + 38, + -3 + ], + [ + -12, + -3 + ] + ] +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/buildings.csv b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/buildings.csv new file mode 100644 index 0000000000000000000000000000000000000000..443fd5da3cf83946c6252fad248e44c4c1358b5f --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/buildings.csv @@ -0,0 +1,6 @@ +plot_id,floor_m2,footprint_m2 +G00,637,171 +G01,753,183 +G02,363,127 +G03,413,151 +G04,256,141 diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0082/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0082/instruction.md b/tasks/zoning-check/zoning-check-geometry-d3-t0082/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4d6a8a6f9df22e93ecdc1a7f4400a8c41022626a --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0082/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: geometry + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `boundaries.json` gives each simple plot polygon as ordered [x,y] pairs in metres. The last point joins back to the first; orientation can vary. Compute area with the shoelace formula: half the absolute value of sum(x_i*y_next-x_next*y_i). `buildings.csv` supplies proposed floor and footprint areas. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `plots` is keyed by plot id, with `site_m2`, `far` (floor/site area) and `coverage_percent` (100*footprint/site area). diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0082/solution/oracle.py b/tasks/zoning-check/zoning-check-geometry-d3-t0082/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0082/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-geometry-d3-t0082/tests/verify.py b/tasks/zoning-check/zoning-check-geometry-d3-t0082/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-geometry-d3-t0082/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..0c5b330987edaffbda522a37172e75e1da02b7b6 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M01,5,120,510,16,400, +M00,5,320,390,25,625, +M02,9,320,210,22,550, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0003/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..097a2f527ca7281a33b36dd7c6ec3853f5940443 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M01,10,40,450,26,650, +M02,9,300,420,30,750, +M00,8,140,390,24,600, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-e0015/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..05a7b4b777481136b1d7ee39d6050160f2ec72ae --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M02,5,300,420,20,500, +M01,1,200,210,12,300, +M00,8,160,120,16,400, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0003/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..0b99938cc70da7fb9b471d5c2099ff370ec1f8fb --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,1,60,360,6,150, +M02,9,140,120,22,550, +M01,2,280,330,13,325, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0015/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..adafddf50630fc36ef6bdcab8d612a94ae4d52b3 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,2,100,570,18,450, +M02,2,260,360,19,475, +M01,4,380,270,22,550, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0027/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..ce1b1c439790025c9e0dbee116bec915a57822e4 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M02,9,320,240,28,700, +M00,8,120,450,25,625, +M01,3,280,120,11,275, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0039/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..fe558ef3be296a4ec723109c5d294c9f3a578575 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,6,340,180,24,600, +M01,6,80,600,18,450, +M02,2,80,240,6,150, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0051/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..a089f9811b21a97afefd98821b6e8e146ec5d06b --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,8,40,60,16,400, +M02,2,380,210,19,475, +M01,10,40,480,26,650, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0063/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..385faf62a4d66edb93087c8b16effd8af81d52de --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/workdir/uses.csv @@ -0,0 +1,4 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M01,6,220,540,26,650, +M02,2,300,120,10,250, +M00,2,400,420,17,425, diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d1-t0075/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..e513f61bde90a99db676e723af1ae1195f094309 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M03,8,180,330,19,475,revised application +M00,8,100,360,23,575,revised application +M01,1,360,270,13,325,revised application +M02,6,20,120,15,375,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0007/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..015eb6ac322803c78df23631d09b331c85f14318 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,1,80,600,16,400,revised application +M03,2,380,180,14,350,revised application +M01,4,160,60,14,350,revised application +M02,5,180,300,19,475,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-e0019/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..d6b882fd1625c3e2b3d6003c77690bd94947146a --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M03,2,380,510,19,475,revised application +M02,1,320,510,15,375,revised application +M00,6,80,60,14,350,revised application +M01,4,260,480,18,450,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0007/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..f341824a07699c2b764d22d62a040aa825aca9e8 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M03,3,260,420,20,500,revised application +M00,7,100,210,19,475,revised application +M01,6,240,330,24,600,revised application +M02,10,200,240,26,650,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0019/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..5625a8b5ef87730b1b272ecf274a35eda67b0d73 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M01,6,60,450,21,525,revised application +M00,1,100,210,6,150,revised application +M03,7,140,540,20,500,revised application +M02,7,340,240,25,625,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0031/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..31a553193cfa3cd479c675581e3f94a50f2afc02 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M01,6,100,240,13,325,revised application +M02,2,100,390,14,350,revised application +M03,10,280,150,23,575,revised application +M00,9,320,270,28,700,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0043/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..46026c3621e373da52e89735dbee263495553b98 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,9,120,240,24,600,revised application +M01,3,380,540,25,625,revised application +M03,2,280,120,15,375,revised application +M02,8,320,330,24,600,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0055/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..4fbcbfe41cfeab621b1cd2c3f5c57a2100c5c30b --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,6,80,420,20,500,revised application +M02,5,140,600,23,575,revised application +M01,4,80,510,15,375,revised application +M03,7,60,360,21,525,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0067/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..005c25e70f9ba518312bff4fb24ce35e0152e640 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/workdir/uses.csv @@ -0,0 +1,5 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,6,400,300,26,650,revised application +M02,4,180,150,10,250,revised application +M03,6,40,300,13,325,revised application +M01,3,160,90,13,325,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d2-t0079/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..79529ed93fc29f7fd4bfbd2c28109b4f18b9a88c --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M02,8,20,150,12,300,revised application +M00,5,140,270,18,450,revised application +M03,9,200,300,26,650,revised application +M01,9,200,540,25,625,revised application +M04,7,200,210,16,400,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0011/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..70fc9e589038d4a60c977813e6913b58c9525c67 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M03,10,120,300,20,500,revised application +M01,4,280,600,20,500,revised application +M02,7,60,480,22,550,revised application +M04,2,60,120,9,225,revised application +M00,7,140,240,15,375,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-e0023/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..68873ed7883344071d64bc6a4a3cd05ef6b449d1 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,1,60,510,10,250,revised application +M03,8,340,210,26,650,revised application +M04,4,160,240,17,425,revised application +M02,7,400,600,34,850,revised application +M01,1,400,90,16,400,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0011/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..5fd4b7488867471e6978e5cf35788526a37c3eb3 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,1,80,60,3,75,revised application +M03,9,280,330,28,700,revised application +M01,6,280,540,22,550,revised application +M04,6,280,330,19,475,revised application +M02,8,220,300,26,650,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0023/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..4127e4de6d83e893081730234c7c74aebcfc24df --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M01,1,120,510,10,250,revised application +M04,10,240,360,30,750,revised application +M03,1,120,120,10,250,revised application +M02,9,380,150,24,600,revised application +M00,4,120,240,10,250,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0035/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..39b792787da1da9ac5d1da60fa5a80dd21ccb032 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M01,6,40,540,17,425,revised application +M04,10,240,600,33,825,revised application +M00,4,280,480,18,450,revised application +M03,6,280,600,29,725,revised application +M02,8,120,240,21,525,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0047/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..ebad86fab558319054e33e13d3c77bd181bde07e --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M03,8,260,420,29,725,revised application +M04,6,80,330,20,500,revised application +M00,2,220,120,14,350,revised application +M02,3,380,30,13,325,revised application +M01,4,40,240,8,200,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0059/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..6a911f6a397d82d608ce00d80e4ec18c9c9712b3 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,9,360,150,28,700,revised application +M04,6,400,300,22,550,revised application +M02,1,360,180,16,400,revised application +M01,2,400,420,23,575,revised application +M03,9,340,300,24,600,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0071/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main() diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/Dockerfile b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/workdir/uses.csv b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/workdir/uses.csv new file mode 100644 index 0000000000000000000000000000000000000000..91b3651bf4223255e8787379e1492eb0ae02ab90 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/workdir/uses.csv @@ -0,0 +1,6 @@ +proposal_id,dwellings,shop_m2,office_m2,provided_spaces,parking_surface_m2,notes +M00,4,200,480,16,400,revised application +M03,8,100,60,19,475,revised application +M04,3,40,60,9,225,revised application +M02,3,80,300,15,375,revised application +M01,10,380,210,31,775,revised application diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/workdir/zoning_code.json b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/workdir/zoning_code.json new file mode 100644 index 0000000000000000000000000000000000000000..643d5778043a22d5fb5f1baf48ea8a871e4229bf --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/environment/workdir/zoning_code.json @@ -0,0 +1,10 @@ +{ + "max_far": 1.2, + "max_coverage": 0.4, + "setback_m": 4, + "height_m": 15, + "parking_area_m2": 25, + "parking_per_dwelling": 1.5, + "shop_m2_per_space": 40, + "office_m2_per_space": 60 +} diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/instruction.md b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..af579dc3f0499944e613e2aaa1aefd02afcff343 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/instruction.md @@ -0,0 +1,5 @@ +# Zoning Check: mixed-use + +All records are synthetic. Apply only the fictional limits in `zoning_code.json`. `uses.csv` lists mixed-use proposals. Required spaces = ceil(dwellings*parking_per_dwelling + shop_m2/shop_m2_per_space + office_m2/office_m2_per_space). Round upward once, after summing uses. Each space requires parking_area_m2 of land. Notes are irrelevant. + +Write `answer.json` as one JSON object. Round numbers to 2 decimal places without rounding intermediate calculations; numbers are accepted within 0.01. `proposals` is keyed by proposal id. Each value has `unrounded_spaces` (the sum before ceiling), `required_spaces` (integer), `shortfall` (max(0, required minus provided), integer), and `required_parking_m2`. diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/solution/oracle.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..74217b1a085163bad2f08f64018f024d04ebc018 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent file-based planning review under the supplied fictional code.""" +import csv,json,math +from pathlib import Path + +def read(name): + with open(name) as f: return list(csv.DictReader(f)) +def solve(): + c=json.loads(Path('zoning_code.json').read_text()); out={} + if Path('proposals.csv').exists(): + for r in read('proposals.csv'): + area=float(r['width_m'])*float(r['depth_m']); far=float(r['gross_floor_m2'])/area; cov=float(r['footprint_m2'])/area + bad=[k for k,fail in [('far',far>c['max_far']),('coverage',cov>c['max_coverage']),('height',float(r['height_m'])>c['height_m']),('setback',any(float(r[k]) /logs/verifier/reward.txt diff --git a/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/tests/verify.py b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/zoning-check/zoning-check-mixed-use-d3-t0083/tests/verify.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +"""Verifier for Renaissance Labs practice environments. Standard library only. + +Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1]. +The reward is the weighted share of checks that pass. A missing, unreadable or non-object +answer scores 0. Each check addresses one value in the answer by a dotted path. + +Check types + int exact integer (a float with integral value is accepted; booleans are not) + number within abs_tol of value (default 1e-9); booleans and strings are rejected + str equal after trimming and case-folding + bool exact boolean + list ordered list; items compared as int/number/str according to "item" (default str) + set unordered collection of distinct strings (or ints) + custom a function in validators.py: name(answer, args) -> bool or float in [0, 1] +""" +import argparse, json, math, os, sys + +MISSING = object() + +def lookup(obj, path): + cur = obj + for part in path.split("."): + if isinstance(cur, dict): + if part not in cur: return MISSING + cur = cur[part] + elif isinstance(cur, list): + try: cur = cur[int(part)] + except (ValueError, IndexError): return MISSING + else: + return MISSING + return cur + +def is_num(x): + return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x))) + +def eq_int(got, want): + return is_num(got) and float(got) == float(int(got)) and int(got) == want + +def eq_num(got, want, tol): + return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12 + +def eq_str(got, want): + return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold() + +def eq_item(got, want, kind, tol): + if kind == "int": return eq_int(got, want) + if kind == "number": return eq_num(got, want, tol) + return eq_str(got, want) + +def run_check(answer, chk, validators): + t = chk["type"] + if t == "custom": + fn = getattr(validators, chk["name"], None) if validators else None + if fn is None: return 0.0 + try: r = fn(answer, chk.get("args", {})) + except Exception: return 0.0 + if r is True: return 1.0 + if r is False or r is None: return 0.0 + return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0 + got = lookup(answer, chk["path"]) + if got is MISSING: return 0.0 + want, tol = chk["value"], chk.get("abs_tol", 1e-9) + if t == "int": ok = eq_int(got, want) + elif t == "number": ok = eq_num(got, want, tol) + elif t == "str": ok = eq_str(got, want) + elif t == "bool": ok = isinstance(got, bool) and got is want + elif t == "list": + ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want)) + elif t == "set": + kind = chk.get("item", "str") + if not isinstance(got, list): ok = False + else: + norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None) + g = [norm(x) for x in got]; w = [norm(x) for x in want] + ok = None not in g and len(g) == len(set(g)) and set(g) == set(w) + else: ok = False + return 1.0 if ok else 0.0 + +def grade(answer, checks, validators=None): + """Return (reward, details). answer is the parsed JSON, or None if it could not be read.""" + if not isinstance(answer, dict): + return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks] + total = sum(c.get("weight", 1.0) for c in checks) + got, details = 0.0, [] + for c in checks: + s = run_check(answer, c, validators) + got += s * c.get("weight", 1.0) + details.append({"check": c.get("path", c.get("name")), "score": s}) + return (round(got / total, 6) if total else 0.0), details + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--answer", default="/app/answer.json") + ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json")) + ap.add_argument("--out", default="/logs/verifier") + a = ap.parse_args() + checks = json.load(open(a.checks)) + try: + with open(a.answer) as f: answer = json.load(f) + except Exception: + answer = None + validators = None + here = os.path.dirname(os.path.abspath(__file__)) + if os.path.exists(os.path.join(here, "validators.py")): + sys.path.insert(0, here) + import validators # noqa + reward, details = grade(answer, checks, validators) + os.makedirs(a.out, exist_ok=True) + with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward)) + with open(os.path.join(a.out, "reward.json"), "w") as f: + json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f) + print("reward", reward) + +if __name__ == "__main__": + main()