diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..b54d8894cf7cf26ad684fa95f29515c9eb28f55a --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,3000,161,45,g/L,planned,nursery stock +T01,2500,184,74,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bd54117babae6ef195f13985d19f3ec755c7a76c --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10000 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..de29244632146272b4b84d4e0089629421109b9b --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 483.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 10.733, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2989.267, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 279.503, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 460.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 6.216, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2493.784, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 402.174, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d1-e0009/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..46aa3c1ff7f72143a7443e5140e7349e2d2a79f6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,3600,64,29,g/L,planned,nursery stock +T01,1600,197,76,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d35c90b44e186c417f33571f8d623d9986efd32f --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10009 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..681c023f3824161b3c08edb82777ea76bf7ca6cf --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 230.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 7.945, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3592.055, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 453.125, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 315.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 4.147, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 1595.853, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 385.787, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-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/grower-desk/grower-desk-fertigation-d1-e0018/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..32992ed92a64b83fb7e3e07668406cfdd7a0919f --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,3700,103,61,g/L,planned,nursery stock +T01,4000,171,45,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..30e3dae678a02cf842faa4b5a5d3a654545fb858 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10018 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..89d3c12db73a68dfea71e1a9d2b10953fcf9dba3 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 381.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 6.248, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3693.752, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 592.233, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 684.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 15.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3984.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 263.158, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-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/grower-desk/grower-desk-fertigation-d1-t0000/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..5f8cf8fc113f1893fa31416306a3eb22f73958cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,1500,111,60,g/L,planned,nursery stock +T01,3100,95,43,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3e4967154fbf3c3c472e3525a421b148c78872da --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 0 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f64ff7077bb2be697c7aeb00d2144bbfd35ca75a --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 166.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 2.775, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1497.225, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 540.541, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 294.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 6.849, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3093.151, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 452.632, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d1-t0009/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..959310bc64905cd3f78d1eec5b2bf294852bbefa --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,3000,199,76,g/L,planned,nursery stock +T01,2200,80,44,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f1997e84ba40224308fa77e7e77b782de14847eb --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 9 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6c617dedf4faba582382253823585007f1d30b1e --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 597.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 7.855, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2992.145, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 381.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 176.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 4.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2196.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 550.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-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/grower-desk/grower-desk-fertigation-d1-t0018/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..7d389d5961dccd47f8efa6007c6cd38e06638aef --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2000,193,26,g/L,planned,nursery stock +T01,2600,188,38,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9c604b0b849c84d09ad347605a77473bd26cf1e6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 18 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ab68c2ecc3a186495a6f2d2f5500615b16849e73 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 386.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 14.846, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1985.154, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 134.715, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 488.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 12.863, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2587.137, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 202.128, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-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/grower-desk/grower-desk-fertigation-d1-t0027/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..4d856a67a53b1f70a6134032fa3bb477c797b6ac --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2700,111,47,g/L,planned,nursery stock +T01,1000,56,67,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..34391ec39bf90a57dd79dc470b0348485faa38bb --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 27 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..35c3e83c49b65812e7172e75ab9bc7fed76c0e4f --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 299.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 6.377, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2693.623, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 423.423, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 56.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 0.836, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 999.164, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 1196.429, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0027/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d1-t0036/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..5d61bb6e6a8adae215798509bcfd75c22e799854 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,3400,183,52,g/L,planned,nursery stock +T01,3500,168,25,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..03713edd9ef0e081ac7215ed33bff886d411fbcd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 36 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..75a10fcda43db0b6fdc0d8e84c96244162f83ce2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 622.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 11.965, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3388.035, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 284.153, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 588.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 23.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3476.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 148.81, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0036/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d1-t0045/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..4906a61441fd0122dd169c5686d4b482bebe28c4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2300,134,79,g/L,planned,nursery stock +T01,2500,89,55,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8bd09424faa4da0a97aa2c1c66a82ad4a20e1968 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 45 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..39665f35042c776983f75b30d26b017c29fdb077 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 308.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 3.901, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2296.099, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 589.552, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 222.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 4.045, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2495.955, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 617.978, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0045/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-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/grower-desk/grower-desk-fertigation-d1-t0054/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..bac7962684ceba2bd14e63ef0d0071864fb1817f --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2100,182,60,g/L,planned,nursery stock +T01,2700,105,65,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0ced10f0ff028a186a74cde189f25bf14bc9cb54 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 54 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..31c667fdb4a57caf723d172bba84aae525fd3768 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 382.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 6.37, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2093.63, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 329.67, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 283.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 4.362, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2695.638, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 619.048, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0054/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-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/grower-desk/grower-desk-fertigation-d1-t0063/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..daf687d366cfef797d2e9d2c4b5ba498a22e9f47 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,1000,78,55,g/L,planned,nursery stock +T01,2700,151,26,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bf47715fba4c5470ddc14ad4ccd6c33300c6236b --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 63 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0a00ce937ba12fa8dbbdb3310b7ee610303dcc44 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 78.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 1.418, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 998.582, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 705.128, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 407.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 15.681, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2684.319, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 172.185, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0063/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d1-t0072/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..df81e14e75a96fc438e506b087c5d67e48393137 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,1000,111,20,g/L,planned,nursery stock +T01,2000,103,46,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..adefc8ca7aed3cdec12764117048d9fcba56d79b --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 72 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9e99605228add9559f0647b5c7724287de385bdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 111.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 5.55, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 994.45, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 180.18, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 206.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 4.478, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 1995.522, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 446.602, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0072/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d1-t0081/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..e359df26960c2b3851a197cbad6c89c40fce23f0 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/environment/workdir/fertigation.csv @@ -0,0 +1,3 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2500,120,63,g/L,planned,nursery stock +T01,3800,162,35,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/task.toml b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e51475c05a522a98e25ec2f45fc58f6b070630e6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 81 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d55e5bb205482858e8e71db292f480adfe5b93ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 300.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 4.762, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2495.238, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 525.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 615.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 17.589, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3782.411, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 216.049, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d1-t0081/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d1-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/grower-desk/grower-desk-fertigation-d2-e0003/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..34da4db50b5f8b2269900e45112fb3d950ecd4f1 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T02,3400,145,58,g/L,planned,nursery stock +TRIAL,99999,76,78,g/L,trial,nursery stock +T00,3200,76,78,g/L,planned,nursery stock +T01,1500,165,22,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1fc3a4401de577ab82299655858acde68bcc12ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10003 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7722dddb715ae679295a4da5f75fddd9cb5ad907 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 243.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 3.118, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3196.882, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 1026.316, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 247.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 11.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 1488.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 133.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 493.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 8.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 3391.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 400.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-e0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-e0012/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..50ef611d2983e6fbf22644f4a3f38bb146a4f5da --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T01,2200,175,53,g/L,planned,nursery stock +T02,2700,135,64,g/L,planned,nursery stock +TRIAL,99999,85,47,g/L,trial,nursery stock +T00,1900,85,47,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f166fac485dd330e4b250e95d3a8b326f1176e3e --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10012 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6726570b3a77bd10b69a481cc3797770bc60e5be --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 161.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 3.436, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1896.564, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 552.941, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 385.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 7.264, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2192.736, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 302.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 364.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 5.695, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2694.305, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 474.074, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-e0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-e0021/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..1c74f9a4dc3420956be1bb774239e2d854e5b5a3 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,3500,196,37,g/L,planned,nursery stock +T01,3400,126,39,g/L,planned,nursery stock +T02,3000,97,40,g/L,planned,nursery stock +TRIAL,99999,196,37,g/L,trial,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..50114fee3ca9edd06f72846066395db970d63755 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10021 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..00c17e55466e5f39ef3733c7a234a6130c0dd19a --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 686.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 18.541, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3481.459, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 188.776, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 428.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 10.985, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3389.015, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 309.524, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 291.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 7.275, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2992.725, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 412.371, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-e0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-t0003/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..5e79b15ba65e2c11759ec31f3b4b58ffdfabd2d6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T01,2200,144,28,g/L,planned,nursery stock +T00,2000,152,41,g/L,planned,nursery stock +T02,3700,102,53,g/L,planned,nursery stock +TRIAL,99999,152,41,g/L,trial,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..497bb8264dc5c521d04bba752509051b10648007 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 3 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cbb3abe0dc6d49674ca77fd5c6c0066a3d5836f6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 304.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 7.415, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1992.585, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 269.737, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 316.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 11.314, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2188.686, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 194.444, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 377.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 7.121, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 3692.879, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 519.608, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-t0012/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..c4538c97f9e2dd186699785aa51a36da9aa674fe --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2100,50,27,g/L,planned,nursery stock +T01,2700,139,34,g/L,planned,nursery stock +T02,2700,136,53,g/L,planned,nursery stock +TRIAL,99999,50,27,g/L,trial,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..350fbc202be999f3d8161d637b10b38272f81b17 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 12 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f8de061feb108df53e882f915bd433c1d590151e --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 105.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 3.889, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2096.111, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 540.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 375.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 11.038, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2688.962, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 244.604, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 367.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 6.928, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2693.072, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 389.706, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-t0021/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..fd06e880fabba98660d8bcb32b5568aac433615a --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +TRIAL,99999,143,62,g/L,trial,nursery stock +T00,4000,143,62,g/L,planned,nursery stock +T01,2200,79,30,g/L,planned,nursery stock +T02,2400,57,38,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5cf69cf583ab833d11cdd01d98d1f209c537998b --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 21 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4ea0a281da9dc5eea261331a24769ae65266642e --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 572.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 9.226, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3990.774, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 433.566, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 173.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 5.793, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2194.207, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 379.747, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 136.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 3.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2396.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 666.667, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-t0030/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..55b08c2dce085e3b83cc03e92abfb66c2ada0198 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T02,3000,200,66,g/L,planned,nursery stock +TRIAL,99999,177,21,g/L,trial,nursery stock +T00,2600,177,21,g/L,planned,nursery stock +T01,3100,138,32,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9c4bb9ed7a78a37e37dcb70012b2a94bc85159eb --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 30 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7c6731e54159500132a2da092f59bc84fdcd5c83 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 460.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 21.914, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2578.086, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 118.644, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 427.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 13.369, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3086.631, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 231.884, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 600.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 9.091, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2990.909, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 330.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0030/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d2-t0039/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..cf2924fc5fce6ad57802440b931ac7d4b171c056 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2300,194,37,g/L,planned,nursery stock +T02,2300,184,63,g/L,planned,nursery stock +T01,2000,55,51,g/L,planned,nursery stock +TRIAL,99999,194,37,g/L,trial,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..32a7bd8523c150600bfdc64176c241b13a192b4d --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 39 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f06827fc4cbf40b6a4890929d180e49616b78837 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 446.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 12.059, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2287.941, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 190.722, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 110.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 2.157, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 1997.843, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 927.273, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 423.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 6.717, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2293.283, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 342.391, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0039/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-t0048/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..8d2fd689632601b2d15395e5c9172632275aa68f --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T02,3400,199,23,g/L,planned,nursery stock +T01,3400,90,25,g/L,planned,nursery stock +T00,2000,167,33,g/L,planned,nursery stock +TRIAL,99999,167,33,g/L,trial,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..77882388c057d1853bc11bab137b7e9aebfe2bd8 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 48 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8517d506eaa6a73c6fcb3b85684369f220315472 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 334.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 10.121, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1989.879, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 197.605, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 306.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 12.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3387.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 277.778, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 676.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 29.417, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 3370.583, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 115.578, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0048/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-t0057/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..b99133b117ed1b939b8629befff1cf654d450a6b --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,1600,199,59,g/L,planned,nursery stock +T02,1100,60,52,g/L,planned,nursery stock +TRIAL,99999,199,59,g/L,trial,nursery stock +T01,2700,143,28,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..87474fa7ef7675ca7f9d51c19632a447b3c5c974 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 57 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..183b3c594748ddcbff80e11f91f56983e69bad49 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 318.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 5.397, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1594.603, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 296.482, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 386.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 13.789, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2686.211, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 195.804, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 66.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 1.269, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 1098.731, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 866.667, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0057/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d2-t0066/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..390602f0737bc4f2dbdf9f9c53ededfa3b2260bb --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,1300,106,53,g/L,planned,nursery stock +T02,1400,93,23,g/L,planned,nursery stock +TRIAL,99999,106,53,g/L,trial,nursery stock +T01,1800,119,39,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5fe10ea4f94084c774f32d55a0f840f34be90c7b --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 66 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0c0b859eb7d68a026c8ec25f22129a1d172db60e --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 137.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 2.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1297.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 500.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 214.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 5.492, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 1794.508, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 327.731, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 130.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 5.661, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 1394.339, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 247.312, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0066/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d2-t0075/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..f2fa093e55862cb4f4b831bb143df5a0c8e2c3cb --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/environment/workdir/fertigation.csv @@ -0,0 +1,5 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T01,3000,107,39,g/L,planned,nursery stock +TRIAL,99999,144,61,g/L,trial,nursery stock +T00,2100,144,61,g/L,planned,nursery stock +T02,3000,99,76,g/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b9432b3a26b0ac22df7b985139bd74b1245158e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/task.toml b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a87a978b79c123258883877953484744647fc3ea --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 75 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3600e2b1958428da39c56a91c3f17fa76811a5ea --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 302.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 4.957, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2095.043, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 423.611, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 321.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 8.231, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2991.769, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 364.486, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 297.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 3.908, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2996.092, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 767.677, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d2-t0075/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d2-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/grower-desk/grower-desk-fertigation-d3-e0006/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..32796876fece338fd5cdf72e02762f49efcedef1 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2900,66,45000,mg/L,planned,nursery stock +T01,3800,149,44000,mg/L,planned,nursery stock +T03,2800,143,70000,mg/L,planned,nursery stock +TRIAL,99999,66,45000,mg/L,trial,nursery stock +T02,2500,118,20000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a3f9a4860706493b6ed217a5b8289bebdd95f216 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10006 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8807b952a09f8e9d9d81df97a2efe94aa711da8c --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 191.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 4.253, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2895.747, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 681.818, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 566.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 12.868, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3787.132, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 295.302, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 295.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 14.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2485.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 169.492, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 400.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 5.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 2794.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 489.51, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1453.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-e0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-e0015/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..a25c010cc9405f927bf6e0c381033126f7f6dddc --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +TRIAL,99999,72,80000,mg/L,trial,nursery stock +T01,4000,158,61000,mg/L,planned,nursery stock +T02,1500,84,75000,mg/L,planned,nursery stock +T00,2400,72,80000,mg/L,planned,nursery stock +T03,1800,137,68000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..624ca287b1473f73196a983e1d63d8d82946caaa --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "eval"] +isced_f = "0812" +family = "fertigation" +split = "eval" +seed = 10015 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b515a907ba0df4bc280f78d57a7e77f815842faa --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 172.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 2.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2397.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 1111.111, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 632.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 10.361, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3989.639, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 386.076, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 126.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 1.68, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 1498.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 892.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 246.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 3.626, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 1796.374, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 496.35, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1177.4, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-e0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-t0006/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..566aa698a01a2ad2594362c90bf85535474dd266 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T01,2900,177,24000,mg/L,planned,nursery stock +T02,3700,200,58000,mg/L,planned,nursery stock +TRIAL,99999,152,52000,mg/L,trial,nursery stock +T03,2000,131,34000,mg/L,planned,nursery stock +T00,2100,152,52000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..49eb722cfaf2a6aba41aae7890c7de1833309bfa --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..30f53317146fef7e8014456246bdcead3794cfd8 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 319.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 6.138, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2093.862, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 342.105, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 513.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 21.387, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2878.613, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 135.593, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 740.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 12.759, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 3687.241, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 290.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 262.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 7.706, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 1992.294, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 259.542, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1834.5, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-t0015/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..2b6f91c508ad4d7c794d5ace9d247d4c6f4ef02b --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T03,2300,148,32000,mg/L,planned,nursery stock +T00,1600,188,49000,mg/L,planned,nursery stock +T01,3500,146,74000,mg/L,planned,nursery stock +TRIAL,99999,188,49000,mg/L,trial,nursery stock +T02,2300,125,75000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bbce5a819cb5990eec10eda3bde8b36aa93f0c07 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 15 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9b3114ed3b4f589a04ff79e34d897654e8027db5 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 300.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 6.139, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1593.861, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 260.638, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 511.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 6.905, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3493.095, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 506.849, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 287.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 3.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2296.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 600.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 340.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 10.637, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 2289.363, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 216.216, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1439.7, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-t0024/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..f44aea096c31624c3dae84f2f56e1b31d3908197 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T02,4000,98,37000,mg/L,planned,nursery stock +T00,3100,115,39000,mg/L,planned,nursery stock +TRIAL,99999,115,39000,mg/L,trial,nursery stock +T03,3900,86,30000,mg/L,planned,nursery stock +T01,2000,156,27000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b68c133c9e453bc95531f98ae776f28f6dbbfdb6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 24 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7038ffb08299597f9d6274c039de32fd11a9a4c6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 356.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 9.141, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3090.859, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 339.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 312.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 11.556, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 1988.444, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 173.077, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 392.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 10.595, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 3989.405, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 377.551, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 335.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 11.18, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 3888.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 348.837, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1395.9, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0024/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-t0033/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..b607626cefba306200480e8b76932810f014ad04 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T03,2800,150,80000,mg/L,planned,nursery stock +T01,2900,81,47000,mg/L,planned,nursery stock +T00,3700,156,65000,mg/L,planned,nursery stock +T02,2400,193,52000,mg/L,planned,nursery stock +TRIAL,99999,156,65000,mg/L,trial,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..019203440822e0728996c5b9a982a8542421d7bf --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 33 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..33aeee551d71490d590dfe2232cb9aadb9652984 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 577.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 8.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3691.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 416.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 234.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 4.998, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2895.002, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 580.247, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 463.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 8.908, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2391.092, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 269.43, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 420.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 5.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 2794.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 533.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1695.3, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0033/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d3-t0042/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..c895bf7297f45dde0e07ce87903e0f4fdc707364 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T01,2200,143,28000,mg/L,planned,nursery stock +TRIAL,99999,196,77000,mg/L,trial,nursery stock +T03,1300,103,31000,mg/L,planned,nursery stock +T02,2100,150,77000,mg/L,planned,nursery stock +T00,1200,196,77000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a4172a6d5c31785a7ff3aca1f76561e872edbdac --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 42 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..18c6e8366ebb2fad1c61b6f327682d84e517afe9 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 235.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 3.055, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 1196.945, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 392.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 314.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 11.236, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2188.764, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 195.804, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 315.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 4.091, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2095.909, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 513.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 133.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 4.319, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 1295.681, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 300.971, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 998.7, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0042/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-t0051/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..e1d3661bb5ddcb550cd61ef83ab13195836672b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T03,3000,196,39000,mg/L,planned,nursery stock +T02,2200,157,53000,mg/L,planned,nursery stock +TRIAL,99999,65,34000,mg/L,trial,nursery stock +T00,2200,65,34000,mg/L,planned,nursery stock +T01,2600,52,71000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e27a86d36f6b02dac0dd6719340c62caa1178a1e --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 51 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..808f0aa66f187515ad0c50274b7bcb3f78e663fa --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 143.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 4.206, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2195.794, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 523.077, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 135.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 1.904, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 2598.096, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 1365.385, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 345.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 6.517, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 2193.483, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 337.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 588.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 15.077, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 2984.923, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 198.98, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1211.6, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0051/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-t0060/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..27ba0a2351d52c0cd413f2c01a856ae91cadea0f --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T03,2600,65,31000,mg/L,planned,nursery stock +T02,1400,146,47000,mg/L,planned,nursery stock +T00,4000,90,39000,mg/L,planned,nursery stock +TRIAL,99999,90,39000,mg/L,trial,nursery stock +T01,3100,136,36000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7f16d02d468fe8af441b86ba9895914f0a4031d3 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 60 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..83bf45930dd585f215b43001a502c37b863effec --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 360.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 9.231, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3990.769, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 433.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 421.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 11.711, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3088.289, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 264.706, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 204.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 4.349, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 1395.651, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 321.918, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 169.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 5.452, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 2594.548, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 476.923, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1155.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0060/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-fertigation-d3-t0069/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..5189a26be4a41302d71cb020cccbeb609de9df2d --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,2100,147,74000,mg/L,planned,nursery stock +TRIAL,99999,147,74000,mg/L,trial,nursery stock +T03,2100,156,74000,mg/L,planned,nursery stock +T01,3400,126,73000,mg/L,planned,nursery stock +T02,1500,197,59000,mg/L,planned,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..68b49d0e8557d2e171852d3ee1c1300389af1af5 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 69 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..aa66c646d4fcd333ae172ad3268590273c2dd1aa --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 308.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 4.172, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 2095.828, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 503.401, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 428.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 5.868, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3394.132, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 579.365, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 295.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 5.008, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 1494.992, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 299.492, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 327.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 4.427, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 2095.573, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 474.359, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1360.2, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0069/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-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/grower-desk/grower-desk-fertigation-d3-t0078/environment/Dockerfile b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/environment/workdir/fertigation.csv b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/environment/workdir/fertigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..6225e44124110e9e6f929f86ae5571f483a75b6d --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/environment/workdir/fertigation.csv @@ -0,0 +1,6 @@ +tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop +T00,3200,71,32000,mg/L,planned,nursery stock +T01,4000,90,61000,mg/L,planned,nursery stock +T02,1800,81,33000,mg/L,planned,nursery stock +T03,1000,110,24000,mg/L,planned,nursery stock +TRIAL,99999,71,32000,mg/L,trial,nursery stock diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/instruction.md b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e7105e32b5ed321d3fd5e2fea421c11a2bbd8c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: fertigation + +`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `nutrient_g` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/solution/oracle.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/solution/solve.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/task.toml b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1792095d93e4579abb865df97a8001035632d8dc --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "fertigation", "isced-0812", "train"] +isced_f = "0812" +family = "fertigation" +split = "train" +seed = 78 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/checks.json b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ddf7c0bbd7f6442dbf7998d06061d503c7d975e4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.T00.nutrient_g", + "type": "number", + "value": 227.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.stock_l", + "type": "number", + "value": 7.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.makeup_water_l", + "type": "number", + "value": 3192.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T00.dilution_factor", + "type": "number", + "value": 450.704, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.nutrient_g", + "type": "number", + "value": 360.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.stock_l", + "type": "number", + "value": 5.902, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.makeup_water_l", + "type": "number", + "value": 3994.098, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T01.dilution_factor", + "type": "number", + "value": 677.778, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.nutrient_g", + "type": "number", + "value": 145.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.stock_l", + "type": "number", + "value": 4.418, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.makeup_water_l", + "type": "number", + "value": 1795.582, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T02.dilution_factor", + "type": "number", + "value": 407.407, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.nutrient_g", + "type": "number", + "value": 110.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.stock_l", + "type": "number", + "value": 4.583, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.makeup_water_l", + "type": "number", + "value": 995.417, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.T03.dilution_factor", + "type": "number", + "value": 218.182, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 843.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/test.sh b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/verify.py b/tasks/grower-desk/grower-desk-fertigation-d3-t0078/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-fertigation-d3-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/grower-desk/grower-desk-irrigation-d1-e0001/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..4b607e50073ed70fece5a5ac4161d744e80fc762 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,6.5,0.8,0,1100,m2,0.6,15,planned +Z01,3.1,0.8,0,3200,m2,0.8,8,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..56aea93829d91d8476808cbd149a770dc1e15a30 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10001 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ec37f1c8b8a49097f4da303c5d73b36af1a8dd01 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 5.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 8.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 9.533, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.636, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 2.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 2.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 3.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 9.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 1.24, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-e0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d1-e0010/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..81d81077eab8619a61df2f7c264ca699efe2a483 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,5.9,1.1,0,6200,m2,0.9,7,planned +Z01,5.0,0.8,0,4700,m2,0.6,6,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f3a90e5e3bd7135cbfbe5f9c25fefa67b11da0d0 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10010 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5f2f22cf8b899d1747938944a23cff92eccd6a91 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 6.49, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 6.49, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 7.211, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 44.709, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 6.387, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 31.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 5.222, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-e0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-e0019/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..2ef06d7d9909b4b8ba4fe6f3b68f15eedc86d138 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,4.6,1.0,0,3900,m2,0.6,11,planned +Z01,5.7,0.8,0,6000,m2,0.6,11,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8edad69f3320272d3b14190e885ac447caca1bcb --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10019 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ecce09e2d2cc794305263a6aff3c984555042806 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 4.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 7.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 29.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 2.718, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 7.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 45.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 4.145, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-e0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-t0001/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..19cb274d21d6eeae99da672c83376992249f0617 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,3.4,1.0,0,7700,m2,0.75,8,planned +Z01,4.4,1.0,0,4200,m2,0.6,14,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7b67319cacf69b78a4a82f2eea68e6611b617e70 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 1 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0a388c6674785a06befc793585f44b63e6dc8d93 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 3.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 4.533, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 34.907, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 4.363, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 7.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 30.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.2, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d1-t0010/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..1df56fba24528cce000629c1f2b39d00271f2497 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,4.9,1.2,0,2200,m2,0.75,13,planned +Z01,3.6,0.9,0,5800,m2,0.9,4,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c4317a2220a14d0374ba467450042a76a99aed3c --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 10 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..840c7178c9d70c2558fb9879f845226fbbecc845 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 5.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 7.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 17.248, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.327, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 3.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 3.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 20.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 5.22, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-t0019/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..55658450385acc6f294984aac7fccc4a0ecacd1d --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,6.4,0.9,0,5700,m2,0.9,15,planned +Z01,3.8,1.0,0,6400,m2,0.75,10,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..363d2c0ea3fa551f92c215d11d0b9c35f49f1b42 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 19 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3f4fb60763abe1676313b0888d96300c5493765f --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 5.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 6.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 36.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 2.432, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 3.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 5.067, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 32.427, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 3.243, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-t0028/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..9b7d3060a69e7cffc44c1cae6942288916aa0580 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,6.4,0.7,0,3600,m2,0.6,8,planned +Z01,6.5,1.1,0,6800,m2,0.9,14,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b8b5f624f83f3307ce88268805e4a08ee2988190 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 28 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..739a9e9a4a882d4cc852e7039ff756b69e4c635b --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 4.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 7.467, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 26.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 3.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 7.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 7.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 7.944, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 54.022, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 3.859, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0028/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-t0037/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..6be5568d9fec34420a4c900834a8d718f063cfc9 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,4.1,0.8,0,7200,m2,0.75,15,planned +Z01,3.0,1.1,0,7000,m2,0.6,14,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..62c4cc89d2687b752963607966d30fb370912d22 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 37 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..53da7c91c5d96f56406acbe52c9652ca22dc00f4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 3.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 4.373, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 31.488, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 2.099, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 3.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 5.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 38.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.75, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0037/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d1-t0046/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..e1b4577ff03e0ba74685568cec66735527abdfa5 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,5.6,1.2,0,6100,m2,0.9,9,planned +Z01,5.4,0.9,0,3900,m2,0.8,8,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5ebb94a8c9754d9c7d16d6abfe5406bfaa34e716 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 46 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..138dd9ebe02d2c115d8b55a99ef272a920714a13 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 6.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 6.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 7.467, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 45.547, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 5.061, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.86, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.86, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.075, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 23.692, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.962, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0046/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-t0055/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..69b75021278a7aa16f48a0e87e589990ec3a35b1 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,3.8,0.8,0,4200,m2,0.9,12,planned +Z01,6.1,0.9,0,4400,m2,0.8,15,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..78b167ea140022ae16f02f91ebba75fc293ea62a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 55 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..38bd318ba720b3c9497c99eb9e610aa43fc1918f --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 3.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 3.378, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 14.187, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.182, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 5.49, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 5.49, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.862, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 30.195, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.013, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0055/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-t0064/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..3a7db3b14ed12c03049a017bd696fed91273a0b9 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,3.6,0.8,0,2400,m2,0.6,11,planned +Z01,5.0,0.8,0,5600,m2,0.6,8,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7c31da4d6037dbee2f84b547ad360964560d0786 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 64 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3bda1825d6ab0dc939574b2977cde2b54ceb198a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 2.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 2.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 4.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 11.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.047, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 37.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 4.667, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0064/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d1-t0073/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..da6f22c6651aa0d4cdb234f661459d30be4ca763 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,5.5,1.2,0,5200,m2,0.6,7,planned +Z01,3.1,1.0,0,7600,m2,0.8,10,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0e78160c730bc87cb484b29b02c12826cd09d4ea --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 73 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..baaf50b3635b420340b0f4f406a5fdb35f2d32fc --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 6.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 6.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 11.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 57.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 8.171, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 3.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 3.875, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 29.45, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.945, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0073/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d1-t0082/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..eaee2d830136e5f198d160a4dd51e2a7a130bf2a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/environment/workdir/irrigation.csv @@ -0,0 +1,3 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,5.6,0.8,0,2500,m2,0.6,9,planned +Z01,4.9,1.2,0,7400,m2,0.9,12,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/task.toml b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4e2299c7c04b99ede8211048a0d52ede82b7361e --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 82 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5efd2c19977fb777a7bd446e9d2f9840a583d427 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 4.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 7.467, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 18.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 2.074, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 5.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 5.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.533, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 48.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 4.029, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d1-t0082/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d1-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/grower-desk/grower-desk-irrigation-d2-e0004/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..f7d5a70c7eb4eafc020279cf5fbfd52ff6426c4c --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +CLOSED,4.2,1.1,8,99999,m2,0.75,7,closed +Z02,6.3,1.1,2,2200,m2,0.6,14,planned +Z00,4.2,1.1,8,7900,m2,0.75,7,planned +Z01,5.9,0.7,1,6100,m2,0.9,14,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2a83ff5d39f91aa8264753da19a8c29b955636e4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10004 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b47ccf16988020bff16d9e3351affa9166b3011b --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.62, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 3.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 3.478, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 21.214, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 1.515, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 6.93, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 4.93, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 8.217, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 18.077, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.291, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-e0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d2-e0013/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..ff5f0998d168eeefa065121349962c3005770b11 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z01,6.3,0.9,1,3000,m2,0.8,8,planned +Z00,3.5,1.1,2,6100,m2,0.75,13,planned +CLOSED,3.5,1.1,2,99999,m2,0.75,13,closed +Z02,3.1,0.7,2,4000,m2,0.6,15,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dc222002b6144ef660c0a9439dad04ababd9b9d9 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10013 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4b9f06ddfb3d67792b9c0e185a2456968180104c --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.85, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 1.85, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 2.467, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 15.047, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.157, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 5.67, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.67, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 5.837, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 17.512, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.189, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 2.17, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 0.17, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 0.283, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 1.133, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 0.076, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-e0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-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/grower-desk/grower-desk-irrigation-d2-e0022/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..c17fc47e6a54f43d5fe23b0342457818466ed0b2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,5.6,1.1,8,4800,m2,0.75,14,planned +Z01,5.0,0.9,1,6700,m2,0.6,8,planned +Z02,5.2,0.8,1,5300,m2,0.8,15,planned +CLOSED,5.6,1.1,8,99999,m2,0.75,14,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..92b9337bf9cbb5652811387a9172940c9251004f --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10022 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..988717a16e44edcc60f62ccdd34e0f34d5ff321c --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 6.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 3.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 5.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 39.083, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 4.885, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 4.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 3.95, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 20.935, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.396, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-e0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-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/grower-desk/grower-desk-irrigation-d2-t0004/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..708f624713660d7eb99272d4166beb1319d8756a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z01,3.6,1.0,8,6900,m2,0.8,6,planned +Z02,5.8,1.1,8,7700,m2,0.75,12,planned +Z00,6.3,0.7,1,3000,m2,0.6,10,planned +CLOSED,6.3,0.7,1,99999,m2,0.6,10,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..abae7433113e6e82cad86a66133941cb2445e28a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 4 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7d7489eee96ecc41d97e560f0e2a71f9c7e1442d --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.41, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 3.41, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 5.683, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 17.05, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.705, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 6.38, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d2-t0013/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..2f44561c669386193c78283c1b943dc04f7758ba --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z01,6.4,1.0,2,4500,m2,0.6,12,planned +Z00,4.2,0.8,8,5900,m2,0.75,15,planned +Z02,6.1,1.2,0,1100,m2,0.8,9,planned +CLOSED,4.2,0.8,8,99999,m2,0.75,15,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4456f914482afeb483d4dc844df13ac58c02e74d --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 13 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..32a2788ee8bf55abcf311792246058176d31eb0b --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 6.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 7.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 33.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 7.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 7.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 9.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 10.065, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.118, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-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/grower-desk/grower-desk-irrigation-d2-t0022/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..7aa5c90694f79549b100cdda11071efb496dedaa --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,6.4,0.7,8,2700,m2,0.9,15,planned +Z01,4.1,0.8,8,8000,m2,0.75,13,planned +Z02,3.0,1.1,0,7000,m2,0.75,9,planned +CLOSED,6.4,0.7,8,99999,m2,0.9,15,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b426ad1a70769f55d25dfc04381e044ce5a6fe79 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 22 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3793abd5981d17cabbaf3346da4fd7fc093849cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 3.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 4.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 30.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 3.422, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-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/grower-desk/grower-desk-irrigation-d2-t0031/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..c7199c8b734b3705dfc5b334759de05799178a0a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +CLOSED,3.5,1.1,1,99999,m2,0.8,7,closed +Z01,5.9,0.8,2,1300,m2,0.8,5,planned +Z00,3.5,1.1,1,7800,m2,0.8,7,planned +Z02,6.5,1.1,1,6500,m2,0.9,11,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1d7ae07b3cabae34c2c279ff6f05d3edef78592f --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 31 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..98c8ce16c7ece21936d71baee87f110e7416d5e0 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.85, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 2.85, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 3.563, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 27.788, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 3.97, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 2.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 3.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 4.42, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.884, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 7.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 6.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 6.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 44.417, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 4.038, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0031/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d2-t0040/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..593805e067c15527996fd26560d60eca1be462c5 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,3.6,0.8,8,1900,m2,0.6,10,planned +Z01,5.2,1.2,8,3500,m2,0.9,14,planned +Z02,5.7,0.9,2,5200,m2,0.75,10,planned +CLOSED,3.6,0.8,8,99999,m2,0.6,10,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5049976059ab52e6c31e9775b5113608f7ca4778 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 40 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5431877c75fc9c980e5ff385a0e59431c032f009 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 2.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 6.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 5.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 4.173, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 21.701, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 2.17, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0040/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d2-t0049/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..b2df8c4c4bba64b33895468244753ddd936d162d --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,5.2,1.0,1,1900,m2,0.75,7,planned +Z01,3.0,1.0,1,3000,m2,0.9,14,planned +Z02,4.3,1.0,2,6400,m2,0.75,15,planned +CLOSED,5.2,1.0,1,99999,m2,0.75,7,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d86737366c2c64dcc747a31b5041a2435ccc17ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 49 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..de4b2ffd415711e5fbc48f0adec0b9d06c335ce0 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 4.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 5.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 10.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 2.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 2.222, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 6.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.476, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 4.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 2.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 3.067, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 19.627, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.308, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0049/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-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/grower-desk/grower-desk-irrigation-d2-t0058/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..31a8405db29b29fec1693d32040f17349ab22df4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z01,3.0,0.8,8,3600,m2,0.75,9,planned +CLOSED,4.1,1.0,8,99999,m2,0.8,13,closed +Z02,4.1,1.0,1,7200,m2,0.6,5,planned +Z00,4.1,1.0,8,5700,m2,0.8,13,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..afdffb417b0c270ac3d1c70bae573efd055381e5 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 58 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..add0fb69d77e3867eb7b7a7a75cf5e959fdd7464 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 2.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 4.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 5.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 37.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 7.44, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0058/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-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/grower-desk/grower-desk-irrigation-d2-t0067/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..af2486641cfe74ff4565d8f8a085fe63a654b875 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z02,5.2,1.2,1,6800,m2,0.75,12,planned +Z00,6.1,1.0,8,3200,m2,0.9,15,planned +Z01,6.5,0.8,2,1700,m2,0.9,15,planned +CLOSED,6.1,1.0,8,99999,m2,0.9,15,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5668d405faa0b036ac46b35fa7708ea94eca7a17 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 67 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bdcc515c3eadbbeaba1d2ab920fe216dfbbf650e --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 6.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 5.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 3.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 3.556, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 6.044, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.403, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 6.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 5.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 6.987, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 47.509, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 3.959, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0067/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d2-t0076/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..f081eccc086559b5b1fbcb8e79fea7828c700d0b --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/environment/workdir/irrigation.csv @@ -0,0 +1,5 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z02,5.1,1.0,2,5900,m2,0.9,12,planned +CLOSED,5.2,0.8,0,99999,m2,0.6,10,closed +Z01,4.9,0.8,8,4900,m2,0.75,5,planned +Z00,5.2,0.8,0,1500,m2,0.6,10,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..46f7eb9d2d875cfcac3d0d45cc80df8cd79511b7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/task.toml b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..de7f1d5b5497c2ee1bd83f143aee1703f83509d8 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 76 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7b3059bd44d74777914e0c2d8025db36ccb92e8e --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 4.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 6.933, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 10.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 5.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 3.444, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 20.322, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.694, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d2-t0076/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d3-e0007/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..c47d583adae9106dc7cb28e64008ee2695123d63 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,4.8,1.2,2,0.54,ha,0.75,11,planned +Z03,3.4,1.1,0,0.11,ha,0.75,8,planned +Z02,4.2,0.9,0,0.23,ha,0.9,9,planned +CLOSED,4.8,1.2,2,99999,ha,0.75,11,closed +Z01,4.6,1.0,0,0.21,ha,0.9,7,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fd77f9b81c03e1e81b71ef46755e487f3c788e46 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10007 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..eefcf7a23d3f2a663c3da33d0608045beb3ca2c3 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 3.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 5.013, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 27.072, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 2.461, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 5.111, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 10.733, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 1.533, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 3.78, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.78, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 4.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 9.66, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.073, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 3.74, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 3.74, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 4.987, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 5.485, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.686, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 52.951, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-e0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-e0016/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..fc6d372629c5123e63785d076ec4840a5fc5be7d --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +CLOSED,4.4,0.9,8,99999,ha,0.8,10,closed +Z03,4.2,1.2,8,0.38,ha,0.8,10,planned +Z01,3.9,1.1,8,0.38,ha,0.6,7,planned +Z02,3.0,0.7,1,0.2,ha,0.8,9,planned +Z00,4.4,0.9,8,0.33,ha,0.8,10,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c4dddbf6748eefaf00bba6c3dd2fc0b00a83efd7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "eval"] +isced_f = "0812" +family = "irrigation" +split = "eval" +seed = 10016 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..606b053aa5960908ee13a6962c971af6f8a89cfc --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.29, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 2.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 1.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 1.375, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 2.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 0.306, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 5.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 2.75, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-e0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-t0007/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..dc88d8262c119ed8a3ab7f01c046fdb5f88a1ac5 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,3.2,1.0,0,0.8,ha,0.75,9,planned +Z01,5.5,1.2,2,0.42,ha,0.6,14,planned +CLOSED,3.2,1.0,0,99999,ha,0.75,9,closed +Z02,4.3,1.2,0,0.38,ha,0.75,13,planned +Z03,4.3,1.2,1,0.74,ha,0.75,7,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ff93f45f808bab78301aa479c9e10f6a4c2f2b23 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 7 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a89a5f2895b87f33f8700de6d3a0703d4b745d26 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 3.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 4.267, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 34.133, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 3.793, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 6.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 7.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 32.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 2.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 5.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 5.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 6.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 26.144, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 2.011, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 5.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 4.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 5.547, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 41.045, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 5.864, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 133.523, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-t0016/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..c16e403223857e8fd98d659174b1c7047ba1c0ea --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z02,5.6,1.0,0,0.45,ha,0.8,6,planned +Z01,3.7,1.1,0,0.67,ha,0.6,4,planned +CLOSED,6.3,1.2,8,99999,ha,0.8,11,closed +Z03,4.9,1.0,0,0.17,ha,0.8,12,planned +Z00,6.3,1.2,8,0.24,ha,0.8,11,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7a4f3e2e67f305d04e513cdabefc0858281d403e --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 16 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..367716dbaade80f3f8e97b4e4d3f9906e1eed3c7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 7.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.07, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 4.07, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.783, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 45.448, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 11.362, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 5.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 5.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 7.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 31.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 5.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 4.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 4.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 6.125, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 10.412, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.868, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 87.361, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-t0025/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..4a53d6f05350d6007ebd879c0b2461c330392469 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z02,3.6,0.8,0,0.58,ha,0.6,14,planned +Z03,5.2,1.1,0,0.17,ha,0.75,14,planned +Z01,6.2,0.9,0,0.46,ha,0.9,4,planned +Z00,3.7,0.7,2,0.58,ha,0.9,6,planned +CLOSED,3.7,0.7,2,99999,ha,0.9,6,closed diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e8b18e0c21ce32315b863c2d541fe857b6312b99 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 25 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..da07ff66b795c351122d48ccb62edd7dd584c79e --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 2.59, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.59, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.656, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 3.802, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.634, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 5.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 5.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 28.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 7.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 2.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 2.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 4.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 27.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.989, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 5.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 5.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 7.627, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 12.965, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.926, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 73.128, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0025/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-t0034/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..087ef2d1df5f2302790c986c2c2757dcdd72b933 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z01,5.1,0.8,8,0.22,ha,0.6,14,planned +Z00,5.7,0.9,1,0.28,ha,0.8,11,planned +Z02,5.0,1.1,0,0.7,ha,0.6,9,planned +CLOSED,5.7,0.9,1,99999,ha,0.8,11,closed +Z03,5.0,0.9,0,0.13,ha,0.6,12,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..752ef836ff686895a1961868bf77397389a0799f --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 34 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4b60501c74c6a87785687e4eb480feec884f21ee --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 4.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 5.162, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 14.455, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.314, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 5.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 5.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 9.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 64.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 7.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 4.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 4.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 7.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 9.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.812, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 88.372, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0034/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d3-t0043/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..20fef9cbb79ca70990ab04fcd7926a61c02ef79f --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z01,4.4,0.7,2,0.39,ha,0.8,8,planned +CLOSED,5.0,1.1,8,99999,ha,0.9,13,closed +Z02,3.8,1.2,2,0.47,ha,0.8,14,planned +Z03,6.4,0.9,1,0.69,ha,0.8,15,planned +Z00,5.0,1.1,8,0.6,ha,0.9,13,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2d568179b081c845e7221b784e5a5e7f9c051a66 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 43 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..14691ea0512de905aadce8debaac213021e455c6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 1.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 1.35, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 5.265, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.658, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 4.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 2.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 3.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 15.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.074, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 5.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 4.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 5.95, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 41.055, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 2.737, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 61.36, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0043/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-t0052/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..ef2ca823918dc9f4282d289f72b576b9606585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z03,5.1,0.7,2,0.78,ha,0.6,8,planned +Z02,3.4,1.1,0,0.42,ha,0.9,15,planned +Z01,3.4,0.9,8,0.36,ha,0.75,13,planned +CLOSED,6.2,0.9,0,99999,ha,0.8,12,closed +Z00,6.2,0.9,0,0.74,ha,0.8,12,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..449a3b3a8079446d5ed6a78c63bdc54fc916a73d --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 52 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..22bb02f893b10f821b2ea2f745d31e4097a05dc7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 5.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 5.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 6.975, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 51.615, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 4.301, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 3.06, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 3.74, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.74, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 4.156, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 17.453, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.164, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 3.57, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 1.57, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 2.617, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 20.41, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 2.551, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 89.478, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0052/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-t0061/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..f92b23470e3d4e10a08032e5943d89ef7cfe9049 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z02,3.4,0.9,0,0.53,ha,0.75,13,planned +Z03,4.4,1.1,8,0.2,ha,0.6,8,planned +CLOSED,6.1,0.7,2,99999,ha,0.8,13,closed +Z01,6.0,1.2,2,0.3,ha,0.75,12,planned +Z00,6.1,0.7,2,0.59,ha,0.8,13,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..caf41ed386c32924e1b53b7d20e52f41caea3027 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 61 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0b56911348d858ba1347622b370734bdd8bcc838 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.27, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 2.27, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 2.837, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 16.741, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.288, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 7.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 5.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 6.933, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 20.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 1.733, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 3.06, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 3.06, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 4.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 21.624, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 1.663, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 4.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 59.165, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0061/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-irrigation-d3-t0070/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..2ccfc3380dca2316303e3db8e8bc90a426d35128 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z00,3.1,1.2,2,0.8,ha,0.9,13,planned +Z03,4.0,1.2,8,0.55,ha,0.8,10,planned +CLOSED,3.1,1.2,2,99999,ha,0.9,13,closed +Z02,5.8,0.8,2,0.59,ha,0.6,12,planned +Z01,4.1,1.0,2,0.2,ha,0.75,14,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7ca6dd09b511cf1b2bdf7b764257144895da9dd2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 70 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..db6194b58d37710920cf8035468cfb6b818558e7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 3.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 1.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 1.911, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 15.289, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 1.176, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 2.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 2.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 5.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 4.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 2.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 4.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 25.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 2.163, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 4.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 46.849, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0070/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-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/grower-desk/grower-desk-irrigation-d3-t0079/environment/Dockerfile b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/environment/workdir/irrigation.csv b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/environment/workdir/irrigation.csv new file mode 100644 index 0000000000000000000000000000000000000000..fd4ad00f2eaba5358167365ec90e38753a2dc05a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/environment/workdir/irrigation.csv @@ -0,0 +1,6 @@ +zone_id,eto_mm,kc,effective_rain_mm,area,area_unit,application_efficiency,flow_m3_h,status +Z02,3.0,0.7,1,0.12,ha,0.75,6,planned +Z01,3.7,1.1,2,0.4,ha,0.9,11,planned +Z03,5.4,0.9,8,0.63,ha,0.6,4,planned +CLOSED,3.7,1.2,1,99999,ha,0.75,6,closed +Z00,3.7,1.2,1,0.1,ha,0.75,6,planned diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/instruction.md b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9a877d6ec4a7d340106d791d7aabb8b4bd7ea814 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: irrigation + +`irrigation.csv` gives a one-day water budget for nursery zones. Return per `zone_id`: `crop_et_mm` = eto_mm*kc, `net_mm` = max(0, crop ET - effective rainfall), `gross_mm` = net/application_efficiency (a fraction between 0 and 1), `water_m3` = gross mm*zone area in m2/1000, and `runtime_h` = water volume/flow_m3_h. The task model ignores soil storage and runoff; use the supplied effective rainfall directly. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `water_m3` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/solution/oracle.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/solution/solve.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/task.toml b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..db4e366025b88552f7bbbe65eee60f1e6e3c5c66 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "irrigation", "isced-0812", "train"] +isced_f = "0812" +family = "irrigation" +split = "train" +seed = 79 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/checks.json b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0fd81fd7916cb0e46251aa77f000bb680f0de10a --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.Z00.crop_et_mm", + "type": "number", + "value": 4.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.net_mm", + "type": "number", + "value": 3.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.gross_mm", + "type": "number", + "value": 4.587, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.water_m3", + "type": "number", + "value": 4.587, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z00.runtime_h", + "type": "number", + "value": 0.764, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.crop_et_mm", + "type": "number", + "value": 4.07, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.net_mm", + "type": "number", + "value": 2.07, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.gross_mm", + "type": "number", + "value": 2.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.water_m3", + "type": "number", + "value": 9.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z01.runtime_h", + "type": "number", + "value": 0.836, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.crop_et_mm", + "type": "number", + "value": 2.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.net_mm", + "type": "number", + "value": 1.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.gross_mm", + "type": "number", + "value": 1.467, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.water_m3", + "type": "number", + "value": 1.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z02.runtime_h", + "type": "number", + "value": 0.293, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.crop_et_mm", + "type": "number", + "value": 4.86, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.net_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.gross_mm", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.water_m3", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Z03.runtime_h", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 15.547, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/test.sh b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/verify.py b/tasks/grower-desk/grower-desk-irrigation-d3-t0079/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-irrigation-d3-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/grower-desk/grower-desk-propagation-d1-e0002/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-e0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-e0002/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..fd530bbee07bde1679c11dca9e74ed1f7323d828 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,23,40,1,71,100,100,planned +L01,35,60,1,72,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-e0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-e0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-e0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-e0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b09a8b2f5e05255903ee449c2f7062f158b55782 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10002 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4ab0eb22d8954fc8e7828848f42729596dfa6799 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 653.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 653.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 653.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 71.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1512.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1512.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1512.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 72.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-e0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d1-e0011/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-e0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-e0011/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..9e045c52542c533468d95ee6069f389694be3f13 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,18,84,1,87,100,100,planned +L01,38,60,1,82,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-e0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-e0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-e0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-e0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dfa9c52540e2cd99ac6f41030c0c3821236c0e10 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10011 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8675f2adf32e32d06188293ab2032f06de3263f2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1315.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1315.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1315.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 87.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1869.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1869.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1869.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 82.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-e0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-e0020/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-e0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-e0020/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..92048fe7ab83336518ed72e84d63ec3ff74874d3 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,34,60,1,73,100,100,planned +L01,12,40,1,76,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-e0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-e0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-e0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-e0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5411ce5c526bc9ac78e73c4ee95674b94df37a26 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10020 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6bc26b7540b260cdd055b6b78dce386a8b9cdb82 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1489.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1489.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1489.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 73.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 364.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 364.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 364.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 76.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-e0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-t0002/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0002/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..0f0b8f43116d7683d3eb8805f3bef59d3c12e579 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,16,84,1,84,100,100,planned +L01,15,40,1,72,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5996cf2d71d78c73b3e6c0011a7c136040a9f5f2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4a508f2e41b22f3945ef636204682dea04e951f7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1128.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1128.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1128.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 84.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 432.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 432.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 432.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 72.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d1-t0011/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0011/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..ae6b0277f1418d35b82c7dd71eedfc9c97366450 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,29,40,1,75,100,100,planned +L01,20,60,1,91,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..68b15e57ea68c3675d6abeb445aad8fa292677f7 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 11 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9369c1c464aab5a8af9ebe4428575e64daf2e3c8 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 870.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 870.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 870.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 75.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1092.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1092.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1092.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 91.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-t0020/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0020/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..b63e290c8fc26eb7c47457f4e498638ed4f4feb8 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,49,84,1,83,100,100,planned +L01,41,40,1,83,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6f73187fb43a2d4a763ef1bfec40de68e70c1205 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 20 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..31552665f590f91d2b10e27f499f619ac8867482 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 3416.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 3416.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 3416.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 83.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1361.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1361.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1361.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 83.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-t0029/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0029/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0029/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..5ee42521f99a08949fa565347f81bc99c3324fa4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,45,40,1,71,100,100,planned +L01,28,40,1,81,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0029/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0029/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0029/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0029/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4188bf22a69c527833dabc4868181b7e350cbfb8 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 29 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..de72fb33f1924d987c6ba0c6ea1af0b3e1fbdf4b --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1278.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1278.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1278.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 71.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 907.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 907.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 907.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 81.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0029/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-t0038/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0038/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0038/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..13e3eaf49327e7bf3008cdd1e473ace2fdde9b46 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,20,40,1,72,100,100,planned +L01,16,40,1,77,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0038/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0038/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0038/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0038/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f959b8d87b768c7d7b9b1f31e2a22fd3d211241e --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 38 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9d195b203da2b955b873047e23e89add9884845d --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 576.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 576.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 576.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 72.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 492.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 492.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 492.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 77.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0038/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d1-t0047/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0047/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0047/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..a6a3e1d420f35a6256f49386abb226409babff2b --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,43,84,1,78,100,100,planned +L01,29,40,1,93,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0047/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0047/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0047/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0047/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..477dc662e5575f4527f1ab3510a1f5d69cf783e1 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 47 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c152598e5c1a263b4d873e5de4253689fb7d2304 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2817.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 2817.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 2817.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 78.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1078.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1078.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1078.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 93.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0047/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-t0056/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0056/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0056/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..4f8f05feb238868e4f3911e6f76b74fcc6754d73 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,18,40,1,75,100,100,planned +L01,26,60,1,70,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0056/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0056/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0056/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0056/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e178e31733414929d94fe02af2e0059586562d7e --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 56 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..586208c45ffce2a3755f19fe804ee93390e408b4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 540.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 540.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 540.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 75.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1092.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1092.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1092.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 70.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0056/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-t0065/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0065/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0065/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..d44ca3a524f76718cc976a613c53eec41e97e60e --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,36,40,1,90,100,100,planned +L01,47,60,1,78,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0065/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0065/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0065/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0065/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f64deac0ca45d250fbd08314acc8a937b163618d --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 65 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6f2401007d1801ac6d7153a50185e438001ec250 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1296.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1296.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1296.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 90.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 2199.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 2199.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 2199.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 78.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0065/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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/grower-desk/grower-desk-propagation-d1-t0074/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0074/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0074/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..15e5c3779671022fb2e8ad9ae15413452b9d92f2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,19,60,1,94,100,100,planned +L01,38,60,1,89,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0074/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0074/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0074/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0074/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2a37f259aa52397c1a912027c4437191a4bea5b1 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 74 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bef49862b153219f10730a53b1129a8a190adfa5 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1071.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1071.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1071.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 94.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 2029.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 2029.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 2029.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 89.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0074/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d1-t0083/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d1-t0083/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d1-t0083/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..4990aec89a4ab493db16a8e5516b5646568f530f --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/environment/workdir/propagation.csv @@ -0,0 +1,3 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,12,40,1,77,100,100,planned +L01,43,60,1,73,100,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/instruction.md b/tasks/grower-desk/grower-desk-propagation-d1-t0083/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d1-t0083/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0083/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/task.toml b/tasks/grower-desk/grower-desk-propagation-d1-t0083/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9c6b07d6d25f0ae84db81ce32c439e89dc993504 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 83 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..37c7c52c9007b65627e2f2ab47e9f1246de4bd33 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 369.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 369.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 369.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 77.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1883.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1883.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1883.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 73.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d1-t0083/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d1-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() diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-e0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-e0005/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..eec4f35e51a5b1aabd6d96195cd7f8dde6bc713f --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L01,46,40,1,86,93,100,planned +L00,45,60,1,84,77,100,planned +L02,22,40,1,94,93,100,planned +CANCELLED,9999,60,1,84,77,100,cancelled diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-e0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-e0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-e0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-e0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ee43da0e052ceb9ca1798d9c0362b450440a9194 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10005 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..abef106cf3317f556e18721b6c501be9ef198d5e --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2268.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1746.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1746.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 64.68, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1582.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1471.632, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1471.632, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 79.98, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 827.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 769.296, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 769.296, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 87.42, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-e0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d2-e0014/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-e0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-e0014/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..250e9fdf561b94ce1b262195c4478fe34c3553da --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L02,13,84,1,89,85,100,planned +L01,13,60,1,70,87,100,planned +CANCELLED,9999,60,1,70,98,100,cancelled +L00,46,60,1,70,98,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-e0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-e0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-e0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-e0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fa91fbbbf4c31342bec8d72ee289a7c32bfc5a88 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10014 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8686ac73425b5d5f8dbdb2d897229af15f44ba6d --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1932.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1893.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1893.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 68.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 546.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 475.02, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 475.02, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 60.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 971.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 826.098, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 826.098, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 75.65, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-e0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-e0023/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-e0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-e0023/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..ad12251a7e96d9312cdaffa4bff744189cc6780a --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,48,60,1,81,84,100,planned +L02,50,60,1,88,97,100,planned +CANCELLED,9999,60,1,81,84,100,cancelled +L01,40,40,1,94,86,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-e0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-e0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-e0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-e0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4bc28621e5706399fed2c5c85069090b1653d8af --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10023 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..64c3d9ef2035e4c933413d40edb43f83f166c205 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2332.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1959.552, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1959.552, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 68.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1504.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1293.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1293.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 80.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 2640.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 2560.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 2560.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 85.36, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-e0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-t0005/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0005/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..3b04b5fbc3df162e7fb9e2787c325c8bb383e675 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L01,10,60,1,93,91,100,planned +CANCELLED,9999,60,1,77,92,100,cancelled +L02,30,60,1,73,81,100,planned +L00,42,60,1,77,92,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6777e6a130d7bc9aa0ca3cd5ff741c6b4ee1d3e0 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 5 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8ae43ee9cd060cc4a51e60486f422040956a5518 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1940.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1785.168, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1785.168, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 70.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 558.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 507.78, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 507.78, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 84.63, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 1314.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 1064.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 1064.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 59.13, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d2-t0014/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0014/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..c25c1debd6d46797789398a127c815d7874708df --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L02,48,84,1,85,85,100,planned +CANCELLED,9999,84,1,78,87,100,cancelled +L01,22,84,1,84,96,100,planned +L00,40,84,1,78,87,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..258cc55ecb589463d3953f808b41b89dccfe461b --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 14 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ed3eaa701195c053e2248cdbc3b6b68d2be6d231 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2620.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 2280.096, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 2280.096, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 67.86, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1552.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1490.227, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1490.227, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 80.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 3427.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 2913.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 2913.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 72.25, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-t0023/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0023/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..03ff6924571f80f25e611426bd8cf6d528f78470 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L01,14,60,1,81,80,100,planned +L02,45,60,1,84,77,100,planned +CANCELLED,9999,60,1,77,93,100,cancelled +L00,13,60,1,77,93,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..706f77976ee688021164faca00126f8d5748a7a8 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 23 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9c907f1d75cc220068bb397c2836261520ef96b2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 600.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 558.558, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 558.558, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 71.61, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 680.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 544.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 544.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 64.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 2268.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 1746.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 1746.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 64.68, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-t0032/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0032/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0032/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..895e0d2c78affbc611d8f37f62bc3caf80365142 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,32,60,1,94,76,100,planned +L02,42,84,1,83,80,100,planned +CANCELLED,9999,60,1,94,76,100,cancelled +L01,17,60,1,91,97,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0032/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0032/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0032/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0032/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..27cc74427f7e32bfbb4da7e5ff7dfc888441f33f --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 32 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ad5d1dc62953549918110aaca82a320af33b5942 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1804.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1371.648, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1371.648, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 71.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 928.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 900.354, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 900.354, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 88.27, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 2928.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 2342.592, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 2342.592, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 66.4, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0032/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-t0041/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0041/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0041/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..7eba7b9a953611c5877ae68d27e89cce945991f6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +CANCELLED,9999,60,1,80,84,100,cancelled +L02,18,60,1,84,95,100,planned +L00,14,60,1,80,84,100,planned +L01,39,40,1,79,85,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0041/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0041/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0041/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0041/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..98958bda97148fb5b9e8a57b32a6e9f72beba533 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 41 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..dda989cb52214f5f979331e617504482b672ccab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 672.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 564.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 564.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 67.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1232.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1047.54, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1047.54, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 67.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 907.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 861.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 861.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 79.8, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0041/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d2-t0050/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0050/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0050/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..ba9bafaba0cf65e7a86bb1205fc82e033e4cdf02 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L01,20,40,1,94,91,100,planned +L02,16,60,1,79,98,100,planned +CANCELLED,9999,84,1,78,84,100,cancelled +L00,10,84,1,78,84,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0050/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0050/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0050/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0050/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e26c58a06c1f00f2966bac5c95010768e95bd163 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 50 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6b17e405bc1ef39533d668ad22feed674334a9f2 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 655.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 550.368, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 550.368, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 65.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 752.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 684.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 684.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 85.54, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 758.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 743.232, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 743.232, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 77.42, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0050/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-t0059/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0059/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0059/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..e57d0dbb482aab95405c395e3e56bc3f708dfc48 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L01,19,60,1,75,98,100,planned +L00,36,60,1,82,75,100,planned +L02,39,60,1,86,80,100,planned +CANCELLED,9999,60,1,82,75,100,cancelled diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0059/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0059/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0059/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0059/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..287e672cfd88717a5870a1f116275ed6f17b834a --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 59 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..db700d9d9e364cad3bc2e54aebfec7dc1619517d --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1771.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1328.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1328.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 61.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 855.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 837.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 837.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 73.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 2012.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 1609.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 1609.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 68.8, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0059/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-t0068/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0068/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0068/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..7ae9b90eb596ff4c7b98bf5a1a88ed57a6c6ba0d --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +CANCELLED,9999,40,1,78,94,100,cancelled +L02,28,60,1,83,81,100,planned +L01,31,84,1,71,80,100,planned +L00,16,40,1,78,94,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0068/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0068/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0068/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0068/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3ec95bc2c2e91d4aad35242047114bf930509a89 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 68 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4e474f6cfcf5c1714ca87e638ca16372768302e6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 499.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 469.248, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 469.248, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 73.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1848.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1479.072, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1479.072, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 56.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 1394.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 1129.464, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 1129.464, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 67.23, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0068/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-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/grower-desk/grower-desk-propagation-d2-t0077/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d2-t0077/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d2-t0077/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..b3b2a5a4ad9105c3a2186dd34c69b71f669d816f --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/environment/workdir/propagation.csv @@ -0,0 +1,5 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +CANCELLED,9999,60,1,83,88,100,cancelled +L02,11,60,1,73,95,100,planned +L01,49,84,1,74,83,100,planned +L00,20,60,1,83,88,100,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/instruction.md b/tasks/grower-desk/grower-desk-propagation-d2-t0077/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..192f3c1e84e548e8d60e1e653da5eaca9a5bf3cc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d2-t0077/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0077/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/task.toml b/tasks/grower-desk/grower-desk-propagation-d2-t0077/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5004999a6a44a9c09c24084557217bd7d5866b1c --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 77 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c870272065d3dd5cdb322d4bf35349776e3ae258 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 996.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 876.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 876.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 73.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 3045.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 2528.047, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 2528.047, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 61.42, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 481.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 457.71, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 457.71, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 69.35, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d2-t0077/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d3-e0008/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-e0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-e0008/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..84476ea0525dc1a1684027d868fee78c2bc30c9e --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L02,26,84,1,84,84,92,planned +CANCELLED,9999,40,1,85,95,89,cancelled +L03,15,40,1,84,98,85,planned +L00,12,40,1,85,95,89,planned +L01,38,84,1,73,98,94,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-e0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-e0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-e0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-e0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c06dc71910947356476435682784d529d4075776 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10008 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f9518b2c84896b8479b0a2a3cdebf8cd1f5b3d63 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 408.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 387.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 344.964, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 71.868, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 2330.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 2283.557, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 2146.543, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 67.248, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 1834.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 1541.03, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 1417.748, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 64.915, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 504.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 493.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 419.832, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 69.972, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4329.087, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-e0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d3-e0017/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-e0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-e0017/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..5492cb9b40272207eb8704211fd66b33ef787dda --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,29,84,1,87,96,93,planned +CANCELLED,9999,84,1,87,96,93,cancelled +L02,13,40,1,95,93,84,planned +L03,30,60,1,83,84,86,planned +L01,22,84,1,73,98,92,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-e0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-e0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-e0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-e0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..aa2bd2d067b80af770b9c8ace76b6059ad7123ca --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "eval"] +isced_f = "0812" +family = "propagation" +split = "eval" +seed = 10017 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..034fd1885a5d788a64a9a4efebcded1b9dbef292 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2119.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 2034.547, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1892.129, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 77.674, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1349.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1322.059, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1216.294, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 65.817, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 494.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 459.42, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 385.913, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 74.214, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 1494.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 1254.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 1079.266, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 59.959, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4573.602, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-e0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-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/grower-desk/grower-desk-propagation-d3-t0008/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0008/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..6255dc9eb2f39d27c78420b8fdf8f5b8d1e558ef --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,13,60,1,84,88,93,planned +L01,47,60,1,78,84,80,planned +L02,16,40,1,91,96,87,planned +CANCELLED,9999,60,1,84,88,93,cancelled +L03,28,60,1,91,83,82,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..32ef4f044196247c35f2634fc9d8cf827cdc3904 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 8 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5bbaba7a91e4f16c5df01e9e36bcea32ee15f9ea --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 655.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 576.576, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 536.216, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 68.746, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 2199.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1847.664, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1478.131, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 52.416, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 582.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 559.104, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 486.42, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 76.003, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 1528.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 1268.904, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 1040.501, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 61.935, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3541.269, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d3-t0017/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0017/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..ba56e6cce62f3158eac36a43fb12efa3dea65990 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L02,21,84,1,85,91,85,planned +L00,38,84,1,82,98,91,planned +L01,17,40,1,75,79,86,planned +CANCELLED,9999,84,1,82,98,91,cancelled +L03,20,40,1,89,80,84,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e72a573fba184f5881a4ab59ab901cdfe36a5c87 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 17 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f49fc2e94d136d0eed350744232a3a4a6e740125 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2617.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 2565.091, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 2334.233, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 73.128, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 510.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 402.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 346.494, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 50.955, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 1499.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 1364.454, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 1159.786, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 65.747, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 712.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 569.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 478.464, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 59.808, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4318.977, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-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/grower-desk/grower-desk-propagation-d3-t0026/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0026/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0026/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..0f7f4b04eb3f3638f52292f615ed95a11f6c96bc --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +CANCELLED,9999,84,1,74,89,91,cancelled +L03,45,84,1,72,91,86,planned +L01,11,40,1,89,92,83,planned +L02,11,40,1,83,81,92,planned +L00,50,84,1,74,89,91,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0026/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0026/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0026/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0026/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0dcd8807629d1610e5a9a50514cb09cd5533d6b3 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 26 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..292ccc459ae4743bd2bbbedbf9e7726b76a60be4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 3108.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 2766.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 2517.169, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 59.933, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 391.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 360.272, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 299.026, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 67.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 365.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 295.812, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 272.147, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 61.852, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 2721.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 2476.656, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 2129.924, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 56.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5218.266, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0026/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-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/grower-desk/grower-desk-propagation-d3-t0035/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0035/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0035/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..f2576e946cec0e7ee8ecb4a54a615eabca2a490a --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +CANCELLED,9999,60,1,82,98,96,cancelled +L03,50,84,1,92,75,90,planned +L02,11,84,1,79,87,80,planned +L01,42,60,1,85,79,80,planned +L00,32,60,1,82,98,96,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0035/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0035/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0035/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0035/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f46eaebd39e493ec5cc14a18bc7106f7268dddfd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 35 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..76430c05000a23050269d0f17a4a020a52e92fc4 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1574.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1542.912, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1481.196, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 77.146, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 2142.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1692.18, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 1353.744, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 53.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 729.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 635.065, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 508.052, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 54.984, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 3864.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 2898.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 2608.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 62.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5951.192, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0035/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d3-t0044/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0044/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0044/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..5920de8f4f2b0820154dd7e8b437abc565df099e --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +CANCELLED,9999,40,1,87,86,82,cancelled +L03,34,40,1,76,87,95,planned +L02,23,40,1,78,85,97,planned +L01,19,84,1,72,91,81,planned +L00,15,40,1,87,86,82,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0044/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0044/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0044/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0044/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1eb99f609c0a4a80be5e4412ef506a078e755aaf --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 44 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a2c10138d8571728384ba69856a97777e420604a --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 522.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 448.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 368.114, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 61.352, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1149.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1045.699, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 847.016, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 53.071, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 717.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 609.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 591.661, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 64.311, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 1033.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 899.232, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 854.27, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 62.814, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 2661.062, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0044/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d3-t0053/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0053/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0053/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..6b461f7e4bea9063fa5bcc3334fc7a89822133eb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L03,50,40,1,89,88,94,planned +L01,34,84,1,93,85,95,planned +L00,28,84,1,95,90,81,planned +L02,39,40,1,87,85,96,planned +CANCELLED,9999,84,1,95,90,81,cancelled diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0053/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0053/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0053/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0053/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..db783d998b3c9fca5456802c7fff14c10cb6a564 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 53 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..674390dd81ba106583d9337ed079dcd1830ee3de --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2234.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 2010.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1628.878, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 69.255, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 2656.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 2257.668, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 2144.785, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 75.097, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 1357.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 1153.62, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 1107.475, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 70.992, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 1780.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 1566.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 1472.416, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 73.621, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 6353.553, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0053/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-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/grower-desk/grower-desk-propagation-d3-t0062/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0062/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0062/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..0fe5a188bb50aaa6949a4b1280b9d43be4560049 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,22,84,1,83,88,85,planned +L01,16,60,1,72,85,97,planned +L03,26,84,1,89,78,86,planned +L02,18,60,1,70,91,89,planned +CANCELLED,9999,84,1,83,88,85,cancelled diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0062/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0062/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0062/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0062/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2625df470120facf12cbcf88291c6c4538761cff --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 62 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8ea766a269d5efaec8e0ef3c673b4ec6f8a6f842 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1533.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1349.779, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1147.312, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 62.084, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 691.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 587.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 569.894, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 59.364, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 756.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 687.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 612.284, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 56.693, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 1943.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 1516.133, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 1303.874, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 59.701, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3633.365, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0062/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-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/grower-desk/grower-desk-propagation-d3-t0071/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0071/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0071/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..477dcdda9e479336ee7ef782ac0e0e42855db88a --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L00,35,60,1,82,80,93,planned +CANCELLED,9999,60,1,82,80,93,cancelled +L02,49,60,1,92,90,89,planned +L01,34,40,1,93,80,96,planned +L03,44,60,1,83,88,82,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0071/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0071/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0071/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0071/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a4ce080f8af1a2b8869c779dfac24be1e27c7734 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 71 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f9de54b34098991201e2f17954a018773e1c731b --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 1722.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 1377.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1281.168, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 61.008, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 1264.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 1011.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 971.366, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 71.424, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 2704.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 2434.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 2166.545, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 73.692, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 2191.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 1928.256, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 1581.17, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 59.893, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 6000.249, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0071/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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/grower-desk/grower-desk-propagation-d3-t0080/environment/Dockerfile b/tasks/grower-desk/grower-desk-propagation-d3-t0080/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/environment/workdir/propagation.csv b/tasks/grower-desk/grower-desk-propagation-d3-t0080/environment/workdir/propagation.csv new file mode 100644 index 0000000000000000000000000000000000000000..6b46f5ff10cc0fb8ae36c8037537f5703b680072 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/environment/workdir/propagation.csv @@ -0,0 +1,6 @@ +lot_id,trays,cells_per_tray,seeds_per_cell,germination_percent,transplant_survival_percent,sale_grade_percent,status +L03,46,84,1,90,87,88,planned +L00,31,84,1,89,96,88,planned +L02,11,84,1,89,85,94,planned +CANCELLED,9999,84,1,89,96,88,cancelled +L01,12,60,1,87,98,93,planned diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/instruction.md b/tasks/grower-desk/grower-desk-propagation-d3-t0080/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..94870a155d952aca79e9f9a0c895cbb41ea48fdb --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/instruction.md @@ -0,0 +1,5 @@ +# Grower Desk: propagation + +`propagation.csv` gives trays, cells and sequential expected yields. Sown seeds = trays*cells_per_tray*seeds_per_cell. For each `lot_id` return `germinated` = seeds*germination_percent/100, `transplanted` = germinated*transplant_survival_percent/100, `saleable` = transplanted*sale_grade_percent/100, and `overall_yield_percent` = 100*saleable/seeds. These are expected counts, so retain fractions rather than rounding to whole plants. + +Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. Also give `total_primary`, the sum of `saleable` across result groups. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions. diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/solution/oracle.py b/tasks/grower-desk/grower-desk-propagation-d3-t0080/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..ff022a9227569d66ef1aca584819c6be8f0585b6 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/solution/oracle.py @@ -0,0 +1,27 @@ +"""Independent solution from nursery records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned'] + +def solve(): + out={} + if Path('irrigation.csv').exists(): + for r in read('irrigation.csv'): + crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10 + out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h'])) + primary='water_m3' + elif Path('fertigation.csv').exists(): + for r in read('fertigation.csv'): + stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio + out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio) + primary='nutrient_g' + else: + for r in read('propagation.csv'): + initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')] + out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s) + primary='saleable' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/solution/solve.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0080/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/task.toml b/tasks/grower-desk/grower-desk-propagation-d3-t0080/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c9bf4315277c0e3ddabfce1387b661b6445af3cf --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "grower-desk" +tags = ["grower-desk", "propagation", "isced-0812", "train"] +isced_f = "0812" +family = "propagation" +split = "train" +seed = 80 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +build_timeout_sec = 600.0 +cpus = 1 +memory_mb = 1024 +storage_mb = 2048 +allow_internet = false diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/checks.json b/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9c06627f65f9c3febd129c86e14234a19b9d044a --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.L00.germinated", + "type": "number", + "value": 2317.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.transplanted", + "type": "number", + "value": 2224.858, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.saleable", + "type": "number", + "value": 1957.875, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L00.overall_yield_percent", + "type": "number", + "value": 75.187, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.germinated", + "type": "number", + "value": 626.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.transplanted", + "type": "number", + "value": 613.872, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.saleable", + "type": "number", + "value": 570.901, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L01.overall_yield_percent", + "type": "number", + "value": 79.292, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.germinated", + "type": "number", + "value": 822.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.transplanted", + "type": "number", + "value": 699.006, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.saleable", + "type": "number", + "value": 657.066, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L02.overall_yield_percent", + "type": "number", + "value": 71.111, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.germinated", + "type": "number", + "value": 3477.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.transplanted", + "type": "number", + "value": 3025.512, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.saleable", + "type": "number", + "value": 2662.451, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.L03.overall_yield_percent", + "type": "number", + "value": 68.904, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5848.292, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/test.sh b/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir -p /logs/verifier +python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/verify.py b/tasks/grower-desk/grower-desk-propagation-d3-t0080/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/grower-desk/grower-desk-propagation-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()