diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..f903ede2d41d66be9d1c47704d8b18c7be03dc71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,151,kg,15,h,0,completed,Harbour 0 +V00,T1,532,kg,6,h,0,completed,Harbour 1 +V00,T2,371,kg,8,h,0,completed,Harbour 0 +V00,T3,155,kg,10,h,0,completed,Harbour 1 +V01,T0,608,kg,9,h,0,completed,Harbour 0 +V01,T1,138,kg,11,h,0,completed,Harbour 1 +V01,T2,136,kg,11,h,0,completed,Harbour 0 +V01,T3,309,kg,12,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-e0000/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4ae7b676aa90025e070de17896fc3b4fb1b0d8e1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-e0000/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..815183dab065e8d2bf756787d79b3144549f4a28 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1209.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 39.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 31.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1209.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1191.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 43.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 27.698, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1191.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-e0000/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-e0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-e0009/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..665f0d8f51dc11ed96cea60fe10cc2234122b264 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,276,kg,6,h,0,completed,Harbour 0 +V00,T1,751,kg,8,h,0,completed,Harbour 1 +V00,T2,790,kg,12,h,0,completed,Harbour 0 +V00,T3,659,kg,15,h,0,completed,Harbour 1 +V01,T0,645,kg,9,h,0,completed,Harbour 0 +V01,T1,145,kg,8,h,0,completed,Harbour 1 +V01,T2,157,kg,10,h,0,completed,Harbour 0 +V01,T3,530,kg,10,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-e0009/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c6ef4c7e13aa7a42834691fa6e588296e74c4310 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-e0009/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c0e6f01e26eeb64836338bc55293e1718148ee94 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2476.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 41.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 60.39, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2476.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1477.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 37.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 39.919, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1477.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-e0009/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-e0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-e0018/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..66e155681ddf534e08dd20b172c1f6643cc3c390 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,318,kg,8,h,0,completed,Harbour 0 +V00,T1,355,kg,4,h,0,completed,Harbour 1 +V00,T2,359,kg,13,h,0,completed,Harbour 0 +V00,T3,437,kg,15,h,0,completed,Harbour 1 +V01,T0,586,kg,7,h,0,completed,Harbour 0 +V01,T1,588,kg,8,h,0,completed,Harbour 1 +V01,T2,683,kg,14,h,0,completed,Harbour 0 +V01,T3,425,kg,15,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-e0018/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a98b97de0c819ae8cb95220dcc5691df3656af56 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-e0018/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4a530d3ce54fb5080fdfe3ada6a62222ef50dd88 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1469.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 40.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 36.725, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1469.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2282.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 44.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 51.864, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2282.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-e0018/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-e0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0000/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..fa88e4df1812df1d113622fa4445b3239a710cc6 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,722,kg,8,h,0,completed,Harbour 0 +V00,T1,591,kg,15,h,0,completed,Harbour 1 +V00,T2,795,kg,6,h,0,completed,Harbour 0 +V00,T3,461,kg,16,h,0,completed,Harbour 1 +V01,T0,149,kg,11,h,0,completed,Harbour 0 +V01,T1,207,kg,7,h,0,completed,Harbour 1 +V01,T2,768,kg,9,h,0,completed,Harbour 0 +V01,T3,689,kg,9,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0000/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0329aedeecabdd8b08a42619f2f60efb42f6837a --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0000/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cf366f8cf684fa911482fa0517a1054504459cf9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2569.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 45.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 57.089, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2569.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1813.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 36.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 50.361, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1813.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0000/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0009/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..5c9f278eae46b0425e6237593fa9073eabd32804 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,486,kg,6,h,0,completed,Harbour 0 +V00,T1,799,kg,6,h,0,completed,Harbour 1 +V00,T2,125,kg,8,h,0,completed,Harbour 0 +V00,T3,522,kg,16,h,0,completed,Harbour 1 +V01,T0,392,kg,10,h,0,completed,Harbour 0 +V01,T1,492,kg,7,h,0,completed,Harbour 1 +V01,T2,781,kg,15,h,0,completed,Harbour 0 +V01,T3,539,kg,13,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0009/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..85cd71a393ac0bf5fd951849351691d4ad1cfd59 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0009/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3d3a3b07434c68682b94943c3788da8c9e0eed6b --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1932.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 36.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 53.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1932.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2204.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 45.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 48.978, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2204.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0009/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0018/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..70ef2930e7d14423a6ef425c132680df98f640e9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,496,kg,13,h,0,completed,Harbour 0 +V00,T1,699,kg,16,h,0,completed,Harbour 1 +V00,T2,386,kg,12,h,0,completed,Harbour 0 +V00,T3,435,kg,13,h,0,completed,Harbour 1 +V01,T0,229,kg,9,h,0,completed,Harbour 0 +V01,T1,327,kg,16,h,0,completed,Harbour 1 +V01,T2,365,kg,6,h,0,completed,Harbour 0 +V01,T3,740,kg,5,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0018/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..19e4e5152f3cd450b3d4fcc2b435219fd7cbeec5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0018/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8a97be762b3e73a14cdf749509c9bc7494f907b2 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2016.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 54.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 37.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2016.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1661.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 36.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 46.139, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1661.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0018/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0027/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..2fd8b780a420a9bcdd0a49f92060d195c098cdba --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,459,kg,12,h,0,completed,Harbour 0 +V00,T1,789,kg,15,h,0,completed,Harbour 1 +V00,T2,625,kg,12,h,0,completed,Harbour 0 +V00,T3,134,kg,13,h,0,completed,Harbour 1 +V01,T0,299,kg,7,h,0,completed,Harbour 0 +V01,T1,141,kg,7,h,0,completed,Harbour 1 +V01,T2,562,kg,13,h,0,completed,Harbour 0 +V01,T3,695,kg,8,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0027/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e9b6a6b80ea73ac0d7dc394db67b826f5aad61cb --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0027/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6ee0a03d0ca750ab64e95b2ba873a56048b706e3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2007.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 52.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 38.596, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2007.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1697.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 35.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 48.486, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1697.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0027/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0027/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0036/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..2afc1e370e5b74e37518da3fdc776dd8dedef07f --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,663,kg,4,h,0,completed,Harbour 0 +V00,T1,511,kg,5,h,0,completed,Harbour 1 +V00,T2,251,kg,13,h,0,completed,Harbour 0 +V00,T3,671,kg,10,h,0,completed,Harbour 1 +V01,T0,199,kg,11,h,0,completed,Harbour 0 +V01,T1,742,kg,7,h,0,completed,Harbour 1 +V01,T2,634,kg,7,h,0,completed,Harbour 0 +V01,T3,552,kg,9,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0036/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fde38c2ab46b466b89eed0aeef6264b1781d36ea --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0036/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e22a07b3e8d00562a03dd728c4de9b6dc42618e7 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2096.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 32.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 65.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2096.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2127.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 34.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 62.559, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2127.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0036/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0036/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0045/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..4fc4e755d244f9c1ee369fdaa5f407ce3bce9e92 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,423,kg,6,h,0,completed,Harbour 0 +V00,T1,716,kg,4,h,0,completed,Harbour 1 +V00,T2,234,kg,4,h,0,completed,Harbour 0 +V00,T3,660,kg,12,h,0,completed,Harbour 1 +V01,T0,762,kg,11,h,0,completed,Harbour 0 +V01,T1,463,kg,5,h,0,completed,Harbour 1 +V01,T2,399,kg,16,h,0,completed,Harbour 0 +V01,T3,353,kg,13,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0045/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..89317155d661730866f2894d3a0257c99a540709 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0045/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0199df1eb0c5e8eed2d905bd8a05a402bfa31b81 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2033.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 26.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 78.192, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2033.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1977.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 45.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 43.933, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1977.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0045/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0045/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0054/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..af9df0bc52326b7a7d3e5df8ce837ce0e95c046d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,396,kg,6,h,0,completed,Harbour 0 +V00,T1,420,kg,12,h,0,completed,Harbour 1 +V00,T2,551,kg,9,h,0,completed,Harbour 0 +V00,T3,204,kg,11,h,0,completed,Harbour 1 +V01,T0,387,kg,12,h,0,completed,Harbour 0 +V01,T1,686,kg,16,h,0,completed,Harbour 1 +V01,T2,683,kg,14,h,0,completed,Harbour 0 +V01,T3,478,kg,7,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0054/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..98182ad7375b682032135d11578208885430adb0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0054/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..47c5e8b354e2987c9e86a3fede3ce75be4e2b9fb --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1571.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 38.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 41.342, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1571.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2234.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 49.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 45.592, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2234.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0054/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0054/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0063/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..7b91927f06e3e34f70e56b9313f6903cdeb92e61 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,394,kg,9,h,0,completed,Harbour 0 +V00,T1,681,kg,9,h,0,completed,Harbour 1 +V00,T2,232,kg,9,h,0,completed,Harbour 0 +V00,T3,534,kg,15,h,0,completed,Harbour 1 +V01,T0,267,kg,16,h,0,completed,Harbour 0 +V01,T1,553,kg,12,h,0,completed,Harbour 1 +V01,T2,408,kg,5,h,0,completed,Harbour 0 +V01,T3,433,kg,13,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0063/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f05192625a58433a43d8e0b1121f459f841dfbdb --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0063/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..22c5b2e23a6158d394be0dec4b7980c93ee3b84d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1841.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 42.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 43.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1841.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1661.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 46.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 36.109, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1661.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0063/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0063/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0072/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..17f8d1e9411c291392125fa51f15ba178dab680d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,432,kg,8,h,0,completed,Harbour 0 +V00,T1,331,kg,9,h,0,completed,Harbour 1 +V00,T2,520,kg,11,h,0,completed,Harbour 0 +V00,T3,122,kg,5,h,0,completed,Harbour 1 +V01,T0,439,kg,5,h,0,completed,Harbour 0 +V01,T1,433,kg,7,h,0,completed,Harbour 1 +V01,T2,378,kg,11,h,0,completed,Harbour 0 +V01,T3,155,kg,10,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0072/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..50912777557220575e99f12baa4f553475695ae8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0072/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9fc67c8f3a18a9e288fc838626db124f90d95be5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1405.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 33.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 42.576, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1405.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1405.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 33.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 42.576, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1405.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0072/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0072/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0081/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..1f244a535956289b68038afb7dd7470c19b37112 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/environment/workdir/trips.csv @@ -0,0 +1,9 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T0,565,kg,13,h,0,completed,Harbour 0 +V00,T1,694,kg,15,h,0,completed,Harbour 1 +V00,T2,392,kg,16,h,0,completed,Harbour 0 +V00,T3,204,kg,6,h,0,completed,Harbour 1 +V01,T0,730,kg,12,h,0,completed,Harbour 0 +V01,T1,490,kg,12,h,0,completed,Harbour 1 +V01,T2,374,kg,14,h,0,completed,Harbour 0 +V01,T3,121,kg,13,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d1-t0081/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a4e63433ae389c521a063086e8c7af994a29be5d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d1-t0081/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4127b121e55c4c07e6d6e3736a191ef68fe415ac --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1855.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 50.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 37.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1855.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1715.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 51.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 33.627, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1715.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d1-t0081/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d1-t0081/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-e0003/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..4bf3ff8358c502da6d6b7a9f750b6de90b76b352 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V02,T4,681,kg,7,h,0,completed,Harbour 0 +V00,T1,544,kg,10,h,0,completed,Harbour 1 +V00,T4,549,kg,11,h,0,completed,Harbour 0 +V01,CANCEL,99999,kg,7,h,0,cancelled,Harbour 0 +V01,T2,713,kg,9,h,0,completed,Harbour 0 +V02,T3,377,kg,15,h,0,completed,Harbour 1 +V00,T3,540,kg,7,h,0,completed,Harbour 1 +V01,T3,291,kg,13,h,0,completed,Harbour 1 +V00,CANCEL,99999,kg,11,h,0,cancelled,Harbour 0 +V00,T2,565,kg,15,h,0,completed,Harbour 0 +V01,T0,649,kg,7,h,0,completed,Harbour 0 +V01,T4,696,kg,7,h,0,completed,Harbour 0 +V00,T0,245,kg,12,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,7,h,0,cancelled,Harbour 0 +V02,T2,678,kg,7,h,0,completed,Harbour 0 +V02,T0,551,kg,4,h,0,completed,Harbour 0 +V01,T1,109,kg,12,h,0,completed,Harbour 1 +V02,T1,694,kg,14,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-e0003/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8ab85898c323a60eaa50adcf11ff8dcf0449f3e6 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-e0003/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b8f9f509648a526aace559f233dbde7b76e21874 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2443.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 55.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 44.418, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2443.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2458.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 48.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 51.208, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2458.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2981.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 47.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 63.426, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2981.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-e0003/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-e0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-e0012/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..b2161b8a9287df854c71d351dfd55ba945800f44 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V02,T3,556,kg,8,h,0,completed,Harbour 1 +V02,CANCEL,99999,kg,15,h,0,cancelled,Harbour 0 +V00,T3,795,kg,7,h,0,completed,Harbour 1 +V00,T0,629,kg,6,h,0,completed,Harbour 0 +V00,T2,597,kg,16,h,0,completed,Harbour 0 +V00,T1,503,kg,15,h,0,completed,Harbour 1 +V02,T2,388,kg,15,h,0,completed,Harbour 0 +V02,T4,339,kg,15,h,0,completed,Harbour 0 +V01,T4,600,kg,4,h,0,completed,Harbour 0 +V02,T1,219,kg,16,h,0,completed,Harbour 1 +V01,T2,228,kg,6,h,0,completed,Harbour 0 +V02,T0,652,kg,15,h,0,completed,Harbour 0 +V01,T1,297,kg,8,h,0,completed,Harbour 1 +V01,T3,474,kg,7,h,0,completed,Harbour 1 +V01,CANCEL,99999,kg,4,h,0,cancelled,Harbour 0 +V01,T0,627,kg,8,h,0,completed,Harbour 0 +V00,CANCEL,99999,kg,12,h,0,cancelled,Harbour 0 +V00,T4,722,kg,12,h,0,completed,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-e0012/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dcc25f451776097a4973042a1d81051bfcffa2cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-e0012/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9f735a9ce211f3d97df8a04d70788bd818775ec3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 3246.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 56.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 57.964, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 3246.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2226.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 33.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 67.455, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2226.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2154.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 69.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 31.217, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2154.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-e0012/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-e0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-e0021/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..bc1114da8fd75f6df6d0bf54857c744971cd3b44 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V01,T0,765,kg,11,h,0,completed,Harbour 0 +V02,T1,548,kg,9,h,0,completed,Harbour 1 +V01,T4,174,kg,10,h,0,completed,Harbour 0 +V00,T0,229,kg,15,h,0,completed,Harbour 0 +V02,T0,705,kg,16,h,0,completed,Harbour 0 +V00,CANCEL,99999,kg,15,h,0,cancelled,Harbour 0 +V00,T4,725,kg,15,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,13,h,0,cancelled,Harbour 0 +V02,T4,175,kg,13,h,0,completed,Harbour 0 +V01,T2,642,kg,5,h,0,completed,Harbour 0 +V00,T3,730,kg,15,h,0,completed,Harbour 1 +V01,T1,777,kg,7,h,0,completed,Harbour 1 +V00,T1,349,kg,8,h,0,completed,Harbour 1 +V02,T3,121,kg,5,h,0,completed,Harbour 1 +V01,T3,494,kg,8,h,0,completed,Harbour 1 +V01,CANCEL,99999,kg,10,h,0,cancelled,Harbour 0 +V02,T2,363,kg,10,h,0,completed,Harbour 0 +V00,T2,637,kg,13,h,0,completed,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-e0021/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b75933ef6ae96a876994022c1777654e63b48d73 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-e0021/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a119f16a3499cfae4d7f7bf3027c31c8ba21b4dc --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2670.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 66.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 40.455, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2670.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2852.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 41.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 69.561, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2852.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 1912.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 53.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 36.075, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 1912.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-e0021/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-e0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0003/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..cd97922c3b88d761d55978a3b82fda7beaf18630 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V01,T3,290,kg,15,h,0,completed,Harbour 1 +V02,T3,344,kg,7,h,0,completed,Harbour 1 +V02,T2,209,kg,5,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,12,h,0,cancelled,Harbour 0 +V00,T4,769,kg,11,h,0,completed,Harbour 0 +V01,T2,431,kg,14,h,0,completed,Harbour 0 +V01,CANCEL,99999,kg,15,h,0,cancelled,Harbour 0 +V00,T3,590,kg,12,h,0,completed,Harbour 1 +V01,T1,327,kg,6,h,0,completed,Harbour 1 +V00,CANCEL,99999,kg,11,h,0,cancelled,Harbour 0 +V00,T1,125,kg,4,h,0,completed,Harbour 1 +V02,T4,681,kg,12,h,0,completed,Harbour 0 +V02,T1,445,kg,8,h,0,completed,Harbour 1 +V01,T4,784,kg,15,h,0,completed,Harbour 0 +V00,T2,445,kg,4,h,0,completed,Harbour 0 +V01,T0,506,kg,9,h,0,completed,Harbour 0 +V00,T0,315,kg,11,h,0,completed,Harbour 0 +V02,T0,181,kg,9,h,0,completed,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0003/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..341fd07d2b00491fa753a9af01e20548fc13409b --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0003/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0e6c53a2e031c2f98c796c8e959f9b654485b39a --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2244.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 42.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 53.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2244.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2338.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 59.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 39.627, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2338.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 1860.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 41.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 45.366, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 1860.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0003/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0012/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..8e42cfb91fa69b17fe5a2c4eca3e587f0aa2e9db --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V02,T0,410,kg,12,h,0,completed,Harbour 0 +V01,T1,493,kg,12,h,0,completed,Harbour 1 +V00,T1,352,kg,5,h,0,completed,Harbour 1 +V00,T0,753,kg,15,h,0,completed,Harbour 0 +V02,T1,308,kg,8,h,0,completed,Harbour 1 +V01,T4,241,kg,6,h,0,completed,Harbour 0 +V00,T2,103,kg,14,h,0,completed,Harbour 0 +V00,T4,250,kg,4,h,0,completed,Harbour 0 +V00,T3,271,kg,6,h,0,completed,Harbour 1 +V01,T3,372,kg,16,h,0,completed,Harbour 1 +V01,CANCEL,99999,kg,6,h,0,cancelled,Harbour 0 +V02,T3,183,kg,13,h,0,completed,Harbour 1 +V01,T0,145,kg,15,h,0,completed,Harbour 0 +V00,CANCEL,99999,kg,4,h,0,cancelled,Harbour 0 +V02,CANCEL,99999,kg,10,h,0,cancelled,Harbour 0 +V01,T2,263,kg,8,h,0,completed,Harbour 0 +V02,T4,227,kg,10,h,0,completed,Harbour 0 +V02,T2,492,kg,9,h,0,completed,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0012/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ca37b40eecc40a1472640e4935d0d5d102572088 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0012/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7d1ea1c5d4463627acbac5b03be3bb479d75e7da --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1729.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 44.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 39.295, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1729.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1514.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 57.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 26.561, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1514.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 1620.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 52.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 31.154, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 1620.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0012/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0021/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..9acbb3e9623e8cacce31484beec2a7313b24e88d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T1,202,kg,14,h,0,completed,Harbour 1 +V00,T4,727,kg,11,h,0,completed,Harbour 0 +V02,T4,238,kg,7,h,0,completed,Harbour 0 +V02,T2,361,kg,8,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,7,h,0,cancelled,Harbour 0 +V01,T3,528,kg,16,h,0,completed,Harbour 1 +V01,CANCEL,99999,kg,16,h,0,cancelled,Harbour 0 +V01,T1,635,kg,9,h,0,completed,Harbour 1 +V02,T1,312,kg,15,h,0,completed,Harbour 1 +V00,T0,166,kg,14,h,0,completed,Harbour 0 +V01,T2,708,kg,14,h,0,completed,Harbour 0 +V00,T2,707,kg,13,h,0,completed,Harbour 0 +V00,T3,219,kg,8,h,0,completed,Harbour 1 +V02,T0,402,kg,11,h,0,completed,Harbour 0 +V01,T0,560,kg,12,h,0,completed,Harbour 0 +V02,T3,598,kg,12,h,0,completed,Harbour 1 +V01,T4,331,kg,16,h,0,completed,Harbour 0 +V00,CANCEL,99999,kg,11,h,0,cancelled,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0021/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..53d62e77331262deff659359b11c41abdf773d2f --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0021/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7bfe58a8ace74a48c90d374ea30de6d36172cd63 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2021.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 60.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 33.683, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2021.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2762.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 67.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 41.224, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2762.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 1911.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 53.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 36.057, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 1911.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0021/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0030/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..1b5e2468cf34ca642e2370ba4b9c555cb0ed88a3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T3,146,kg,13,h,0,completed,Harbour 1 +V01,T4,738,kg,13,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,9,h,0,cancelled,Harbour 0 +V00,T0,629,kg,10,h,0,completed,Harbour 0 +V02,T4,308,kg,9,h,0,completed,Harbour 0 +V00,CANCEL,99999,kg,11,h,0,cancelled,Harbour 0 +V01,T2,100,kg,5,h,0,completed,Harbour 0 +V01,T3,103,kg,4,h,0,completed,Harbour 1 +V01,CANCEL,99999,kg,13,h,0,cancelled,Harbour 0 +V00,T1,241,kg,11,h,0,completed,Harbour 1 +V01,T1,633,kg,16,h,0,completed,Harbour 1 +V01,T0,104,kg,14,h,0,completed,Harbour 0 +V02,T1,504,kg,4,h,0,completed,Harbour 1 +V00,T4,788,kg,11,h,0,completed,Harbour 0 +V02,T3,513,kg,16,h,0,completed,Harbour 1 +V02,T2,650,kg,8,h,0,completed,Harbour 0 +V00,T2,476,kg,5,h,0,completed,Harbour 0 +V02,T0,139,kg,13,h,0,completed,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0030/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1b7db6eea4d32573f5ef0bf9191f2f93b5bf0a83 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0030/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a63985d5dbaf61f10b90049bbb3dff4ff919dc1f --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2280.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 50.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 45.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2280.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1678.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 52.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 32.269, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1678.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2114.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 50.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 42.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2114.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0030/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0030/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0039/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..567ff7ec20c1737182633b752a9ce32cd50bff2a --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T4,114,kg,9,h,0,completed,Harbour 0 +V02,T3,765,kg,5,h,0,completed,Harbour 1 +V01,CANCEL,99999,kg,13,h,0,cancelled,Harbour 0 +V01,T0,653,kg,4,h,0,completed,Harbour 0 +V01,T3,148,kg,15,h,0,completed,Harbour 1 +V00,T3,437,kg,7,h,0,completed,Harbour 1 +V00,T1,201,kg,4,h,0,completed,Harbour 1 +V02,T1,595,kg,5,h,0,completed,Harbour 1 +V01,T2,560,kg,10,h,0,completed,Harbour 0 +V02,T4,620,kg,7,h,0,completed,Harbour 0 +V01,T4,769,kg,13,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,7,h,0,cancelled,Harbour 0 +V02,T2,249,kg,10,h,0,completed,Harbour 0 +V02,T0,450,kg,12,h,0,completed,Harbour 0 +V01,T1,387,kg,14,h,0,completed,Harbour 1 +V00,T2,749,kg,9,h,0,completed,Harbour 0 +V00,T0,446,kg,14,h,0,completed,Harbour 0 +V00,CANCEL,99999,kg,9,h,0,cancelled,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0039/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b5392042cca3b2adba0835fad99550d9533ffb39 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0039/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cd437c0b5ce6b7fc95ad0053d2c908a3ac038f70 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1947.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 43.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 45.279, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1947.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2517.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 56.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 44.946, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2517.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2679.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 39.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 68.692, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2679.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0039/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0039/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0048/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..033470972370cdd122881505faa53a93b8e9abc3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,CANCEL,99999,kg,9,h,0,cancelled,Harbour 0 +V00,T0,435,kg,4,h,0,completed,Harbour 0 +V01,T0,205,kg,7,h,0,completed,Harbour 0 +V00,T4,399,kg,9,h,0,completed,Harbour 0 +V00,T1,389,kg,10,h,0,completed,Harbour 1 +V01,T3,569,kg,13,h,0,completed,Harbour 1 +V00,T2,748,kg,10,h,0,completed,Harbour 0 +V02,T3,151,kg,8,h,0,completed,Harbour 1 +V02,CANCEL,99999,kg,6,h,0,cancelled,Harbour 0 +V00,T3,769,kg,13,h,0,completed,Harbour 1 +V01,T2,735,kg,4,h,0,completed,Harbour 0 +V02,T0,143,kg,6,h,0,completed,Harbour 0 +V02,T2,655,kg,5,h,0,completed,Harbour 0 +V02,T4,193,kg,6,h,0,completed,Harbour 0 +V01,CANCEL,99999,kg,16,h,0,cancelled,Harbour 0 +V02,T1,776,kg,7,h,0,completed,Harbour 1 +V01,T4,653,kg,16,h,0,completed,Harbour 0 +V01,T1,508,kg,9,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0048/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2b02211e69e0b33906b80cc467bb59e4fda751f0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0048/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..45be500d0b47e7c88ce18f1d6fd7a8a89847b65f --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2740.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 46.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 59.565, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2740.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2670.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 49.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 54.49, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2670.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 1918.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 32.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 59.938, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 1918.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0048/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0048/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0057/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..d9355714da022f61d88fac6af4c2343908787a84 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V02,T3,119,kg,4,h,0,completed,Harbour 1 +V01,T0,441,kg,15,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,10,h,0,cancelled,Harbour 0 +V02,T0,705,kg,16,h,0,completed,Harbour 0 +V00,T2,397,kg,9,h,0,completed,Harbour 0 +V01,T2,708,kg,15,h,0,completed,Harbour 0 +V00,T0,476,kg,10,h,0,completed,Harbour 0 +V00,T4,243,kg,8,h,0,completed,Harbour 0 +V01,T4,421,kg,16,h,0,completed,Harbour 0 +V01,T1,504,kg,8,h,0,completed,Harbour 1 +V02,T4,445,kg,10,h,0,completed,Harbour 0 +V00,CANCEL,99999,kg,8,h,0,cancelled,Harbour 0 +V02,T2,340,kg,10,h,0,completed,Harbour 0 +V02,T1,239,kg,6,h,0,completed,Harbour 1 +V00,T1,371,kg,16,h,0,completed,Harbour 1 +V01,CANCEL,99999,kg,16,h,0,cancelled,Harbour 0 +V01,T3,299,kg,6,h,0,completed,Harbour 1 +V00,T3,259,kg,13,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0057/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dae3e00ab9371fc5bde41555f488739d92f4a933 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0057/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7db8fe88a7f579c3804110c0a177ca02b230a8d1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1746.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 56.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 31.179, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1746.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2373.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 60.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 39.55, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2373.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 1848.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 46.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 40.174, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 1848.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0057/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0057/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0066/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..236f9950ec91ee194f8319aec71b527d4821b725 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V01,T3,446,kg,8,h,0,completed,Harbour 1 +V01,T1,274,kg,12,h,0,completed,Harbour 1 +V00,T1,526,kg,11,h,0,completed,Harbour 1 +V02,T1,754,kg,15,h,0,completed,Harbour 1 +V02,T2,740,kg,15,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,8,h,0,cancelled,Harbour 0 +V01,T2,358,kg,15,h,0,completed,Harbour 0 +V01,T0,580,kg,5,h,0,completed,Harbour 0 +V00,T0,664,kg,7,h,0,completed,Harbour 0 +V02,T4,270,kg,8,h,0,completed,Harbour 0 +V01,T4,684,kg,14,h,0,completed,Harbour 0 +V00,T2,415,kg,15,h,0,completed,Harbour 0 +V00,T4,197,kg,12,h,0,completed,Harbour 0 +V01,CANCEL,99999,kg,14,h,0,cancelled,Harbour 0 +V02,T0,410,kg,11,h,0,completed,Harbour 0 +V00,T3,598,kg,13,h,0,completed,Harbour 1 +V00,CANCEL,99999,kg,12,h,0,cancelled,Harbour 0 +V02,T3,650,kg,8,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0066/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..99c383eaf1914c824e384238cb6744ccfaae019a --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0066/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4d725177e765d359db2bd3bc42d3211dd33fa0fe --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2400.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 58.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 41.379, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2400.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2342.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 54.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 43.37, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2342.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2824.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 57.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 49.544, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2824.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0066/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0066/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0075/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..d456fb5641437e37476ecdf2e2285cadd24d7389 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/environment/workdir/trips.csv @@ -0,0 +1,19 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,CANCEL,99999,kg,4,h,0,cancelled,Harbour 0 +V02,T2,789,kg,11,h,0,completed,Harbour 0 +V00,T1,179,kg,8,h,0,completed,Harbour 1 +V00,T4,186,kg,4,h,0,completed,Harbour 0 +V01,T2,617,kg,15,h,0,completed,Harbour 0 +V01,T1,411,kg,12,h,0,completed,Harbour 1 +V02,T0,299,kg,6,h,0,completed,Harbour 0 +V01,CANCEL,99999,kg,12,h,0,cancelled,Harbour 0 +V02,T4,781,kg,5,h,0,completed,Harbour 0 +V00,T3,417,kg,9,h,0,completed,Harbour 1 +V00,T0,209,kg,8,h,0,completed,Harbour 0 +V00,T2,683,kg,8,h,0,completed,Harbour 0 +V02,T1,144,kg,13,h,0,completed,Harbour 1 +V02,T3,359,kg,5,h,0,completed,Harbour 1 +V01,T4,267,kg,12,h,0,completed,Harbour 0 +V01,T0,215,kg,5,h,0,completed,Harbour 0 +V02,CANCEL,99999,kg,5,h,0,cancelled,Harbour 0 +V01,T3,414,kg,8,h,0,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f39d8ce4008e2712d187518c9190e3c34230f4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d2-t0075/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a01f703c2a4fa0477d175381018d519908d087a9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d2-t0075/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3e7ea60923930ee4c04d61b30d707c9f8ea2f055 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1674.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 37.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 45.243, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 1674.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1924.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 52.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 37.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1924.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2372.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 40.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 59.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2372.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d2-t0075/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d2-t0075/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-e0006/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..f929bf712de08b9146b4e57c355edb6d3804c3ce --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T4,359,kg,12,h,35,completed,Harbour 0 +V03,T2,526,kg,16,h,27,completed,Harbour 0 +V00,T5,0.278,tonne,0.3333333333333333,day,24,completed,Harbour 1 +V00,T1,0.498,tonne,0.2916666666666667,day,14,completed,Harbour 1 +V00,T0,184,kg,6,h,51,completed,Harbour 0 +V00,T2,678,kg,12,h,54,completed,Harbour 0 +V03,T3,0.46,tonne,0.375,day,49,completed,Harbour 1 +V01,T4,104,kg,4,h,41,completed,Harbour 0 +V01,T5,0.332,tonne,0.6666666666666666,day,15,completed,Harbour 1 +V02,T0,240,kg,13,h,21,completed,Harbour 0 +V01,T3,0.432,tonne,0.5,day,32,completed,Harbour 1 +V03,T1,0.183,tonne,0.3333333333333333,day,34,completed,Harbour 1 +V02,T3,0.252,tonne,0.5416666666666666,day,51,completed,Harbour 1 +V02,T2,461,kg,8,h,34,completed,Harbour 0 +V02,CANCEL,99999,tonne,0.5416666666666666,day,51,cancelled,Harbour 1 +V02,T4,125,kg,11,h,26,completed,Harbour 0 +V03,T4,361,kg,9,h,54,completed,Harbour 0 +V03,T5,0.14,tonne,0.6666666666666666,day,14,completed,Harbour 1 +V00,T3,0.78,tonne,0.3333333333333333,day,13,completed,Harbour 1 +V01,T1,0.738,tonne,0.5416666666666666,day,56,completed,Harbour 1 +V00,CANCEL,99999,tonne,0.3333333333333333,day,24,cancelled,Harbour 1 +V02,T1,0.586,tonne,0.625,day,30,completed,Harbour 1 +V01,T0,583,kg,10,h,21,completed,Harbour 0 +V01,T2,419,kg,8,h,31,completed,Harbour 0 +V01,CANCEL,99999,tonne,0.6666666666666666,day,15,cancelled,Harbour 1 +V03,T0,466,kg,15,h,32,completed,Harbour 0 +V03,CANCEL,99999,tonne,0.6666666666666666,day,14,cancelled,Harbour 1 +V02,T5,0.538,tonne,0.5416666666666666,day,51,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-e0006/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8c7b08bd593773be6698af64e7ff0864b8d4dd57 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-e0006/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f15d01495cca3d15b31de96e1de14e2cfa5225b1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2777.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 53.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 52.396, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 191.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2968.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2608.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 63.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 41.397, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 196.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2804.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2202.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 73.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 30.164, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 213.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2415.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 2136.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 73.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 29.26, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 210.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 2346.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 9723.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-e0006/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-e0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-e0015/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..4ccbf8f147e46916a70d16be663e44938cdf003c --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,CANCEL,99999,tonne,0.3333333333333333,day,46,cancelled,Harbour 1 +V01,T0,488,kg,7,h,36,completed,Harbour 0 +V03,CANCEL,99999,tonne,0.20833333333333334,day,36,cancelled,Harbour 1 +V03,T4,164,kg,6,h,58,completed,Harbour 0 +V01,T4,219,kg,14,h,13,completed,Harbour 0 +V02,T1,0.33,tonne,0.25,day,6,completed,Harbour 1 +V02,T3,0.227,tonne,0.25,day,34,completed,Harbour 1 +V02,T5,0.35,tonne,0.375,day,22,completed,Harbour 1 +V01,T2,350,kg,15,h,7,completed,Harbour 0 +V00,T0,675,kg,15,h,34,completed,Harbour 0 +V01,T1,0.17,tonne,0.4583333333333333,day,38,completed,Harbour 1 +V00,T5,0.586,tonne,0.3333333333333333,day,46,completed,Harbour 1 +V00,T4,154,kg,11,h,10,completed,Harbour 0 +V01,T3,0.416,tonne,0.20833333333333334,day,53,completed,Harbour 1 +V03,T2,748,kg,14,h,17,completed,Harbour 0 +V03,T0,743,kg,10,h,22,completed,Harbour 0 +V02,T4,752,kg,14,h,58,completed,Harbour 0 +V01,T5,0.337,tonne,0.5833333333333334,day,43,completed,Harbour 1 +V00,T1,0.256,tonne,0.625,day,18,completed,Harbour 1 +V02,T0,612,kg,13,h,26,completed,Harbour 0 +V03,T5,0.136,tonne,0.20833333333333334,day,36,completed,Harbour 1 +V00,T3,0.467,tonne,0.5833333333333334,day,54,completed,Harbour 1 +V03,T1,0.677,tonne,0.20833333333333334,day,58,completed,Harbour 1 +V02,T2,344,kg,13,h,10,completed,Harbour 0 +V01,CANCEL,99999,tonne,0.5833333333333334,day,43,cancelled,Harbour 1 +V00,T2,591,kg,4,h,17,completed,Harbour 0 +V02,CANCEL,99999,tonne,0.375,day,22,cancelled,Harbour 1 +V03,T3,0.451,tonne,0.5416666666666666,day,28,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-e0015/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1126fa72e9b6607da68c058b6d2851d1c0c8087f --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "eval"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-e0015/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..668170de5a7234abb71c2e89d394513630d6111f --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2729.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 67.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 40.731, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 179.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2908.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1980.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 66.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 30.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 190.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2170.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2615.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 61.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 42.869, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 156.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2771.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 2919.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 53.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 55.075, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 219.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 3138.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 10243.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-e0015/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-e0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0006/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..99211e945f4ba51077e71913fddcd2a3ef76c045 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,CANCEL,99999,tonne,0.20833333333333334,day,53,cancelled,Harbour 1 +V01,T1,0.138,tonne,0.25,day,26,completed,Harbour 1 +V03,T0,590,kg,8,h,7,completed,Harbour 0 +V03,T5,0.441,tonne,0.4583333333333333,day,25,completed,Harbour 1 +V00,T0,243,kg,10,h,10,completed,Harbour 0 +V03,CANCEL,99999,tonne,0.4583333333333333,day,25,cancelled,Harbour 1 +V00,T1,0.208,tonne,0.4166666666666667,day,35,completed,Harbour 1 +V01,T5,0.221,tonne,0.20833333333333334,day,34,completed,Harbour 1 +V00,T5,0.374,tonne,0.20833333333333334,day,53,completed,Harbour 1 +V01,T4,225,kg,9,h,30,completed,Harbour 0 +V00,T3,0.232,tonne,0.16666666666666666,day,24,completed,Harbour 1 +V02,T1,0.384,tonne,0.375,day,19,completed,Harbour 1 +V03,T1,0.431,tonne,0.25,day,45,completed,Harbour 1 +V02,T2,285,kg,14,h,44,completed,Harbour 0 +V00,T2,547,kg,6,h,23,completed,Harbour 0 +V02,T0,198,kg,9,h,58,completed,Harbour 0 +V00,T4,300,kg,15,h,49,completed,Harbour 0 +V01,T2,219,kg,15,h,56,completed,Harbour 0 +V02,T5,0.613,tonne,0.5833333333333334,day,42,completed,Harbour 1 +V03,T4,220,kg,15,h,28,completed,Harbour 0 +V01,T3,0.763,tonne,0.375,day,60,completed,Harbour 1 +V01,CANCEL,99999,tonne,0.20833333333333334,day,34,cancelled,Harbour 1 +V03,T3,0.279,tonne,0.4583333333333333,day,33,completed,Harbour 1 +V01,T0,102,kg,8,h,14,completed,Harbour 0 +V02,T4,315,kg,4,h,53,completed,Harbour 0 +V03,T2,607,kg,13,h,24,completed,Harbour 0 +V02,CANCEL,99999,tonne,0.5833333333333334,day,42,cancelled,Harbour 1 +V02,T3,0.704,tonne,0.4166666666666667,day,60,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0006/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7122bee34591f7f14e3010599d93090c00bbc90d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0006/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4c5bc6736d5e892b73c112368fc466b86f16544d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 1904.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 50.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 38.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 194.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2098.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 1668.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 52.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 32.077, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 220.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 1888.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2499.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 60.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 41.65, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 276.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2775.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 2568.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 64.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 40.125, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 162.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 2730.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 8639.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0006/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0015/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..b87c0fdb582a130fdecfdb6fcd8755a022a9095b --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V02,CANCEL,99999,tonne,0.16666666666666666,day,8,cancelled,Harbour 1 +V02,T2,582,kg,7,h,12,completed,Harbour 0 +V01,T1,0.658,tonne,0.20833333333333334,day,22,completed,Harbour 1 +V00,T3,0.448,tonne,0.16666666666666666,day,15,completed,Harbour 1 +V01,T2,379,kg,16,h,41,completed,Harbour 0 +V02,T0,552,kg,10,h,31,completed,Harbour 0 +V02,T1,0.364,tonne,0.6666666666666666,day,18,completed,Harbour 1 +V03,CANCEL,99999,tonne,0.625,day,34,cancelled,Harbour 1 +V03,T3,0.381,tonne,0.625,day,10,completed,Harbour 1 +V00,T0,504,kg,9,h,43,completed,Harbour 0 +V00,T5,0.575,tonne,0.5416666666666666,day,47,completed,Harbour 1 +V03,T5,0.167,tonne,0.625,day,34,completed,Harbour 1 +V01,CANCEL,99999,tonne,0.5416666666666666,day,13,cancelled,Harbour 1 +V00,T4,498,kg,14,h,14,completed,Harbour 0 +V01,T5,0.328,tonne,0.5416666666666666,day,13,completed,Harbour 1 +V02,T5,0.271,tonne,0.16666666666666666,day,8,completed,Harbour 1 +V03,T4,100,kg,6,h,34,completed,Harbour 0 +V00,T1,0.607,tonne,0.5,day,7,completed,Harbour 1 +V01,T3,0.583,tonne,0.6666666666666666,day,26,completed,Harbour 1 +V03,T1,0.203,tonne,0.3333333333333333,day,44,completed,Harbour 1 +V00,CANCEL,99999,tonne,0.5416666666666666,day,47,cancelled,Harbour 1 +V01,T4,245,kg,5,h,20,completed,Harbour 0 +V02,T3,0.361,tonne,0.16666666666666666,day,55,completed,Harbour 1 +V00,T2,708,kg,5,h,60,completed,Harbour 0 +V01,T0,447,kg,10,h,11,completed,Harbour 0 +V02,T4,460,kg,4,h,53,completed,Harbour 0 +V03,T2,369,kg,16,h,53,completed,Harbour 0 +V03,T0,578,kg,9,h,32,completed,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0015/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ea44a2b23890d7c2fe63c652e62ec55a12f45d6e --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0015/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..036429c8193cec71ac0b19e278a86e4216781df6 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 3340.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 57.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 58.596, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 186.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 3526.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2640.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 65.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 40.615, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 133.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2773.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2590.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 45.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 57.556, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 177.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2767.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 1798.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 69.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 26.058, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 207.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 2005.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 10368.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0015/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0024/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..5e3e20d54eba887efb7ea78dd4d94210132bbf64 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V02,T2,179,kg,12,h,50,completed,Harbour 0 +V00,T5,0.711,tonne,0.6666666666666666,day,26,completed,Harbour 1 +V03,CANCEL,99999,tonne,0.375,day,41,cancelled,Harbour 1 +V00,T2,456,kg,13,h,27,completed,Harbour 0 +V03,T5,0.32,tonne,0.375,day,41,completed,Harbour 1 +V00,T4,354,kg,10,h,13,completed,Harbour 0 +V00,T3,0.658,tonne,0.5,day,35,completed,Harbour 1 +V02,T4,635,kg,16,h,23,completed,Harbour 0 +V03,T2,152,kg,6,h,26,completed,Harbour 0 +V01,T0,302,kg,15,h,53,completed,Harbour 0 +V00,CANCEL,99999,tonne,0.6666666666666666,day,26,cancelled,Harbour 1 +V01,T1,0.784,tonne,0.4583333333333333,day,5,completed,Harbour 1 +V01,T2,663,kg,4,h,60,completed,Harbour 0 +V02,T5,0.212,tonne,0.4583333333333333,day,59,completed,Harbour 1 +V02,T0,755,kg,7,h,5,completed,Harbour 0 +V02,T1,0.434,tonne,0.25,day,41,completed,Harbour 1 +V00,T0,194,kg,14,h,13,completed,Harbour 0 +V01,T3,0.636,tonne,0.5833333333333334,day,57,completed,Harbour 1 +V03,T0,529,kg,14,h,44,completed,Harbour 0 +V02,CANCEL,99999,tonne,0.4583333333333333,day,59,cancelled,Harbour 1 +V01,CANCEL,99999,tonne,0.3333333333333333,day,58,cancelled,Harbour 1 +V03,T4,431,kg,8,h,48,completed,Harbour 0 +V00,T1,0.481,tonne,0.25,day,16,completed,Harbour 1 +V01,T5,0.26,tonne,0.3333333333333333,day,58,completed,Harbour 1 +V03,T3,0.3,tonne,0.3333333333333333,day,18,completed,Harbour 1 +V01,T4,385,kg,8,h,56,completed,Harbour 0 +V02,T3,0.632,tonne,0.4166666666666667,day,27,completed,Harbour 1 +V03,T1,0.689,tonne,0.25,day,11,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0024/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..68bfcf0c9cae611df0f91be15920a8b8c2b03408 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0024/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b98ca971d6c2d4eef400b09a5cfcbb7c2c961864 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2854.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 71.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 40.197, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 130.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2984.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 3030.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 60.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 50.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 289.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 3319.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2847.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 62.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 45.919, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 205.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 3052.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 2421.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 51.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 47.471, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 188.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 2609.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 11152.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0024/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0024/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0033/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..a07f994e1c6f70dba7a3e571252de363c1100bba --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V03,CANCEL,99999,tonne,0.375,day,19,cancelled,Harbour 1 +V01,T3,0.19,tonne,0.3333333333333333,day,8,completed,Harbour 1 +V00,T1,0.485,tonne,0.20833333333333334,day,59,completed,Harbour 1 +V01,T0,731,kg,8,h,20,completed,Harbour 0 +V01,T4,704,kg,12,h,6,completed,Harbour 0 +V00,T5,0.208,tonne,0.20833333333333334,day,58,completed,Harbour 1 +V01,T5,0.56,tonne,0.20833333333333334,day,48,completed,Harbour 1 +V03,T4,586,kg,7,h,32,completed,Harbour 0 +V00,CANCEL,99999,tonne,0.20833333333333334,day,58,cancelled,Harbour 1 +V00,T2,146,kg,14,h,39,completed,Harbour 0 +V02,CANCEL,99999,tonne,0.20833333333333334,day,32,cancelled,Harbour 1 +V02,T4,800,kg,7,h,42,completed,Harbour 0 +V02,T3,0.509,tonne,0.16666666666666666,day,53,completed,Harbour 1 +V01,T1,0.187,tonne,0.4583333333333333,day,13,completed,Harbour 1 +V02,T2,264,kg,13,h,16,completed,Harbour 0 +V02,T1,0.393,tonne,0.5416666666666666,day,10,completed,Harbour 1 +V02,T0,209,kg,6,h,5,completed,Harbour 0 +V03,T3,0.503,tonne,0.16666666666666666,day,35,completed,Harbour 1 +V02,T5,0.526,tonne,0.20833333333333334,day,32,completed,Harbour 1 +V00,T0,413,kg,10,h,50,completed,Harbour 0 +V03,T2,743,kg,6,h,27,completed,Harbour 0 +V01,CANCEL,99999,tonne,0.20833333333333334,day,48,cancelled,Harbour 1 +V01,T2,672,kg,12,h,38,completed,Harbour 0 +V00,T4,511,kg,8,h,23,completed,Harbour 0 +V00,T3,0.741,tonne,0.3333333333333333,day,33,completed,Harbour 1 +V03,T1,0.526,tonne,0.4166666666666667,day,53,completed,Harbour 1 +V03,T0,169,kg,5,h,56,completed,Harbour 0 +V03,T5,0.697,tonne,0.375,day,19,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0033/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8087b4f357c9c3dda726ea675f66ecd163ba938e --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0033/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5da4aba7671b730af2d4f84cc756bdb52342699c --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2504.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 50.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 50.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 262.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2766.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 3044.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 56.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 54.357, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 133.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 3177.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2701.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 48.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 56.271, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 158.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2859.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 3224.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 41.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 78.634, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 222.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 3446.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 11473.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0033/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0033/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0042/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..bc982f84641374d6738964daba63878a04a92b4e --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V02,CANCEL,99999,tonne,0.3333333333333333,day,45,cancelled,Harbour 1 +V00,T4,333,kg,12,h,24,completed,Harbour 0 +V02,T5,0.697,tonne,0.3333333333333333,day,45,completed,Harbour 1 +V03,T0,770,kg,7,h,5,completed,Harbour 0 +V02,T4,427,kg,4,h,47,completed,Harbour 0 +V02,T2,484,kg,16,h,29,completed,Harbour 0 +V01,T1,0.694,tonne,0.16666666666666666,day,31,completed,Harbour 1 +V02,T0,446,kg,7,h,7,completed,Harbour 0 +V03,T2,138,kg,7,h,25,completed,Harbour 0 +V00,T3,0.716,tonne,0.5416666666666666,day,53,completed,Harbour 1 +V03,T1,0.664,tonne,0.4166666666666667,day,51,completed,Harbour 1 +V00,CANCEL,99999,tonne,0.5,day,13,cancelled,Harbour 1 +V03,T3,0.414,tonne,0.5,day,56,completed,Harbour 1 +V03,T4,478,kg,8,h,58,completed,Harbour 0 +V00,T5,0.286,tonne,0.5,day,13,completed,Harbour 1 +V01,T5,0.244,tonne,0.6666666666666666,day,29,completed,Harbour 1 +V02,T1,0.492,tonne,0.5833333333333334,day,10,completed,Harbour 1 +V00,T0,509,kg,12,h,49,completed,Harbour 0 +V02,T3,0.38,tonne,0.25,day,37,completed,Harbour 1 +V03,CANCEL,99999,tonne,0.375,day,56,cancelled,Harbour 1 +V01,T3,0.129,tonne,0.5416666666666666,day,57,completed,Harbour 1 +V01,T4,790,kg,13,h,31,completed,Harbour 0 +V01,CANCEL,99999,tonne,0.6666666666666666,day,29,cancelled,Harbour 1 +V01,T2,485,kg,13,h,41,completed,Harbour 0 +V00,T2,198,kg,6,h,19,completed,Harbour 0 +V01,T0,688,kg,12,h,9,completed,Harbour 0 +V03,T5,0.581,tonne,0.375,day,56,completed,Harbour 1 +V00,T1,0.274,tonne,0.375,day,35,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0042/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9571587d30972378fcb413f5a3e4f91fda262a65 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0042/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a2de59b4f78a7590fa4ca55a94590f28f6288210 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2316.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 64.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 36.188, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 193.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2509.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 3030.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 71.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 42.676, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 198.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 3228.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2926.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 55.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 53.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 175.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 3101.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 3045.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 53.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 57.453, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 251.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 3296.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 11317.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0042/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0042/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0051/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..a2b054aaa8a63d85bc0f69f394445d4a7c4cd8d7 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V01,T0,477,kg,4,h,49,completed,Harbour 0 +V02,CANCEL,99999,tonne,0.25,day,24,cancelled,Harbour 1 +V02,T4,313,kg,12,h,38,completed,Harbour 0 +V00,T4,282,kg,6,h,21,completed,Harbour 0 +V03,T2,277,kg,15,h,29,completed,Harbour 0 +V02,T3,0.53,tonne,0.5833333333333334,day,24,completed,Harbour 1 +V01,T3,0.424,tonne,0.20833333333333334,day,40,completed,Harbour 1 +V02,T1,0.428,tonne,0.375,day,8,completed,Harbour 1 +V00,T0,547,kg,13,h,39,completed,Harbour 0 +V01,T5,0.145,tonne,0.4583333333333333,day,7,completed,Harbour 1 +V03,T4,170,kg,9,h,26,completed,Harbour 0 +V00,T3,0.463,tonne,0.2916666666666667,day,37,completed,Harbour 1 +V02,T5,0.43,tonne,0.25,day,24,completed,Harbour 1 +V00,T2,241,kg,7,h,18,completed,Harbour 0 +V03,T5,0.148,tonne,0.5833333333333334,day,60,completed,Harbour 1 +V03,T1,0.627,tonne,0.25,day,51,completed,Harbour 1 +V00,T1,0.205,tonne,0.3333333333333333,day,39,completed,Harbour 1 +V01,T2,196,kg,15,h,19,completed,Harbour 0 +V02,T2,114,kg,4,h,41,completed,Harbour 0 +V00,CANCEL,99999,tonne,0.6666666666666666,day,29,cancelled,Harbour 1 +V01,T4,266,kg,4,h,7,completed,Harbour 0 +V03,T3,0.613,tonne,0.4583333333333333,day,45,completed,Harbour 1 +V01,CANCEL,99999,tonne,0.4583333333333333,day,7,cancelled,Harbour 1 +V03,T0,571,kg,7,h,46,completed,Harbour 0 +V01,T1,0.638,tonne,0.25,day,54,completed,Harbour 1 +V02,T0,339,kg,16,h,33,completed,Harbour 0 +V00,T5,0.384,tonne,0.6666666666666666,day,29,completed,Harbour 1 +V03,CANCEL,99999,tonne,0.5833333333333334,day,60,cancelled,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0051/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..94ceb0591924cb2576eff0cf8aec5cd00a8da7e8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0051/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7617747316d81ffe89ff9c2cb312326f0f96dfca --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2122.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 57.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 37.228, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 183.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2305.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2146.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 45.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 47.689, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 176.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2322.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2154.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 61.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 35.311, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 168.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2322.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 2406.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 62.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 38.806, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 257.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 2663.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 8828.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0051/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0051/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0060/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..501500ef478176189ddc9ef4c039304aec510402 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V01,T0,437,kg,9,h,56,completed,Harbour 0 +V01,T1,0.154,tonne,0.20833333333333334,day,53,completed,Harbour 1 +V00,T5,0.798,tonne,0.4583333333333333,day,34,completed,Harbour 1 +V01,T2,100,kg,14,h,41,completed,Harbour 0 +V01,T3,0.56,tonne,0.3333333333333333,day,52,completed,Harbour 1 +V03,T5,0.526,tonne,0.375,day,36,completed,Harbour 1 +V02,T1,0.175,tonne,0.2916666666666667,day,58,completed,Harbour 1 +V03,T1,0.618,tonne,0.2916666666666667,day,22,completed,Harbour 1 +V01,CANCEL,99999,tonne,0.375,day,32,cancelled,Harbour 1 +V01,T4,448,kg,6,h,26,completed,Harbour 0 +V00,T1,0.103,tonne,0.3333333333333333,day,39,completed,Harbour 1 +V02,T4,192,kg,7,h,48,completed,Harbour 0 +V00,T3,0.769,tonne,0.4583333333333333,day,52,completed,Harbour 1 +V01,T5,0.792,tonne,0.375,day,32,completed,Harbour 1 +V03,T3,0.177,tonne,0.625,day,37,completed,Harbour 1 +V02,T0,372,kg,5,h,58,completed,Harbour 0 +V00,T4,316,kg,9,h,30,completed,Harbour 0 +V02,T5,0.262,tonne,0.5416666666666666,day,11,completed,Harbour 1 +V00,CANCEL,99999,tonne,0.4583333333333333,day,34,cancelled,Harbour 1 +V03,CANCEL,99999,tonne,0.375,day,36,cancelled,Harbour 1 +V03,T4,599,kg,16,h,52,completed,Harbour 0 +V00,T2,285,kg,5,h,12,completed,Harbour 0 +V02,T2,674,kg,10,h,30,completed,Harbour 0 +V02,CANCEL,99999,tonne,0.5416666666666666,day,11,cancelled,Harbour 1 +V02,T3,0.113,tonne,0.625,day,33,completed,Harbour 1 +V03,T2,789,kg,5,h,12,completed,Harbour 0 +V00,T0,628,kg,15,h,51,completed,Harbour 0 +V03,T0,187,kg,10,h,8,completed,Harbour 0 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0060/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2799b43220aec52598f5e330d151e709aea40c1f --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0060/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..de804e6229e3c4fcbb8b3cd01608b3ea327c7640 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2899.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 59.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 49.136, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 218.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 3117.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2491.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 51.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 48.843, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 260.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2751.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 1788.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 57.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 31.368, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 238.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2026.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 2896.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 62.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 46.71, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 167.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 3063.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 10074.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0060/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0060/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0069/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..ebe48967712a27fb806f0784c68b48a594e3cc31 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V00,T2,461,kg,7,h,30,completed,Harbour 0 +V01,T0,721,kg,13,h,15,completed,Harbour 0 +V03,CANCEL,99999,tonne,0.25,day,51,cancelled,Harbour 1 +V02,T5,0.472,tonne,0.3333333333333333,day,21,completed,Harbour 1 +V03,T0,278,kg,9,h,39,completed,Harbour 0 +V00,T1,0.767,tonne,0.6666666666666666,day,5,completed,Harbour 1 +V00,T3,0.178,tonne,0.4166666666666667,day,21,completed,Harbour 1 +V00,CANCEL,99999,tonne,0.2916666666666667,day,45,cancelled,Harbour 1 +V01,T4,330,kg,16,h,52,completed,Harbour 0 +V02,T4,267,kg,8,h,49,completed,Harbour 0 +V02,T2,482,kg,8,h,38,completed,Harbour 0 +V00,T0,634,kg,12,h,12,completed,Harbour 0 +V03,T2,726,kg,4,h,18,completed,Harbour 0 +V02,T3,0.212,tonne,0.4166666666666667,day,52,completed,Harbour 1 +V01,T1,0.42,tonne,0.4583333333333333,day,9,completed,Harbour 1 +V01,CANCEL,99999,tonne,0.375,day,5,cancelled,Harbour 1 +V02,T1,0.779,tonne,0.4166666666666667,day,12,completed,Harbour 1 +V00,T4,290,kg,6,h,5,completed,Harbour 0 +V00,T5,0.595,tonne,0.2916666666666667,day,45,completed,Harbour 1 +V01,T2,484,kg,10,h,23,completed,Harbour 0 +V03,T1,0.719,tonne,0.25,day,21,completed,Harbour 1 +V01,T3,0.75,tonne,0.16666666666666666,day,41,completed,Harbour 1 +V03,T4,205,kg,7,h,55,completed,Harbour 0 +V03,T5,0.788,tonne,0.25,day,51,completed,Harbour 1 +V03,T3,0.641,tonne,0.16666666666666666,day,54,completed,Harbour 1 +V02,CANCEL,99999,tonne,0.3333333333333333,day,21,cancelled,Harbour 1 +V02,T0,383,kg,5,h,7,completed,Harbour 0 +V01,T5,0.726,tonne,0.375,day,5,completed,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0069/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0bfbe1c6cce2af18ff93b8c7707b5ca753421890 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0069/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..148a3dddb6bcd9268bc87a3778c1853ed4e6a43c --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2925.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 58.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 50.431, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 118.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 3043.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 3431.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 63.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 54.46, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 145.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 3576.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2595.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 49.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 52.959, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 179.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2774.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 3357.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 36.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 93.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 238.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 3595.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 12308.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0069/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0069/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0078/environment/Dockerfile b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/environment/workdir/trips.csv b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/environment/workdir/trips.csv new file mode 100644 index 0000000000000000000000000000000000000000..07ee94af842e17e16e89cf34a54e5a21f09b2699 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/environment/workdir/trips.csv @@ -0,0 +1,29 @@ +vessel_id,trip_id,landed,mass_unit,fishing_effort,effort_unit,discard_kg,status,port +V03,T5,0.542,tonne,0.375,day,26,completed,Harbour 1 +V00,T3,0.79,tonne,0.5833333333333334,day,40,completed,Harbour 1 +V02,T3,0.114,tonne,0.375,day,5,completed,Harbour 1 +V01,T2,477,kg,9,h,60,completed,Harbour 0 +V00,T2,385,kg,10,h,26,completed,Harbour 0 +V00,T4,102,kg,6,h,34,completed,Harbour 0 +V00,T5,0.333,tonne,0.20833333333333334,day,18,completed,Harbour 1 +V01,T0,285,kg,10,h,58,completed,Harbour 0 +V01,T4,377,kg,16,h,47,completed,Harbour 0 +V03,CANCEL,99999,tonne,0.375,day,26,cancelled,Harbour 1 +V03,T3,0.536,tonne,0.3333333333333333,day,18,completed,Harbour 1 +V01,CANCEL,99999,tonne,0.4166666666666667,day,17,cancelled,Harbour 1 +V02,T4,101,kg,4,h,56,completed,Harbour 0 +V00,T1,0.516,tonne,0.5416666666666666,day,23,completed,Harbour 1 +V02,CANCEL,99999,tonne,0.625,day,48,cancelled,Harbour 1 +V01,T3,0.64,tonne,0.5,day,38,completed,Harbour 1 +V03,T2,582,kg,12,h,8,completed,Harbour 0 +V02,T1,0.495,tonne,0.2916666666666667,day,42,completed,Harbour 1 +V02,T5,0.661,tonne,0.625,day,48,completed,Harbour 1 +V00,T0,583,kg,15,h,53,completed,Harbour 0 +V03,T1,0.134,tonne,0.16666666666666666,day,11,completed,Harbour 1 +V01,T5,0.297,tonne,0.4166666666666667,day,17,completed,Harbour 1 +V02,T0,709,kg,12,h,49,completed,Harbour 0 +V03,T0,472,kg,15,h,20,completed,Harbour 0 +V03,T4,629,kg,13,h,28,completed,Harbour 0 +V02,T2,618,kg,15,h,48,completed,Harbour 0 +V01,T1,0.569,tonne,0.375,day,57,completed,Harbour 1 +V00,CANCEL,99999,tonne,0.20833333333333334,day,18,cancelled,Harbour 1 diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/instruction.md b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cdccc1db972706ac0b4b14784c7a676f80d4059d --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: catch-effort + +`trips.csv` records fishing trips. Use only `status=completed` rows. For each vessel return `landed_kg` (sum landed mass), `effort_h` (sum fishing effort in hours), `cpue_kg_h` = pooled landed kg / pooled effort hours, `discard_kg` (sum discarded mass) and `total_removals_kg` = landed plus discarded. CPUE uses landed catch only; never average individual trip CPUEs. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `landed_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/solution/oracle.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-catch-effort-d3-t0078/solution/solve.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/task.toml b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5880e4854953fc920d59386c1c0436bb60153574 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "catch-effort", "isced-0831", "train"] +isced_f = "0831" +family = "catch-effort" +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/fishery-log/fishery-log-catch-effort-d3-t0078/tests/checks.json b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..49ecc786d0b7a9e25257b4e5d30f962fe4ac83ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.V00.landed_kg", + "type": "number", + "value": 2709.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.effort_h", + "type": "number", + "value": 63.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.cpue_kg_h", + "type": "number", + "value": 43.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.discard_kg", + "type": "number", + "value": 194.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V00.total_removals_kg", + "type": "number", + "value": 2903.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.landed_kg", + "type": "number", + "value": 2645.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.effort_h", + "type": "number", + "value": 66.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.cpue_kg_h", + "type": "number", + "value": 40.076, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.discard_kg", + "type": "number", + "value": 277.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V01.total_removals_kg", + "type": "number", + "value": 2922.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.landed_kg", + "type": "number", + "value": 2698.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.effort_h", + "type": "number", + "value": 62.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.cpue_kg_h", + "type": "number", + "value": 43.516, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.discard_kg", + "type": "number", + "value": 248.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V02.total_removals_kg", + "type": "number", + "value": 2946.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.landed_kg", + "type": "number", + "value": 2895.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.effort_h", + "type": "number", + "value": 61.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.cpue_kg_h", + "type": "number", + "value": 47.459, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.discard_kg", + "type": "number", + "value": 111.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.V03.total_removals_kg", + "type": "number", + "value": 3006.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 10947.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/tests/test.sh b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-catch-effort-d3-t0078/tests/verify.py b/tasks/fishery-log/fishery-log-catch-effort-d3-t0078/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-catch-effort-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/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..a1475f3c44a4ea5639f0c299cda91775dd6bd801 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,92,kg,fed +P00,F1,63,kg,fed +P00,F2,75,kg,fed +P00,F3,65,kg,fed +P01,F0,104,kg,fed +P01,F1,83,kg,fed +P01,F2,100,kg,fed +P01,F3,77,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..5ec07f7debe505eb5ed70454cf124536f92854e5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,613,976,0,0 +P01,644,1135,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-e0001/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..00163d4b4eb50b145a605f1972da3a64235a7bbf --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-e0001/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3dc42698326098ea9b13f3138b7dd56dc00aa071 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 363.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 295.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.813, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 491.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 364.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.741, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-e0001/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..471f0df8b8d7650d9e974dd68e5c2d4da45fab72 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,89,kg,fed +P00,F1,82,kg,fed +P00,F2,83,kg,fed +P00,F3,116,kg,fed +P01,F0,73,kg,fed +P01,F1,64,kg,fed +P01,F2,126,kg,fed +P01,F3,67,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..63ed9b89e903189f1c34d2ff8ab40ff1359b3f46 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,523,919,0,0 +P01,794,1292,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-e0010/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fadbf68053e7c5ec7f0219d369003d746a016664 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-e0010/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ad0458bb8f1a4a641301f3526641d163dffcbfd1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 396.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 370.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.934, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 498.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 330.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.663, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-e0010/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..f8e16c1b02d9100d7a4f876c48e20314d831de34 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,79,kg,fed +P00,F1,47,kg,fed +P00,F2,95,kg,fed +P00,F3,70,kg,fed +P01,F0,124,kg,fed +P01,F1,89,kg,fed +P01,F2,70,kg,fed +P01,F3,43,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..eea198481cb2467f042864895e95918a19b9a96f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,336,547,0,0 +P01,570,827,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-e0019/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1e919574666d8a63b1976183cb7edb56bfa5a48b --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-e0019/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..76c500f343322ff9e94397c4797f2a6ea78091ff --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 211.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 291.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.379, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 257.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 326.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.268, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-e0019/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-e0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..a947d69b3856a7ae82dd7b4883f9b162030a71b0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,54,kg,fed +P00,F1,111,kg,fed +P00,F2,97,kg,fed +P00,F3,41,kg,fed +P01,F0,105,kg,fed +P01,F1,37,kg,fed +P01,F2,105,kg,fed +P01,F3,117,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..8b9382f908e1379d5911cfe20ae33c63236ee16b --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,569,984,0,0 +P01,544,994,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0001/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bf6fe926104d6f713c9dfb29cd695a4f952ba70d --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0001/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6df7fdc3a318720657e2a556513c1bc8f9772e98 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 415.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 303.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.73, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 450.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 364.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.809, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0001/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..26a427fa988785b45703d91adc904d6992b16c45 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,66,kg,fed +P00,F1,66,kg,fed +P00,F2,74,kg,fed +P00,F3,81,kg,fed +P01,F0,83,kg,fed +P01,F1,76,kg,fed +P01,F2,98,kg,fed +P01,F3,130,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..eea63fcbf8ca9088cc712311415aca1516d3e568 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,339,784,0,0 +P01,523,709,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0010/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7faa0a9ef015fc9898a9b20cec837e0a407e1b43 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0010/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2e1d03666521afa69ab3bcd413f56d63fed3c562 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 445.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 287.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.645, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 186.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 387.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 2.081, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0010/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..079a29d4740810c9677c72cfa3ef199e94cc6eb1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,89,kg,fed +P00,F1,103,kg,fed +P00,F2,107,kg,fed +P00,F3,99,kg,fed +P01,F0,57,kg,fed +P01,F1,63,kg,fed +P01,F2,30,kg,fed +P01,F3,130,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..0df01e6c9f2e5c4ca8baf589dc80b6910c5287bb --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,591,825,0,0 +P01,703,1110,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0019/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0c303ab4f96f614ba7008304ca4b1c48a7f9940d --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0019/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0751746c07c21c8ca461d5d8f807c7f52c846d3f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 234.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 398.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.701, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 407.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 280.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.688, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0019/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..704e9c2286aa0f03029fa474ba512ea0d16044cc --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,113,kg,fed +P00,F1,62,kg,fed +P00,F2,96,kg,fed +P00,F3,50,kg,fed +P01,F0,102,kg,fed +P01,F1,57,kg,fed +P01,F2,55,kg,fed +P01,F3,70,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..bdc10d671ab9e0983db235281eb1000d9eb00a55 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,391,825,0,0 +P01,326,685,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0028/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..293d3b4a974fa9f51f746df0007a1fa0ed7e3aa0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0028/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..13752d4f72de3994bd93344f4f0451faacb7250d --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 434.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 321.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.74, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 359.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 284.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.791, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0028/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0028/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..990c3aef3ae3c84714390b3f611612da97ff8453 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,113,kg,fed +P00,F1,123,kg,fed +P00,F2,36,kg,fed +P00,F3,57,kg,fed +P01,F0,59,kg,fed +P01,F1,58,kg,fed +P01,F2,37,kg,fed +P01,F3,109,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..03d815a4c2f9c7b996214f80141c3c08cfd69127 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,796,1080,0,0 +P01,521,841,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0037/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d99d37f246084db6ed01218b0e8b1683165fa114 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0037/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ea19d5ad1593572d81dd9690199bd24d9d257b79 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 284.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 329.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.158, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 320.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 263.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.822, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0037/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0037/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..394d3986e61e6abd8d1a7cfc5c5a33dbe5bbda4f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,115,kg,fed +P00,F1,96,kg,fed +P00,F2,30,kg,fed +P00,F3,91,kg,fed +P01,F0,72,kg,fed +P01,F1,72,kg,fed +P01,F2,40,kg,fed +P01,F3,125,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..a39b3cc077d29530e57cd2b2aa51172c6681db0d --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,566,818,0,0 +P01,350,709,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0046/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2d253d13ade88f69dcdd58bc5394699925737af0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0046/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2ba0192c4c82fe2108e62c04285d1b0e31da9bc3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 252.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 332.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.317, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 359.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 309.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.861, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0046/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0046/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..16fdb9631028413d9f1bcb3fa7b7b015f09b9522 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,103,kg,fed +P00,F1,113,kg,fed +P00,F2,102,kg,fed +P00,F3,49,kg,fed +P01,F0,124,kg,fed +P01,F1,103,kg,fed +P01,F2,72,kg,fed +P01,F3,81,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..d776ffbfacf4292c8f60c68f51ae3f1f65c3b617 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,595,879,0,0 +P01,404,814,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0055/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4ad5d0c09d3428b1ca7f686199596f8ea3dcd772 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0055/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4aac025a5571b7bffa3398e021979525d47531fe --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 284.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 367.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.292, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 410.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 380.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.927, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0055/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0055/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..e68cf2ec102d509b18666b1257ae4f29426d1e96 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,104,kg,fed +P00,F1,64,kg,fed +P00,F2,99,kg,fed +P00,F3,79,kg,fed +P01,F0,124,kg,fed +P01,F1,52,kg,fed +P01,F2,126,kg,fed +P01,F3,126,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..a44329bb9feaa2547e22a0abd26bbec2c065e5e1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,492,953,0,0 +P01,593,862,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0064/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d7b1bb00e144cc5c6371dd463918b92e4d5ae390 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0064/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e06c960b1e7c107c0741bab9980a3623d1850493 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 461.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 346.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.751, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 269.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 428.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.591, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0064/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0064/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..ba42cca61de36dbfcc5990a70079016234cbf238 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,110,kg,fed +P00,F1,117,kg,fed +P00,F2,52,kg,fed +P00,F3,99,kg,fed +P01,F0,91,kg,fed +P01,F1,51,kg,fed +P01,F2,68,kg,fed +P01,F3,127,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..862439f0721b4853377ea113cca04269dc8b41f0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,395,643,0,0 +P01,317,615,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0073/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a1863c50e6797924f2b40ae9f5e3e36813ebfeb8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0073/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..873a74667c8f64b678f2b605e6a1680019d05353 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 248.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 378.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.524, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 298.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 337.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.131, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0073/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0073/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..2603c803af1529da09714f775e602351c49e54dc --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/workdir/feed.csv @@ -0,0 +1,9 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,31,kg,fed +P00,F1,53,kg,fed +P00,F2,80,kg,fed +P00,F3,99,kg,fed +P01,F0,59,kg,fed +P01,F1,88,kg,fed +P01,F2,68,kg,fed +P01,F3,75,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..cc60e5993239c22b8574befce1ae6089a4cbb24c --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/environment/workdir/stocks.csv @@ -0,0 +1,3 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,694,1083,0,0 +P01,668,937,0,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d1-t0082/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6881c8385c324ac1bf773d4ee11cbc11e7440b97 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d1-t0082/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..81cdd8bcf1109988f97d97a9d64471d001713dbc --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 389.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 263.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.676, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 269.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 290.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.078, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d1-t0082/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d1-t0082/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..5ee453f033431c1aecc6c98395d65bedb1c7ec63 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P01,F0,76,kg,fed +P00,DELIVERY,99999,kg,delivery +P01,DELIVERY,99999,kg,delivery +P01,F3,35,kg,fed +P02,DELIVERY,99999,kg,delivery +P00,F4,99,kg,fed +P00,F2,35,kg,fed +P02,F1,96,kg,fed +P00,F0,96,kg,fed +P01,F2,98,kg,fed +P02,F2,70,kg,fed +P00,F1,118,kg,fed +P00,F3,72,kg,fed +P02,F4,52,kg,fed +P02,F0,128,kg,fed +P01,F4,85,kg,fed +P02,F3,87,kg,fed +P01,F1,65,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..10c15de3dab3dc5b1a01d047e56e74a4dc458899 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,393,597,137,0 +P00,426,745,50,0 +P02,309,687,95,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-e0004/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8f63c92a7fe9a0d30805d6ecab65092011d89bb1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-e0004/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5957ab256f970e6982995e9be0be08dd853d8b71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 369.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 420.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.138, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 341.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 359.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.053, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 473.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 433.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.915, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-e0004/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..6c634484793bd622703ffd44143517b677f352de --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F1,95,kg,fed +P01,F4,60,kg,fed +P00,F0,46,kg,fed +P02,F1,124,kg,fed +P01,F3,94,kg,fed +P01,F0,94,kg,fed +P02,F3,107,kg,fed +P02,F4,57,kg,fed +P01,DELIVERY,99999,kg,delivery +P01,F1,69,kg,fed +P02,F2,44,kg,fed +P02,F0,84,kg,fed +P00,F3,70,kg,fed +P02,DELIVERY,99999,kg,delivery +P01,F2,117,kg,fed +P00,DELIVERY,99999,kg,delivery +P00,F4,41,kg,fed +P00,F2,115,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..81e202402f5502041c4514742ced116901e79062 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P02,435,717,140,0 +P01,578,795,106,0 +P00,777,976,109,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-e0013/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..164dce863566e42ab2de75bba0d6325866234393 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-e0013/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9a379c22c11c7c841637b997c585ca9b6059ad99 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 308.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 367.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.192, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 323.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 434.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.344, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 422.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 416.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.986, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-e0013/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..0583993c317f30f51c0e2c9b467396c00cc72e57 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F0,114,kg,fed +P02,DELIVERY,99999,kg,delivery +P01,F1,59,kg,fed +P01,F4,125,kg,fed +P02,F3,74,kg,fed +P00,F3,79,kg,fed +P00,F2,95,kg,fed +P02,F4,41,kg,fed +P01,F0,64,kg,fed +P00,F1,63,kg,fed +P00,F4,89,kg,fed +P01,F3,53,kg,fed +P01,DELIVERY,99999,kg,delivery +P02,F1,91,kg,fed +P02,F2,91,kg,fed +P02,F0,61,kg,fed +P01,F2,45,kg,fed +P00,DELIVERY,99999,kg,delivery diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..f65e987657a171d45ae688a194dca6338bc9a3fe --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,414,623,57,0 +P02,553,1047,180,0 +P01,328,788,69,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-e0022/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2ff148e8722208c11e580de080b6eda68c958878 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-e0022/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..204295d6fca313a307f591402f72e8ea4d12b9a5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 266.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 440.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.654, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 529.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 346.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.654, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 674.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 358.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.531, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-e0022/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-e0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..affeada361fbc30c76766a198fde611efb065db1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P01,DELIVERY,99999,kg,delivery +P00,F0,79,kg,fed +P00,F2,101,kg,fed +P02,F4,101,kg,fed +P00,F3,90,kg,fed +P02,DELIVERY,99999,kg,delivery +P01,F1,78,kg,fed +P00,F4,82,kg,fed +P02,F0,129,kg,fed +P02,F2,44,kg,fed +P00,DELIVERY,99999,kg,delivery +P01,F2,102,kg,fed +P02,F3,36,kg,fed +P01,F0,64,kg,fed +P02,F1,86,kg,fed +P01,F3,74,kg,fed +P01,F4,77,kg,fed +P00,F1,96,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..7e7e1693c52c9d8fa352d06bd4c3ecd542e38140 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,651,1054,75,0 +P01,672,910,111,0 +P02,462,612,73,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0004/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e7dc96b677fa836720ed377c731258f73d8e1518 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0004/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1348e89c087b3264e268c7bdad1c0eb7337fcd45 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 478.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 448.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.937, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 349.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 395.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.132, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 223.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 396.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.776, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0004/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..d0bdd964f8cd7c9e1bc8d5a4cc5f44beacc3c965 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P02,F3,102,kg,fed +P00,F4,85,kg,fed +P02,F2,38,kg,fed +P02,F0,66,kg,fed +P00,F0,120,kg,fed +P00,DELIVERY,99999,kg,delivery +P02,F1,110,kg,fed +P01,F2,124,kg,fed +P01,DELIVERY,99999,kg,delivery +P00,F2,42,kg,fed +P02,F4,49,kg,fed +P01,F3,108,kg,fed +P02,DELIVERY,99999,kg,delivery +P00,F1,118,kg,fed +P00,F3,93,kg,fed +P01,F4,53,kg,fed +P01,F1,103,kg,fed +P01,F0,63,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..801f19776eb1337d9d941f2758e27d7e914db499 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,365,720,148,0 +P02,730,1181,73,0 +P01,409,832,91,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0013/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..64c4eb9a9a83eb6fc7696c62a6b0318c5c43077c --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0013/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4d8c529b703587580401c7f8cda5a8c85a91623d --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 503.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 458.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.911, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 514.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 451.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.877, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 524.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 365.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.697, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0013/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..f75fb8695f65a1b82cf03468e61d534d24a1f423 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P00,DELIVERY,99999,kg,delivery +P02,F3,105,kg,fed +P01,F3,74,kg,fed +P01,F2,85,kg,fed +P02,DELIVERY,99999,kg,delivery +P00,F4,35,kg,fed +P02,F1,103,kg,fed +P02,F0,55,kg,fed +P00,F0,109,kg,fed +P00,F3,54,kg,fed +P01,F0,42,kg,fed +P00,F1,85,kg,fed +P02,F4,94,kg,fed +P01,DELIVERY,99999,kg,delivery +P01,F4,93,kg,fed +P01,F1,104,kg,fed +P00,F2,46,kg,fed +P02,F2,74,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..6c5a8a9c57e0e863092bef16dbe7c2ee6d4aa0cc --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,348,736,170,0 +P02,508,998,83,0 +P00,337,561,134,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0022/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f535078765e7af4626275c8a6de72bcef13b7165 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0022/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..924428ed5b24f78c2e4745db1b0141604e0a3e2c --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 358.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 329.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.919, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 558.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 398.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.713, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 573.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 431.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.752, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0022/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..a7c7df65c81c4b354d7e6d87833848fdcaa6dc87 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P01,DELIVERY,99999,kg,delivery +P01,F4,118,kg,fed +P02,F0,103,kg,fed +P01,F2,62,kg,fed +P00,F4,98,kg,fed +P01,F1,44,kg,fed +P01,F3,40,kg,fed +P00,DELIVERY,99999,kg,delivery +P02,DELIVERY,99999,kg,delivery +P02,F3,111,kg,fed +P02,F2,78,kg,fed +P02,F4,64,kg,fed +P00,F1,51,kg,fed +P00,F0,50,kg,fed +P00,F3,63,kg,fed +P00,F2,107,kg,fed +P01,F0,95,kg,fed +P02,F1,99,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..d9cb27cc90b6adf58f59e92ab27f91a3dc909f28 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,479,730,176,0 +P02,748,1167,145,0 +P00,519,736,127,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0031/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5ec8af6e70b77d64da31f504f1d48e775dc65aeb --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0031/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4ddf6578d92efee2d86259b25b0a25d264c94052 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 344.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 369.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.073, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 427.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 359.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.841, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 564.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 455.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.807, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0031/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0031/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..07a0e592ae71cfcd99c2d456624777ace009ec51 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P01,F4,88,kg,fed +P02,F2,88,kg,fed +P01,DELIVERY,99999,kg,delivery +P00,DELIVERY,99999,kg,delivery +P01,F3,110,kg,fed +P02,F0,84,kg,fed +P00,F2,66,kg,fed +P01,F2,86,kg,fed +P02,F4,109,kg,fed +P00,F0,71,kg,fed +P01,F0,119,kg,fed +P00,F4,125,kg,fed +P00,F1,90,kg,fed +P02,DELIVERY,99999,kg,delivery +P02,F3,130,kg,fed +P01,F1,42,kg,fed +P00,F3,65,kg,fed +P02,F1,122,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..c5ec156d145270eb28a516be04183ac135d81671 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P02,448,914,51,0 +P01,558,1008,200,0 +P00,655,942,159,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0040/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a4c6e0a448298ddd2d77610d21c900b57a5923ea --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0040/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b5cdc20d9d4da66b5a4bd1e2bcb54f5666726e3c --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 446.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 417.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.935, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 650.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 445.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.685, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 517.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 533.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.031, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0040/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0040/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..f1d625e3746ca059533f3c70fd7e461f7de3eec9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P01,F1,98,kg,fed +P00,DELIVERY,99999,kg,delivery +P00,F4,87,kg,fed +P02,F2,96,kg,fed +P01,F4,103,kg,fed +P01,DELIVERY,99999,kg,delivery +P02,F4,47,kg,fed +P00,F2,39,kg,fed +P00,F1,52,kg,fed +P00,F3,57,kg,fed +P02,F3,119,kg,fed +P02,DELIVERY,99999,kg,delivery +P02,F0,55,kg,fed +P02,F1,95,kg,fed +P01,F3,83,kg,fed +P01,F0,83,kg,fed +P01,F2,47,kg,fed +P00,F0,42,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..6719302c4abda92c6513707c878a878c6670781d --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P02,679,1059,87,0 +P00,599,917,81,0 +P01,380,821,85,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0049/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cae5ed63b6970674e4bba77297802e71226553f0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0049/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4ab0221e9e62f72116d79c9d8f36927c22c48c88 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 399.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 277.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.694, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 526.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 414.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.787, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 467.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 412.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.882, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0049/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0049/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..41f827f274a526bd3300ffc4042f5b016f1d426e --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F3,54,kg,fed +P01,F0,70,kg,fed +P02,DELIVERY,99999,kg,delivery +P01,F3,56,kg,fed +P02,F4,94,kg,fed +P01,DELIVERY,99999,kg,delivery +P00,F2,106,kg,fed +P00,F1,90,kg,fed +P00,DELIVERY,99999,kg,delivery +P01,F2,30,kg,fed +P02,F0,63,kg,fed +P02,F3,107,kg,fed +P02,F2,45,kg,fed +P00,F0,94,kg,fed +P01,F1,76,kg,fed +P00,F4,85,kg,fed +P01,F4,60,kg,fed +P02,F1,102,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..cfe491484af66298dccbf39ce4bf001808e076aa --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,616,1114,93,0 +P02,587,982,192,0 +P01,678,923,130,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0058/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b573b5b2d6111e44833cc452c4ec30ad488285aa --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0058/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..986e7ecf9a4b859da5caa0a35b6933205f7ebd8b --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 591.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 429.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.726, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 375.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 292.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.779, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 587.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 411.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.7, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0058/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0058/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..8738410e888e93d9a030117633e79fca99e2c1dc --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P02,F4,122,kg,fed +P01,F1,92,kg,fed +P01,F2,99,kg,fed +P00,DELIVERY,99999,kg,delivery +P00,F2,41,kg,fed +P02,DELIVERY,99999,kg,delivery +P01,F4,84,kg,fed +P01,F3,57,kg,fed +P02,F3,37,kg,fed +P01,F0,128,kg,fed +P00,F0,92,kg,fed +P00,F1,100,kg,fed +P00,F3,86,kg,fed +P01,DELIVERY,99999,kg,delivery +P02,F2,107,kg,fed +P00,F4,95,kg,fed +P02,F0,108,kg,fed +P02,F1,83,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..18ecef0a27d85ecb5fa1cf9aa14a112f21f10d17 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,791,983,96,0 +P02,405,653,77,0 +P01,706,1009,129,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0067/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a03248ba32897551b2c222a62186604b8262086b --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0067/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..95e7ea29143d4eab06010b23c529aa68cbdda3eb --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 288.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 414.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.438, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 432.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 460.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.065, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 325.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 457.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.406, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0067/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0067/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..86e7a049bcbab688e58fe0fe37d61061ef6e7054 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/workdir/feed.csv @@ -0,0 +1,19 @@ +pond_id,entry_id,feed,feed_unit,status +P01,F1,78,kg,fed +P00,F3,80,kg,fed +P01,DELIVERY,99999,kg,delivery +P02,F0,85,kg,fed +P01,F3,90,kg,fed +P00,F0,65,kg,fed +P01,F4,36,kg,fed +P00,DELIVERY,99999,kg,delivery +P01,F0,86,kg,fed +P02,F4,56,kg,fed +P01,F2,93,kg,fed +P00,F1,100,kg,fed +P00,F2,87,kg,fed +P02,F3,130,kg,fed +P02,F2,79,kg,fed +P02,DELIVERY,99999,kg,delivery +P00,F4,104,kg,fed +P02,F1,70,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..c080f55503a91b13036b83b2656d9be8011222bf --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/environment/workdir/stocks.csv @@ -0,0 +1,4 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,712,982,193,0 +P00,499,699,184,0 +P02,491,667,74,0 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9207e6730d29ca5037296fc312efb345c57c09be --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d2-t0076/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..caf3feb6021de788766be8bddbb291496ab4b181 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d2-t0076/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ab4d586d9cd941250d1e8206fc283f7bbb97654f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 384.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 436.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.135, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 463.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 383.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.827, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 250.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 420.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.68, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d2-t0076/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d2-t0076/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..53f7fe5767fde2b3999db349b41f7e9edc1f068f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P00,DELIVERY,99999,g,delivery +P02,DELIVERY,99999,g,delivery +P00,F5,125000,g,fed +P02,F0,69,kg,fed +P03,F5,31000,g,fed +P00,F0,43,kg,fed +P02,F5,82000,g,fed +P01,F1,47000,g,fed +P00,F2,105,kg,fed +P03,F1,125000,g,fed +P02,F4,100,kg,fed +P01,F2,58,kg,fed +P01,DELIVERY,99999,g,delivery +P03,F0,82,kg,fed +P01,F0,90,kg,fed +P00,F3,30000,g,fed +P01,F3,100000,g,fed +P03,F2,44,kg,fed +P03,F3,85000,g,fed +P03,DELIVERY,99999,g,delivery +P01,F5,54000,g,fed +P01,F4,109,kg,fed +P02,F1,64000,g,fed +P03,F4,92,kg,fed +P02,F3,87000,g,fed +P00,F1,76000,g,fed +P00,F4,76,kg,fed +P02,F2,56,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..b6b5e9b1597d647a18cfb362dc6ca4d002b69d83 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,387,659,80,13 +P02,785,1168,105,18 +P00,455,738,64,33 +P03,469,932,177,22 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-e0007/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4561e70e5811bf243cdda8f2e49381a9a33657e7 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-e0007/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0ebcfa9a6d1c71544983914a917e2601f2d8e075 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 314.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 455.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.449, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 339.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 458.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.351, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 470.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 458.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.974, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 618.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 459.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 0.743, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1741.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-e0007/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..faae2359f218d8b3eb7b974e4574abdd838343b9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P02,F0,83,kg,fed +P00,F0,92,kg,fed +P00,DELIVERY,99999,g,delivery +P00,F2,40,kg,fed +P00,F1,104000,g,fed +P01,DELIVERY,99999,g,delivery +P02,DELIVERY,99999,g,delivery +P03,F4,115,kg,fed +P02,F4,40,kg,fed +P02,F5,98000,g,fed +P01,F1,119000,g,fed +P03,F1,98000,g,fed +P01,F0,112,kg,fed +P01,F2,64,kg,fed +P02,F1,119000,g,fed +P03,F5,64000,g,fed +P00,F4,90,kg,fed +P00,F3,128000,g,fed +P01,F3,106000,g,fed +P01,F4,77,kg,fed +P01,F5,94000,g,fed +P03,F3,78000,g,fed +P03,F2,103,kg,fed +P03,DELIVERY,99999,g,delivery +P02,F3,59000,g,fed +P03,F0,117,kg,fed +P00,F5,37000,g,fed +P02,F2,94,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..0b9a7ec1b4b84e5ad73f7226baee9d66a930977f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,429,631,150,27 +P00,567,899,104,25 +P03,786,1059,58,28 +P02,307,739,100,25 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-e0016/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..633b728b12d8d55121efc99b700e2d8218454bdf --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "eval"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-e0016/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0d8578944e6b6a6646f1ae77d3bdf1de880ae9fe --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 411.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 491.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.195, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 325.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 572.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 507.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 493.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.972, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 303.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 575.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 1.898, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1546.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-e0016/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-e0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..20bea97ab85233cdc194a24a8a5b0301b365c51e --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P02,F0,107,kg,fed +P00,F0,121,kg,fed +P03,F3,36000,g,fed +P01,DELIVERY,99999,g,delivery +P00,F1,61000,g,fed +P00,F3,90000,g,fed +P01,F0,60,kg,fed +P02,DELIVERY,99999,g,delivery +P03,F2,130,kg,fed +P03,F0,69,kg,fed +P01,F4,123,kg,fed +P03,F5,43000,g,fed +P02,F3,39000,g,fed +P02,F2,50,kg,fed +P01,F2,88,kg,fed +P00,F4,125,kg,fed +P01,F5,106000,g,fed +P00,F5,56000,g,fed +P02,F4,106,kg,fed +P03,F4,66,kg,fed +P01,F1,34000,g,fed +P00,DELIVERY,99999,g,delivery +P01,F3,59000,g,fed +P02,F1,47000,g,fed +P03,F1,34000,g,fed +P03,DELIVERY,99999,g,delivery +P02,F5,75000,g,fed +P00,F2,105,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..868bc7b4927e8cec2b3d67f1a223b72f34f5b378 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P02,402,557,99,32 +P01,659,1008,185,35 +P00,581,829,157,31 +P03,443,936,68,20 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0007/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..df74d03eea61d8c824d00e7e24a54428771d20fd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0007/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..aee7988710257dd7196b3b2fc22009733975f3b6 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 374.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 558.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.492, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 499.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 470.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.942, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 222.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 424.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 541.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 378.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 0.699, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1636.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0007/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..d0fe7a4c3f3a03a7f21550db6b84f6eaf958ab15 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F4,85,kg,fed +P01,DELIVERY,99999,g,delivery +P01,F3,125000,g,fed +P00,DELIVERY,99999,g,delivery +P03,F4,37,kg,fed +P02,F5,30000,g,fed +P02,F3,82000,g,fed +P01,F4,116,kg,fed +P02,F4,96,kg,fed +P03,F0,76,kg,fed +P03,F1,102000,g,fed +P01,F5,125000,g,fed +P03,F3,93000,g,fed +P01,F0,63,kg,fed +P02,DELIVERY,99999,g,delivery +P03,F5,30000,g,fed +P00,F1,62000,g,fed +P03,DELIVERY,99999,g,delivery +P03,F2,50,kg,fed +P01,F1,100000,g,fed +P02,F1,113000,g,fed +P01,F2,65,kg,fed +P02,F2,48,kg,fed +P00,F5,59000,g,fed +P00,F3,121000,g,fed +P02,F0,31,kg,fed +P00,F0,70,kg,fed +P00,F2,91,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..2198b4a401a4f9bec06eeb9526e6851a0d01b366 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P02,382,842,61,31 +P00,402,791,138,13 +P03,595,762,135,13 +P01,745,1095,154,39 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0016/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..abfa3e58262786d5538d0b1b26fb6acefb80442c --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0016/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7ebaa8e229cb0988ab1b12f7cf3fbf446ed41d28 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 514.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 488.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.949, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 465.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 594.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.277, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 490.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 400.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.816, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 289.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 388.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 1.343, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1758.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0016/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..f524ccb9628e78c14b55798a473b6bb8fb4b869f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P03,F1,76000,g,fed +P03,F4,127,kg,fed +P00,F0,39,kg,fed +P02,F2,87,kg,fed +P00,F1,95000,g,fed +P01,F0,72,kg,fed +P02,F4,48,kg,fed +P03,F2,38,kg,fed +P01,F2,35,kg,fed +P02,F5,119000,g,fed +P01,F4,50,kg,fed +P03,DELIVERY,99999,g,delivery +P00,F4,62,kg,fed +P02,F0,30,kg,fed +P03,F0,66,kg,fed +P00,F2,49,kg,fed +P01,F3,70000,g,fed +P02,F3,32000,g,fed +P01,DELIVERY,99999,g,delivery +P00,F5,74000,g,fed +P00,F3,60000,g,fed +P03,F5,77000,g,fed +P01,F5,83000,g,fed +P02,DELIVERY,99999,g,delivery +P00,DELIVERY,99999,g,delivery +P02,F1,81000,g,fed +P03,F3,95000,g,fed +P01,F1,106000,g,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..ffd978560703d213b97dda9165993db20e9ac2bd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,362,560,162,35 +P00,452,834,125,25 +P03,386,554,153,34 +P02,546,808,170,38 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0025/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cf0bb0769c02aad9e50dc9d37103b78289b09ce5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0025/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..67e3541784c7fe98cdf3b1de7a5d906b8aa0a31f --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 482.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 379.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.786, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 325.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 416.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 394.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 397.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.008, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 287.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 479.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 1.669, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1488.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0025/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0025/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..ed3874d3ff212f3b7d373cbc9b09ef4a7aa07238 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P00,F3,56000,g,fed +P03,F5,119000,g,fed +P02,F1,115000,g,fed +P00,F0,115,kg,fed +P02,F0,78,kg,fed +P00,DELIVERY,99999,g,delivery +P02,F3,93000,g,fed +P01,F1,73000,g,fed +P00,F4,100,kg,fed +P03,F0,71,kg,fed +P01,F5,109000,g,fed +P02,F5,90000,g,fed +P03,F4,122,kg,fed +P00,F5,78000,g,fed +P03,F3,101000,g,fed +P01,F0,118,kg,fed +P02,DELIVERY,99999,g,delivery +P01,F3,105000,g,fed +P03,F2,70,kg,fed +P00,F1,95000,g,fed +P03,F1,37000,g,fed +P01,F2,104,kg,fed +P00,F2,76,kg,fed +P02,F2,113,kg,fed +P02,F4,30,kg,fed +P01,F4,37,kg,fed +P01,DELIVERY,99999,g,delivery +P03,DELIVERY,99999,g,delivery diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..1578665f85bd5218887941a533ec21af5f44f1a2 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P03,512,977,115,39 +P02,745,1234,57,34 +P00,382,749,63,22 +P01,636,997,147,30 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0034/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9d21692e3cc69d516f9c167ad87da794b1555557 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0034/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0ed36ba5e8ba30faede07f7dd090acb8a82e6659 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 408.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 520.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.275, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 478.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 546.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.142, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 512.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 519.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.014, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 541.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 520.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 0.961, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1939.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0034/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0034/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..2de82b3a58682df94568447ec54f83c0897d4564 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P00,DELIVERY,99999,g,delivery +P00,F0,54,kg,fed +P03,F5,77000,g,fed +P02,F1,35000,g,fed +P01,F0,110,kg,fed +P01,DELIVERY,99999,g,delivery +P00,F4,56,kg,fed +P00,F2,73,kg,fed +P03,F0,79,kg,fed +P00,F5,33000,g,fed +P03,F4,125,kg,fed +P01,F5,115000,g,fed +P02,F4,39,kg,fed +P03,F3,109000,g,fed +P00,F1,64000,g,fed +P02,DELIVERY,99999,g,delivery +P02,F2,44,kg,fed +P01,F1,58000,g,fed +P02,F0,53,kg,fed +P03,F2,60,kg,fed +P01,F3,117000,g,fed +P02,F5,90000,g,fed +P01,F2,52,kg,fed +P01,F4,57,kg,fed +P02,F3,42000,g,fed +P03,DELIVERY,99999,g,delivery +P03,F1,43000,g,fed +P00,F3,114000,g,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..bdee6b065236a645cdf6372991741fd05df55e17 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,328,520,158,14 +P00,446,867,150,24 +P02,792,951,108,28 +P03,376,784,188,22 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0043/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..54e13ef49d6a2cb7857115bb0ce0f87d03017e08 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0043/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b96c8b08919b3cf92572c3a2697afbca79e745a3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 547.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 394.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 336.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 509.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.515, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 239.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 303.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.268, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 574.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 493.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 0.859, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1696.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0043/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0043/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..db3b4d77d6620be05e0dd26abef78f19ce96a82b --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P02,F1,115000,g,fed +P01,F3,126000,g,fed +P01,F1,126000,g,fed +P03,F1,78000,g,fed +P01,F2,87,kg,fed +P00,F1,104000,g,fed +P02,F5,92000,g,fed +P00,DELIVERY,99999,g,delivery +P02,F3,119000,g,fed +P01,F4,99,kg,fed +P00,F4,93,kg,fed +P02,DELIVERY,99999,g,delivery +P03,F0,107,kg,fed +P03,F5,50000,g,fed +P02,F0,59,kg,fed +P00,F2,32,kg,fed +P01,DELIVERY,99999,g,delivery +P00,F5,73000,g,fed +P02,F2,36,kg,fed +P03,F3,65000,g,fed +P01,F0,84,kg,fed +P03,F4,85,kg,fed +P00,F0,109,kg,fed +P03,DELIVERY,99999,g,delivery +P01,F5,130000,g,fed +P00,F3,85000,g,fed +P03,F2,97,kg,fed +P02,F4,74,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..3d33e8157ebe6bbd6c6bf9d38fe7d6847ac34131 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P02,376,653,55,28 +P00,578,1008,59,25 +P03,391,803,137,32 +P01,319,512,80,12 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0052/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6f98c3806cf0d0aa2b9de7d1af54beca578e3ce5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0052/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a0f2f5f2ce5e48bbb00ba523c6c6a8f52dbc0e62 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 464.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 496.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.069, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 261.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 652.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 2.498, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 304.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 495.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.628, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 517.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 482.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 0.932, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1546.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0052/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0052/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..9fc7198d181a54fccfa6990f5849f22cfff94e42 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P00,DELIVERY,99999,g,delivery +P01,F0,105,kg,fed +P02,F2,79,kg,fed +P01,F1,65000,g,fed +P03,F0,91,kg,fed +P00,F4,124,kg,fed +P03,F2,48,kg,fed +P00,F2,43,kg,fed +P00,F1,65000,g,fed +P03,F1,99000,g,fed +P02,F1,67000,g,fed +P02,F0,56,kg,fed +P01,F5,105000,g,fed +P03,DELIVERY,99999,g,delivery +P02,F4,101,kg,fed +P01,F4,34,kg,fed +P02,F5,85000,g,fed +P03,F3,81000,g,fed +P01,DELIVERY,99999,g,delivery +P02,F3,125000,g,fed +P01,F3,71000,g,fed +P00,F5,72000,g,fed +P00,F0,89,kg,fed +P03,F5,89000,g,fed +P00,F3,124000,g,fed +P01,F2,92,kg,fed +P03,F4,100,kg,fed +P02,DELIVERY,99999,g,delivery diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..a58bd40dd0a987de7e81bbb31648c38d99192424 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P01,624,952,103,22 +P03,622,910,52,16 +P02,781,964,129,27 +P00,697,928,79,19 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0061/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a053b50cd7f70dd836163a7d4bc161c98a9601f2 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0061/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..022a38924f5c7439b436497419f37bc29271c390 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 291.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 517.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 1.777, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 409.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 472.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.154, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 285.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 513.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 324.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 508.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 1.568, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1309.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0061/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0061/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..35d509f6a8c4d1b354cc586d806dfaa27c4738a8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P02,F2,88,kg,fed +P03,F3,106000,g,fed +P03,F4,69,kg,fed +P03,F5,89000,g,fed +P00,F4,61,kg,fed +P02,F4,69,kg,fed +P01,F0,60,kg,fed +P02,F0,119,kg,fed +P00,F2,48,kg,fed +P01,F1,107000,g,fed +P02,F3,73000,g,fed +P02,DELIVERY,99999,g,delivery +P03,F0,76,kg,fed +P00,F0,127,kg,fed +P01,F4,118,kg,fed +P00,F3,80000,g,fed +P03,F2,72,kg,fed +P01,F3,91000,g,fed +P01,F2,40,kg,fed +P00,F1,51000,g,fed +P01,F5,83000,g,fed +P00,DELIVERY,99999,g,delivery +P02,F1,105000,g,fed +P02,F5,84000,g,fed +P03,DELIVERY,99999,g,delivery +P00,F5,125000,g,fed +P03,F1,109000,g,fed +P01,DELIVERY,99999,g,delivery diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..84f2259d9db8d6ebb47b66055ee85e3247b7cf8e --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P03,724,937,112,12 +P00,311,806,122,18 +P01,697,916,164,32 +P02,616,987,153,28 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0070/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b67c8ba1574b89732d67a2ec075099fbe53d101d --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0070/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..dea7ac50a45e92317e006fcd2de8bb17b0384678 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 599.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 492.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.821, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 351.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 499.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 1.422, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 496.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 538.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 1.085, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 313.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 521.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 1.665, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1759.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0070/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0070/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/Dockerfile b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/workdir/feed.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/workdir/feed.csv new file mode 100644 index 0000000000000000000000000000000000000000..58c3513be33e220fa6cdcdecb36a80a4ac31eab0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/workdir/feed.csv @@ -0,0 +1,29 @@ +pond_id,entry_id,feed,feed_unit,status +P02,F1,33000,g,fed +P00,F4,60,kg,fed +P00,F0,50,kg,fed +P03,F2,30,kg,fed +P01,F1,50000,g,fed +P03,F1,58000,g,fed +P03,F0,32,kg,fed +P00,F2,72,kg,fed +P02,F5,35000,g,fed +P00,F3,77000,g,fed +P02,F2,46,kg,fed +P00,F5,50000,g,fed +P00,F1,93000,g,fed +P03,F5,93000,g,fed +P01,F3,63000,g,fed +P02,F3,39000,g,fed +P03,F4,103,kg,fed +P01,DELIVERY,99999,g,delivery +P01,F5,40000,g,fed +P02,F4,113,kg,fed +P02,F0,30,kg,fed +P02,DELIVERY,99999,g,delivery +P00,DELIVERY,99999,g,delivery +P01,F2,68,kg,fed +P03,F3,43000,g,fed +P01,F0,74,kg,fed +P03,DELIVERY,99999,g,delivery +P01,F4,118,kg,fed diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/workdir/stocks.csv b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/workdir/stocks.csv new file mode 100644 index 0000000000000000000000000000000000000000..115d421792ee506ea7c861328692cb9d003b1541 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/environment/workdir/stocks.csv @@ -0,0 +1,5 @@ +pond_id,opening_kg,closing_kg,harvested_kg,stocked_kg +P00,706,1195,166,27 +P01,657,1053,144,39 +P02,616,788,194,10 +P03,454,703,144,26 diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/instruction.md b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..589806fd6dde2f451c18594e40fa07ef647a3421 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: feed-conversion + +`stocks.csv` gives opening and closing live biomass, fish harvested out and fish stocked in during the same period. `feed.csv` records feed movements; only `status=fed` was actually fed (delivery records are not consumption). Return per pond `net_production_kg` = closing + harvested - opening - stocked, `feed_kg` = total fed mass, and `fcr` = fed mass/net production. Production is positive in all tasks. Feed is recorded on a consistent as-fed basis. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `net_production_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/solution/oracle.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-feed-conversion-d3-t0079/solution/solve.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/task.toml b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3240980bf5a7fd323e7e97b12e19bef7ae008c28 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "feed-conversion", "isced-0831", "train"] +isced_f = "0831" +family = "feed-conversion" +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/fishery-log/fishery-log-feed-conversion-d3-t0079/tests/checks.json b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4e698d3985210fd9cd572658a1f7fd1f4d7c4213 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.P00.net_production_kg", + "type": "number", + "value": 628.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.feed_kg", + "type": "number", + "value": 402.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.fcr", + "type": "number", + "value": 0.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.net_production_kg", + "type": "number", + "value": 501.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.feed_kg", + "type": "number", + "value": 413.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.fcr", + "type": "number", + "value": 0.824, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.net_production_kg", + "type": "number", + "value": 356.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.feed_kg", + "type": "number", + "value": 296.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.fcr", + "type": "number", + "value": 0.831, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.net_production_kg", + "type": "number", + "value": 367.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.feed_kg", + "type": "number", + "value": 359.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.fcr", + "type": "number", + "value": 0.978, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 1852.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/tests/test.sh b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-feed-conversion-d3-t0079/tests/verify.py b/tasks/fishery-log/fishery-log-feed-conversion-d3-t0079/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-feed-conversion-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/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..482dfca845da15a3937614f2169168902c9d86e8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,3152,72,m3 +C01,4243,27,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..9df20d4ef80cc9015b4954fad211128f3bbc775e --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,267,g,valid +C00,S1,223,g,valid +C00,S2,611,g,valid +C00,S3,382,g,valid +C00,S4,474,g,valid +C01,S0,326,g,valid +C01,S1,865,g,valid +C01,S2,671,g,valid +C01,S3,376,g,valid +C01,S4,608,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-e0002/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1818436941dba86ffaacdbcbf37e0059c2e2830c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-e0002/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d9f23fe06d036a160a19562d9c12a2e205478b28 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 391.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1233.693, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 17.135, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 569.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2415.116, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 89.449, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-e0002/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..f28c7650b0b7aac32749d0299e63c2da306a7393 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,1939,97,m3 +C01,2616,38,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..92861723bcbe1ca1cd93f3f9ebaf48f55507a5d6 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,817,g,valid +C00,S1,249,g,valid +C00,S2,697,g,valid +C00,S3,176,g,valid +C00,S4,319,g,valid +C01,S0,219,g,valid +C01,S1,402,g,valid +C01,S2,565,g,valid +C01,S3,772,g,valid +C01,S4,456,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-e0011/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f44d76f6f52d53c8853bcab551ba8eec9e750b02 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-e0011/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..edc9b4a7682e270fb6bc95b08c849ef3457ddb79 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 451.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 875.652, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 9.027, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 482.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1263.005, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 33.237, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-e0011/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..8d0ecbb011bb3dce4ab382aae3303e7c25d2bac7 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,1342,54,m3 +C01,4535,77,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..744f62e3f1d4937ca35660b88e9123941d99a068 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,853,g,valid +C00,S1,851,g,valid +C00,S2,364,g,valid +C00,S3,590,g,valid +C00,S4,883,g,valid +C01,S0,564,g,valid +C01,S1,582,g,valid +C01,S2,674,g,valid +C01,S3,821,g,valid +C01,S4,860,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-e0020/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9e2332eceee6cb8561e210e7911aa7aa564947be --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-e0020/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9c2cfe431e4dd8def705ef06235e678831da76c7 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 708.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 950.404, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 17.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 700.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 3175.407, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 41.239, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-e0020/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-e0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..349dc69e9e257898ec9e09f2ad9b2ce71d598166 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,3277,63,m3 +C01,2231,40,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..16ec95df9d59bcf6790eb5b3e37fb63d2c7b9e79 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,649,g,valid +C00,S1,780,g,valid +C00,S2,798,g,valid +C00,S3,376,g,valid +C00,S4,613,g,valid +C01,S0,790,g,valid +C01,S1,431,g,valid +C01,S2,199,g,valid +C01,S3,900,g,valid +C01,S4,216,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0002/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c4c1edfa6220573bf032eb3ca7288023eb1589ea --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0002/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2bb053648295ee2c4c1a7a9c771f32894ee09c1e --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 643.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2107.766, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 33.457, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 507.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1131.563, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 28.289, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0002/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..4ab219fc1b65392b56abf5f0fd2fd332a3c60523 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,2988,34,m3 +C01,2110,24,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..5be8828797918f4c8c87f65b1f0f5b2014635435 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,628,g,valid +C00,S1,363,g,valid +C00,S2,514,g,valid +C00,S3,606,g,valid +C00,S4,421,g,valid +C01,S0,723,g,valid +C01,S1,646,g,valid +C01,S2,150,g,valid +C01,S3,538,g,valid +C01,S4,293,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0011/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ae9c4a08520a27744a4fa49a6b89854b943131ed --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0011/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..646727d2142f3e7e65e0cd265a7ad756eea4d761 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 506.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1513.123, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 44.504, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 470.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 991.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 41.321, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0011/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..cd6f75bbe87b044a0e53b25fc9e483a4aee1e308 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,1065,93,m3 +C01,4598,83,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..8e39179d20c8d7151f8482380148b22977b7fd41 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,827,g,valid +C00,S1,826,g,valid +C00,S2,617,g,valid +C00,S3,247,g,valid +C00,S4,804,g,valid +C01,S0,738,g,valid +C01,S1,604,g,valid +C01,S2,737,g,valid +C01,S3,775,g,valid +C01,S4,575,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0020/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..60842cab9a1d91a9db356e09ed817e993062c729 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0020/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a269a13b40e61c3292d9f4e8eb872676681fb60f --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 664.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 707.373, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 7.606, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 685.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 3153.308, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 37.992, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0020/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..cc66dd5f601f55b56cbc8276450f3d1ab2324c0d --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,4785,57,m3 +C01,3013,20,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..7a73206897b134de6de76828cc82b3929e33fa0d --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,335,g,valid +C00,S1,136,g,valid +C00,S2,631,g,valid +C00,S3,328,g,valid +C00,S4,486,g,valid +C01,S0,708,g,valid +C01,S1,517,g,valid +C01,S2,574,g,valid +C01,S3,784,g,valid +C01,S4,442,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0029/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b493c6745deceb94fa233c03eebf4375056deaec --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0029/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f473d344f895d6197241a95c401ce1645ba5679c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 383.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1833.612, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 32.169, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 605.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1822.865, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 91.143, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0029/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0029/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..86388fe7a1ecc4db149c0d4bd565277fdb8fdacf --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,2824,22,m3 +C01,4418,60,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..2fb582f9df80a34adef99e49ac30500bed560e96 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,622,g,valid +C00,S1,487,g,valid +C00,S2,256,g,valid +C00,S3,547,g,valid +C00,S4,283,g,valid +C01,S0,343,g,valid +C01,S1,831,g,valid +C01,S2,858,g,valid +C01,S3,402,g,valid +C01,S4,816,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0038/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..acc2a99c5d5deb52b17b7e46a7b6ae7eff201e67 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0038/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ef8763e782c2a35195066d07c094400f32804263 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 439.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1239.736, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 56.352, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 650.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2871.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 47.862, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0038/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0038/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..bc4bf6de409f9b0d1348b9705647121da8c1b226 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,3061,94,m3 +C01,2723,92,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..5ec9d856510184a58ea83f173c4d5896e91f1983 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,895,g,valid +C00,S1,584,g,valid +C00,S2,279,g,valid +C00,S3,105,g,valid +C00,S4,311,g,valid +C01,S0,704,g,valid +C01,S1,431,g,valid +C01,S2,888,g,valid +C01,S3,694,g,valid +C01,S4,770,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0047/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1b6c8e634d0d60efd52f94665bfab5cc9f84a6c8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0047/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b6d2a78f7462c909c9146be85552b6a988c07a68 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 434.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1330.923, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 14.159, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 697.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1899.02, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 20.642, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0047/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0047/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..c68bd2c16b626bc7b9d6d43c44e3b39a6c55bde3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,4468,81,m3 +C01,1221,47,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..229ddbdd08e7c2fbc72a3f7cf2c2829367435732 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,353,g,valid +C00,S1,236,g,valid +C00,S2,576,g,valid +C00,S3,843,g,valid +C00,S4,360,g,valid +C01,S0,781,g,valid +C01,S1,337,g,valid +C01,S2,648,g,valid +C01,S3,498,g,valid +C01,S4,402,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0056/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..28626a19d427dafaa424e62d8812f0a6830ef47d --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0056/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1de311fa8f84be5e188faf55aceb90029a033a86 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 473.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2116.045, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 26.124, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 533.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 651.037, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 13.852, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0056/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0056/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..efa9bba67e50fb7a43f0f78988fd0d6dbd57c111 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,3752,87,m3 +C01,1906,65,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..54a9b6095fc14f721f9a051f00b38a8748bbfd63 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,490,g,valid +C00,S1,900,g,valid +C00,S2,552,g,valid +C00,S3,854,g,valid +C00,S4,395,g,valid +C01,S0,778,g,valid +C01,S1,585,g,valid +C01,S2,159,g,valid +C01,S3,214,g,valid +C01,S4,226,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0065/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..13b3ecd45b589fa92f516ee26debb23c2119b2dd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0065/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..425ee194e15bbb474620552375ccb969792d4ec2 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 638.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2394.526, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 27.523, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 392.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 747.914, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 11.506, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0065/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0065/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..becbee38a2c49a81c2a793ee00a3ddf42ba0fa56 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,2166,90,m3 +C01,4285,71,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..d001c87016f9cd7804dbdc83d2575591679f9e7c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,536,g,valid +C00,S1,263,g,valid +C00,S2,678,g,valid +C00,S3,602,g,valid +C00,S4,813,g,valid +C01,S0,651,g,valid +C01,S1,718,g,valid +C01,S2,495,g,valid +C01,S3,494,g,valid +C01,S4,755,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0074/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2b4e6002a07e8bb3e2a682d2355044a4dea3f02e --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0074/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a403faf93c0fa27a3635c1c7f21df7dcafca8314 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 578.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1252.814, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 13.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 622.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2667.841, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 37.575, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0074/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0074/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..2d49262946fc254949b00f2897b3dfcef42bce3a --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/workdir/cages.csv @@ -0,0 +1,3 @@ +cage_id,fish_count,volume,volume_unit +C00,1534,29,m3 +C01,4207,43,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..cfe4c16d047f9b99f4d5204f4748d99f532bf248 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/environment/workdir/samples.csv @@ -0,0 +1,11 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S0,857,g,valid +C00,S1,193,g,valid +C00,S2,623,g,valid +C00,S3,644,g,valid +C00,S4,767,g,valid +C01,S0,333,g,valid +C01,S1,162,g,valid +C01,S2,530,g,valid +C01,S3,878,g,valid +C01,S4,719,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d1-t0083/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..673f19b37a5f922463333de47128702ec5247ee1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d1-t0083/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f8c41f22e127a434d9046606a583a6099070eccb --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/tests/checks.json @@ -0,0 +1,56 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 616.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 946.171, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 32.627, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 5, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 524.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2206.151, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 51.306, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d1-t0083/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d1-t0083/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..86cd8a31ac3ef8bddd1917ce2053fb6f7bfdd4bc --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C00,4997,60,m3 +C01,3283,79,m3 +C02,4671,99,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..94dc8aa4f41480344dfcd0040faaf56bd5239cc9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S1,704,g,valid +C01,S5,749,g,valid +C02,S2,470,g,valid +C00,S0,492,g,valid +C01,S4,779,g,valid +C02,S4,378,g,valid +C01,S2,703,g,valid +C00,S2,886,g,valid +C01,BAD,99999,g,invalid +C00,S4,869,g,valid +C02,S5,210,g,valid +C02,S3,335,g,valid +C01,S1,212,g,valid +C01,S3,426,g,valid +C01,S0,477,g,valid +C02,S1,683,g,valid +C02,S0,626,g,valid +C00,S5,238,g,valid +C00,BAD,99999,g,invalid +C00,S3,196,g,valid +C02,BAD,99999,g,invalid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-e0005/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fcb1ee5f65c5b7157d1a8ff623fd5ba7bb111d37 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-e0005/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8f3931edb9ebe0ee3303c16bd7e88a341edf772e --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 564.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2819.141, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 46.986, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 557.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1830.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 23.175, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 450.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 2103.507, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 21.248, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-e0005/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..0c24a228240a8075d16b36141cb7113194c096b8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C01,1434,100,m3 +C00,1695,25,m3 +C02,4508,88,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..da97ffe1ada20f86232ff52aecd1a7a30d5a9855 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C01,S4,863,g,valid +C02,S1,861,g,valid +C01,S1,290,g,valid +C00,BAD,99999,g,invalid +C01,BAD,99999,g,invalid +C01,S2,268,g,valid +C00,S4,477,g,valid +C00,S1,264,g,valid +C02,S5,341,g,valid +C01,S5,283,g,valid +C02,S0,159,g,valid +C01,S3,131,g,valid +C01,S0,752,g,valid +C00,S0,532,g,valid +C02,S2,761,g,valid +C00,S5,263,g,valid +C00,S2,590,g,valid +C02,BAD,99999,g,invalid +C02,S3,683,g,valid +C02,S4,277,g,valid +C00,S3,551,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-e0014/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..aa3ca577f3880da49f3d69017d4200f7602cdcbc --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-e0014/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1819ad64939b590c0cb4f09bb611004cd52281ed --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 446.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 756.253, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 30.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 431.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 618.293, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 6.183, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 513.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 2315.609, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 26.314, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-e0014/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..8042010dc8988cbb36e6e491db51ba1a24a75e55 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C02,1479,92,m3 +C01,2177,63,m3 +C00,1997,84,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..4f7e64c149998fe8c1892dc77c8c8f5959c68cf8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C00,BAD,99999,g,invalid +C00,S5,112,g,valid +C00,S1,104,g,valid +C00,S4,526,g,valid +C02,S0,218,g,valid +C01,S4,638,g,valid +C02,S4,264,g,valid +C02,S3,303,g,valid +C00,S3,576,g,valid +C01,BAD,99999,g,invalid +C00,S2,415,g,valid +C01,S5,640,g,valid +C02,S2,811,g,valid +C01,S0,796,g,valid +C02,BAD,99999,g,invalid +C02,S5,458,g,valid +C00,S0,127,g,valid +C01,S2,392,g,valid +C02,S1,749,g,valid +C01,S1,319,g,valid +C01,S3,749,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-e0023/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..01e0e52cd9f1ab175382212c8119c63e6b7c0cb3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-e0023/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..02782b010d8eaf50302a98ed05aafeb5fc23c0e0 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 310.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 619.07, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 7.37, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 589.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1282.253, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 20.353, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 467.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 690.939, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 7.51, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-e0023/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-e0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..ffb722c64f3424536295ce9e87fe1e43b0e6bcae --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C00,4925,76,m3 +C01,1720,84,m3 +C02,4709,89,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..2326180d5321e1775f8c9ee8d9f33e4a9ad76bb8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C02,S5,230,g,valid +C00,S3,322,g,valid +C01,S3,484,g,valid +C01,BAD,99999,g,invalid +C02,S4,373,g,valid +C00,S0,417,g,valid +C02,S1,582,g,valid +C00,S4,797,g,valid +C01,S5,362,g,valid +C02,S0,304,g,valid +C00,BAD,99999,g,invalid +C00,S1,821,g,valid +C01,S4,840,g,valid +C02,S2,421,g,valid +C01,S2,272,g,valid +C00,S5,657,g,valid +C02,S3,172,g,valid +C00,S2,728,g,valid +C01,S1,370,g,valid +C01,S0,285,g,valid +C02,BAD,99999,g,invalid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0005/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5c40e4169e4412535800f5f69c44922bd2245471 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0005/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4ea01f138436841fc2fe26e85109a991a103ddaf --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 623.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 3071.558, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 40.415, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 435.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 749.06, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 8.917, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 347.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1634.023, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 18.36, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0005/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..422e55b730401818467beea26bdde7f8e17b4bdf --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C02,1105,85,m3 +C01,3398,74,m3 +C00,1974,68,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..a482d98ca0a26880a33e4bcb9ec9dd1bfd47adff --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C02,S4,317,g,valid +C01,S4,676,g,valid +C00,S0,247,g,valid +C00,BAD,99999,g,invalid +C02,BAD,99999,g,invalid +C02,S5,139,g,valid +C00,S3,502,g,valid +C00,S4,100,g,valid +C01,S2,767,g,valid +C01,S3,592,g,valid +C00,S5,418,g,valid +C00,S1,275,g,valid +C02,S1,364,g,valid +C01,S1,406,g,valid +C00,S2,479,g,valid +C02,S0,739,g,valid +C02,S2,168,g,valid +C01,S5,130,g,valid +C02,S3,439,g,valid +C01,S0,449,g,valid +C01,BAD,99999,g,invalid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0014/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d4cf5d637c9771d6ccd2bb6e973f48feb5676131 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0014/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9a4147f1d00f1702748f380c982e959aa7feda0a --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 336.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 664.909, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 9.778, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 503.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1710.327, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 23.113, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 361.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 398.905, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 4.693, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0014/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..0eb619c035af1683b510e314848a141bfb2203a4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C02,2537,52,m3 +C00,1433,26,m3 +C01,4635,80,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..79d44690c1d65c2bc620fe968b2d0984a0a0fc07 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C01,S3,102,g,valid +C00,S2,144,g,valid +C00,S1,604,g,valid +C00,S4,758,g,valid +C01,S5,456,g,valid +C02,S2,530,g,valid +C00,S3,627,g,valid +C00,S5,454,g,valid +C02,BAD,99999,g,invalid +C00,BAD,99999,g,invalid +C00,S0,702,g,valid +C01,S2,390,g,valid +C02,S1,758,g,valid +C02,S5,806,g,valid +C02,S3,370,g,valid +C02,S4,187,g,valid +C01,S0,683,g,valid +C01,S1,529,g,valid +C01,BAD,99999,g,invalid +C01,S4,805,g,valid +C02,S0,716,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0023/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2fb377bb6081d808c4a854196f94c4c6f584def5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0023/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0f4b1c5b1ea81108ee05165550271a6f1dc1ad8b --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 548.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 785.523, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 30.212, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 494.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2290.463, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 28.631, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 561.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1423.68, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 27.378, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0023/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..d629cd4732441e9d354de891257649c7268142f8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C00,2142,88,m3 +C02,4931,40,m3 +C01,1326,67,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..e7b52bf0bbccb770b1aecb56d47efae124be7b06 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C02,BAD,99999,g,invalid +C00,S1,490,g,valid +C00,BAD,99999,g,invalid +C02,S5,425,g,valid +C00,S5,120,g,valid +C02,S1,419,g,valid +C01,S5,271,g,valid +C00,S3,543,g,valid +C01,S4,228,g,valid +C02,S0,337,g,valid +C01,S3,559,g,valid +C01,S2,727,g,valid +C02,S3,631,g,valid +C02,S2,453,g,valid +C01,S1,278,g,valid +C01,BAD,99999,g,invalid +C00,S4,509,g,valid +C00,S0,545,g,valid +C00,S2,564,g,valid +C02,S4,870,g,valid +C01,S0,371,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0032/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..45ddea3417683006e10076cbcaf7fb557d6c1a79 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0032/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ac1a107d61ff62b066eb32cecc49c8e2fb544131 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 461.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 989.247, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 11.241, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 405.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 537.914, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 8.029, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 522.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 2576.448, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 64.411, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0032/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0032/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..e006f2682c6e0cb2e5878b73ccc22bab35feb1c1 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C02,1491,85,m3 +C00,3667,50,m3 +C01,2161,32,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..5168b6312d91e5c356303eebd68712f3872db093 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C01,S0,143,g,valid +C02,S5,454,g,valid +C01,S4,853,g,valid +C02,S1,452,g,valid +C00,S1,209,g,valid +C01,S1,801,g,valid +C00,S4,729,g,valid +C02,S4,200,g,valid +C02,S2,419,g,valid +C01,BAD,99999,g,invalid +C02,S3,462,g,valid +C00,S5,609,g,valid +C02,BAD,99999,g,invalid +C00,S0,787,g,valid +C00,BAD,99999,g,invalid +C01,S3,575,g,valid +C00,S2,284,g,valid +C01,S5,218,g,valid +C00,S3,716,g,valid +C02,S0,825,g,valid +C01,S2,798,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0041/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3142e24c8f4df1ec4e430b2de39c7c9b4f974652 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0041/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..95dca02a221c94f8e2b008cd764e8a33964a2dd3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 555.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2037.63, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 40.753, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 564.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1220.245, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 38.133, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 468.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 698.782, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 8.221, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0041/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0041/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..1ccf815a074511d5be340ce045606710b91e6131 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C02,1029,54,m3 +C01,4850,77,m3 +C00,2274,26,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..112811c6feb7873a116c8f4b6d6877776125725f --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C02,S4,189,g,valid +C01,S5,799,g,valid +C01,S2,546,g,valid +C00,BAD,99999,g,invalid +C00,S0,416,g,valid +C02,S1,428,g,valid +C01,BAD,99999,g,invalid +C02,S3,471,g,valid +C01,S3,884,g,valid +C02,S0,652,g,valid +C00,S5,208,g,valid +C01,S0,183,g,valid +C01,S4,121,g,valid +C02,S5,167,g,valid +C00,S3,235,g,valid +C02,BAD,99999,g,invalid +C00,S1,237,g,valid +C02,S2,170,g,valid +C00,S2,134,g,valid +C01,S1,209,g,valid +C00,S4,660,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0050/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ae6f669b77e7bcf015639db26ae3244c598f9b32 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0050/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a5b3154810f18ca4e02b79341494c3e212689ca5 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 315.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 716.31, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 27.55, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 457.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2216.45, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 28.785, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 346.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 356.205, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 6.596, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0050/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0050/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..9f39add97be13980c6e89edbeb5f27a29c4d5e3a --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C00,1752,85,m3 +C02,4341,61,m3 +C01,3935,67,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..3a0312ce84a08277f41694cd547b56c915c16c26 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C02,S5,839,g,valid +C00,S0,427,g,valid +C02,S0,517,g,valid +C02,S3,433,g,valid +C02,BAD,99999,g,invalid +C00,S2,366,g,valid +C01,S1,297,g,valid +C00,S3,694,g,valid +C02,S4,649,g,valid +C00,BAD,99999,g,invalid +C01,S2,359,g,valid +C01,BAD,99999,g,invalid +C00,S4,231,g,valid +C00,S5,452,g,valid +C01,S3,445,g,valid +C01,S4,231,g,valid +C00,S1,427,g,valid +C02,S1,848,g,valid +C02,S2,410,g,valid +C01,S0,622,g,valid +C01,S5,849,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0059/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fe62133d0283bdb727ca77b1aa373a753619d420 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0059/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..53f560a52557992d0d74711b87cac271a82c2b80 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 432.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 758.324, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 8.921, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 467.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1838.301, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 27.437, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 616.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 2674.056, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 43.837, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0059/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0059/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..31a23065dc404d0223d990eb08f6180b18a2967d --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C00,4882,76,m3 +C01,4284,64,m3 +C02,2366,42,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..f060577940825d0717cf9c6dd4995db339548f06 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C01,S2,300,g,valid +C02,S1,517,g,valid +C02,BAD,99999,g,invalid +C00,S5,168,g,valid +C02,S0,369,g,valid +C02,S5,330,g,valid +C01,S0,631,g,valid +C01,S5,704,g,valid +C02,S2,538,g,valid +C00,BAD,99999,g,invalid +C00,S4,837,g,valid +C01,S3,638,g,valid +C00,S0,633,g,valid +C02,S4,373,g,valid +C01,BAD,99999,g,invalid +C00,S3,895,g,valid +C00,S1,688,g,valid +C02,S3,534,g,valid +C01,S1,305,g,valid +C01,S4,550,g,valid +C00,S2,632,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0068/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..353e5bc6d295b5c325c8c9ddb5ee14d48fc43d50 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0068/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e687e6880a893e3e6f959376b84985d9ae5b5304 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 642.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 3135.058, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 41.251, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 521.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2233.392, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 34.897, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 443.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1049.321, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 24.984, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0068/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0068/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..3cc703d614c9aa908e068fb34e5c484290934b52 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/workdir/cages.csv @@ -0,0 +1,4 @@ +cage_id,fish_count,volume,volume_unit +C02,2945,97,m3 +C01,2525,82,m3 +C00,4185,79,m3 diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..fd63c2b205045184fbf97d2133a29cbb0ab5e057 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/environment/workdir/samples.csv @@ -0,0 +1,22 @@ +cage_id,sample_id,weight,weight_unit,status +C02,S0,900,g,valid +C01,S1,331,g,valid +C02,S5,697,g,valid +C00,S5,417,g,valid +C01,BAD,99999,g,invalid +C00,S1,362,g,valid +C01,S0,680,g,valid +C01,S2,482,g,valid +C02,S2,365,g,valid +C01,S3,253,g,valid +C00,S3,380,g,valid +C02,BAD,99999,g,invalid +C02,S1,573,g,valid +C02,S4,255,g,valid +C02,S3,179,g,valid +C01,S5,367,g,valid +C00,BAD,99999,g,invalid +C01,S4,326,g,valid +C00,S4,854,g,valid +C00,S0,342,g,valid +C00,S2,856,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cacd1f8398d588c30053b62564419b6acd4d6ef8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d2-t0077/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2e71b1e09f2a6da39e183d25a9f75c6858df81ec --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d2-t0077/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a5180e6f1a6ca1f2c376ff3185ed56a151253d7a --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/tests/checks.json @@ -0,0 +1,83 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 535.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2239.673, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 28.35, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 406.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1026.412, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 12.517, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 6, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 494.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1457.284, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 15.024, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d2-t0077/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d2-t0077/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..2dc043e00e9f38ad44f153b0b41f83c66ee95237 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C01,2225,63000,L +C02,2214,94000,L +C00,2925,62000,L +C03,2434,26000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..3dac48520712a0149ea38fd5160e2e0d7763c9c4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S5,0.352,kg,valid +C01,S6,163,g,valid +C01,S1,0.53,kg,valid +C01,S0,141,g,valid +C02,S0,421,g,valid +C02,S6,149,g,valid +C02,S5,0.583,kg,valid +C03,S6,881,g,valid +C02,S4,306,g,valid +C01,S4,385,g,valid +C00,S0,820,g,valid +C00,S1,0.59,kg,valid +C00,S3,0.227,kg,valid +C00,BAD,99999,g,invalid +C03,S0,440,g,valid +C00,S2,614,g,valid +C02,S3,0.408,kg,valid +C01,BAD,99999,g,invalid +C03,BAD,99999,g,invalid +C03,S2,160,g,valid +C02,BAD,99999,g,invalid +C03,S5,0.583,kg,valid +C00,S6,359,g,valid +C01,S2,718,g,valid +C03,S1,0.257,kg,valid +C02,S1,0.134,kg,valid +C02,S2,389,g,valid +C00,S4,537,g,valid +C03,S4,193,g,valid +C03,S3,0.583,kg,valid +C01,S3,0.751,kg,valid +C01,S5,0.878,kg,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-e0008/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..89bf7e5c735dfa2fa0ffbdd807d17a0b48cd6d12 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-e0008/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7a1cdc881bf7f271523a5476e61215804685e15c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 499.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1462.082, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 23.582, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 509.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1133.479, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 17.992, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 341.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 755.923, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 8.042, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 442.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 1076.871, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 41.418, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4428.355, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-e0008/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..04be58151076eb0755b11986fecebbd7a1abad00 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C00,2838,64000,L +C03,4733,68000,L +C02,3694,25000,L +C01,4901,66000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..032c7cfab681f293fb5475e25671b379efc0cc96 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C01,S2,649,g,valid +C00,S2,660,g,valid +C02,S3,0.871,kg,valid +C01,BAD,99999,g,invalid +C01,S4,323,g,valid +C03,S2,496,g,valid +C00,S1,0.19,kg,valid +C01,S3,0.52,kg,valid +C02,S5,0.544,kg,valid +C03,S1,0.459,kg,valid +C03,BAD,99999,g,invalid +C02,S2,684,g,valid +C01,S6,886,g,valid +C00,S0,104,g,valid +C01,S5,0.672,kg,valid +C02,S4,303,g,valid +C00,S6,155,g,valid +C02,S1,0.501,kg,valid +C02,BAD,99999,g,invalid +C03,S3,0.106,kg,valid +C01,S1,0.277,kg,valid +C00,S4,259,g,valid +C02,S0,537,g,valid +C02,S6,315,g,valid +C00,S5,0.373,kg,valid +C03,S6,754,g,valid +C03,S5,0.628,kg,valid +C03,S4,262,g,valid +C00,BAD,99999,g,invalid +C01,S0,423,g,valid +C03,S0,776,g,valid +C00,S3,0.674,kg,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-e0017/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..666f435efd09b26af5b438e1a321678ae2981008 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "eval"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-e0017/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9b4e6ac319d526facc5fe0a7ebe10f409f178dd4 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 345.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 979.11, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 15.299, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 535.714, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2625.536, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 39.781, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 536.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1981.567, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 79.263, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 497.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 2353.653, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 34.613, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 7939.866, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-e0017/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-e0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..07fd5cf21dfa945edfcaf1c6b42fe6e0792e12a8 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C00,1496,78000,L +C03,2159,63000,L +C01,1730,71000,L +C02,2477,21000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..b609d90aa778774d45bcfba204d28269029bc504 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C01,S1,0.895,kg,valid +C01,S2,190,g,valid +C00,S4,578,g,valid +C03,S6,876,g,valid +C02,S0,646,g,valid +C01,S0,565,g,valid +C00,S1,0.773,kg,valid +C01,S6,283,g,valid +C00,S0,468,g,valid +C03,S4,133,g,valid +C03,S2,668,g,valid +C03,S0,509,g,valid +C01,BAD,99999,g,invalid +C00,S2,112,g,valid +C03,BAD,99999,g,invalid +C02,S3,0.407,kg,valid +C01,S5,0.766,kg,valid +C02,S4,463,g,valid +C02,BAD,99999,g,invalid +C02,S2,131,g,valid +C00,BAD,99999,g,invalid +C00,S6,524,g,valid +C00,S5,0.241,kg,valid +C03,S3,0.524,kg,valid +C03,S5,0.754,kg,valid +C01,S4,816,g,valid +C03,S1,0.595,kg,valid +C02,S5,0.413,kg,valid +C02,S1,0.213,kg,valid +C00,S3,0.575,kg,valid +C02,S6,174,g,valid +C01,S3,0.419,kg,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0008/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..90a257ae1c08f0514543cd6a18974c0419a8ecf9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0008/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..eb1dfe958a8abe2851d7879af37c49ecde18ee11 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 467.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 699.059, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 8.962, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 562.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 972.26, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 13.694, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 349.571, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 865.888, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 41.233, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 579.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 1251.912, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 19.872, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3789.119, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0008/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..cbdf04c9ee89acd183d7b316618e6b14d1a62460 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C03,3395,32000,L +C01,4043,73000,L +C02,3091,64000,L +C00,3931,94000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..7a074bbe2a15a7007979b62304f370ae8b9241ee --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C02,S1,0.219,kg,valid +C03,S5,0.895,kg,valid +C01,S4,276,g,valid +C03,S1,0.572,kg,valid +C00,S4,620,g,valid +C02,S4,820,g,valid +C00,S6,718,g,valid +C02,S5,0.6,kg,valid +C00,BAD,99999,g,invalid +C01,S2,777,g,valid +C02,S6,590,g,valid +C00,S3,0.129,kg,valid +C03,BAD,99999,g,invalid +C01,S5,0.787,kg,valid +C03,S2,452,g,valid +C00,S5,0.529,kg,valid +C02,S3,0.424,kg,valid +C00,S1,0.833,kg,valid +C02,BAD,99999,g,invalid +C01,BAD,99999,g,invalid +C03,S6,817,g,valid +C01,S6,495,g,valid +C03,S3,0.86,kg,valid +C01,S0,578,g,valid +C03,S4,190,g,valid +C00,S2,377,g,valid +C02,S2,730,g,valid +C02,S0,595,g,valid +C01,S3,0.603,kg,valid +C03,S0,289,g,valid +C01,S1,0.308,kg,valid +C00,S0,773,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0017/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..849ef6a5ef8be8f2259bb1042f0c8b02136f4474 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0017/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d0b4ddbbc7118a56e80dce9cceaab0be1c4fdae9 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 568.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2234.493, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 23.771, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 546.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2208.633, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 30.255, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 568.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1756.571, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 27.446, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 582.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 1976.375, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 61.762, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 8176.072, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0017/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..9195bc699a296671930e6bc042d1c058491b8ae7 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C01,2927,72000,L +C02,1487,89000,L +C03,2592,98000,L +C00,3518,32000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..1ec620d15f19edd54023db21054bba2bef465f16 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S4,128,g,valid +C01,S0,833,g,valid +C03,S1,0.355,kg,valid +C03,S3,0.348,kg,valid +C01,S5,0.537,kg,valid +C02,S3,0.892,kg,valid +C01,S4,819,g,valid +C00,BAD,99999,g,invalid +C02,BAD,99999,g,invalid +C00,S1,0.799,kg,valid +C01,S1,0.757,kg,valid +C02,S0,328,g,valid +C02,S4,241,g,valid +C03,S5,0.631,kg,valid +C03,S2,680,g,valid +C03,S4,565,g,valid +C01,BAD,99999,g,invalid +C02,S5,0.237,kg,valid +C00,S6,216,g,valid +C02,S2,692,g,valid +C00,S3,0.86,kg,valid +C00,S2,744,g,valid +C01,S2,601,g,valid +C00,S0,305,g,valid +C03,S0,574,g,valid +C02,S1,0.539,kg,valid +C03,BAD,99999,g,invalid +C02,S6,198,g,valid +C03,S6,461,g,valid +C01,S6,859,g,valid +C01,S3,0.752,kg,valid +C00,S5,0.157,kg,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0026/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cea095b4d67f0b37a9aded4817a5a9be68074898 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0026/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a49914bbede5f188de75d53699c7264d69b8a45a --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 458.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1612.752, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 50.398, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 736.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2156.781, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 29.955, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 446.714, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 664.264, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 7.464, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 516.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 1338.213, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 13.655, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5772.009, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0026/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0026/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..55c6f9cdaaba42c3e94e6db2a5b0f1833530bf4d --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C00,2890,56000,L +C01,2222,29000,L +C02,4174,62000,L +C03,1041,67000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..d593c776426ae1150dad3c49411e16198590b072 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C02,S5,0.209,kg,valid +C01,S6,196,g,valid +C03,BAD,99999,g,invalid +C03,S1,0.727,kg,valid +C00,S4,841,g,valid +C03,S6,236,g,valid +C03,S3,0.376,kg,valid +C01,S0,553,g,valid +C03,S5,0.627,kg,valid +C03,S0,742,g,valid +C03,S4,549,g,valid +C00,S6,285,g,valid +C01,S2,517,g,valid +C00,S3,0.306,kg,valid +C02,S3,0.497,kg,valid +C00,S0,720,g,valid +C00,S2,595,g,valid +C00,S5,0.666,kg,valid +C01,S3,0.286,kg,valid +C01,S1,0.754,kg,valid +C02,S0,447,g,valid +C03,S2,328,g,valid +C01,S5,0.334,kg,valid +C01,BAD,99999,g,invalid +C02,S1,0.643,kg,valid +C00,BAD,99999,g,invalid +C02,S4,792,g,valid +C00,S1,0.514,kg,valid +C02,S6,726,g,valid +C02,BAD,99999,g,invalid +C02,S2,271,g,valid +C01,S4,397,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0035/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..625b7991a52624f0c7dff0d958c03dc5d1b7d626 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0035/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c4ab770738559746a763df5a72a1fdee4e99ff07 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 561.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1621.29, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 28.952, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 433.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 964.031, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 33.242, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 512.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 2137.684, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 34.479, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 512.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 533.141, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 7.957, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5256.146, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0035/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0035/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..bdc4ef35f7a05ace6c40dadb6f6804c7f6cc954c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C03,3277,21000,L +C01,3744,93000,L +C02,3199,98000,L +C00,3015,54000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..c625b94b9856ab15a6ec3de4b8c73512a9616fb6 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C03,S4,499,g,valid +C00,S1,0.808,kg,valid +C03,S6,825,g,valid +C02,S1,0.461,kg,valid +C02,BAD,99999,g,invalid +C02,S0,243,g,valid +C01,BAD,99999,g,invalid +C03,S5,0.171,kg,valid +C03,BAD,99999,g,invalid +C00,BAD,99999,g,invalid +C01,S4,740,g,valid +C00,S0,847,g,valid +C03,S0,288,g,valid +C03,S3,0.326,kg,valid +C00,S2,411,g,valid +C01,S3,0.81,kg,valid +C00,S4,445,g,valid +C02,S6,189,g,valid +C01,S5,0.332,kg,valid +C00,S5,0.67,kg,valid +C01,S1,0.412,kg,valid +C00,S3,0.848,kg,valid +C03,S2,392,g,valid +C02,S2,162,g,valid +C02,S3,0.643,kg,valid +C01,S2,480,g,valid +C02,S4,639,g,valid +C02,S5,0.115,kg,valid +C03,S1,0.328,kg,valid +C00,S6,776,g,valid +C01,S6,888,g,valid +C01,S0,680,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0044/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..10c535dcc1207c2d2eda915f9c03f41e996a238e --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0044/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..51cfc14539c119d92211bd1eb637a0ffe06835e7 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 686.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2069.582, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 38.326, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 620.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 2322.35, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 24.972, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 350.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1120.564, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 11.434, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 404.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 1324.376, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 63.066, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 6836.872, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0044/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0044/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..d4931b6991c052221a7416c0285d0b5e688450ae --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C01,3634,76000,L +C00,2761,22000,L +C02,2308,71000,L +C03,1322,91000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..bb3d544281911b2ca6d42dadd5517d4472586333 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C01,BAD,99999,g,invalid +C00,S6,866,g,valid +C02,S5,0.346,kg,valid +C03,S2,340,g,valid +C02,S2,515,g,valid +C00,S1,0.226,kg,valid +C03,S6,384,g,valid +C03,S3,0.848,kg,valid +C00,S0,610,g,valid +C02,BAD,99999,g,invalid +C01,S2,154,g,valid +C01,S6,533,g,valid +C00,S2,508,g,valid +C01,S1,0.415,kg,valid +C01,S0,226,g,valid +C00,S3,0.485,kg,valid +C02,S3,0.714,kg,valid +C03,S5,0.17,kg,valid +C00,S4,481,g,valid +C03,S4,711,g,valid +C01,S3,0.778,kg,valid +C03,BAD,99999,g,invalid +C03,S0,756,g,valid +C02,S1,0.622,kg,valid +C00,BAD,99999,g,invalid +C02,S0,226,g,valid +C01,S5,0.19,kg,valid +C02,S6,777,g,valid +C00,S5,0.227,kg,valid +C01,S4,373,g,valid +C02,S4,607,g,valid +C03,S1,0.539,kg,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0053/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..95851e1d68478fc060a553a3287262e0227bcc90 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0053/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..caf944fcc0280891b7c5fdd6ef1d669cc6b84957 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 486.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1342.24, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 61.011, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 381.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1385.592, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 18.231, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 543.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1255.222, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 17.679, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 535.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 707.837, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 7.778, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4690.892, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0053/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0053/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..9382fc9837b5f58b88397bda5d74a8401b92c653 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C01,2061,79000,L +C00,1025,56000,L +C02,3506,35000,L +C03,1878,67000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..62b72e08b428f9470e5b1d6cbaefdcf7b9cb461c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C01,S1,0.555,kg,valid +C00,BAD,99999,g,invalid +C02,S1,0.453,kg,valid +C03,S3,0.443,kg,valid +C00,S1,0.388,kg,valid +C03,S0,793,g,valid +C00,S6,192,g,valid +C01,S6,809,g,valid +C02,S2,370,g,valid +C02,S4,828,g,valid +C02,S3,0.551,kg,valid +C00,S4,301,g,valid +C02,S5,0.285,kg,valid +C00,S5,0.63,kg,valid +C03,S1,0.161,kg,valid +C01,S0,485,g,valid +C01,S3,0.539,kg,valid +C02,S6,721,g,valid +C00,S3,0.667,kg,valid +C01,S2,349,g,valid +C01,S4,181,g,valid +C03,S4,812,g,valid +C00,S2,830,g,valid +C01,S5,0.509,kg,valid +C02,BAD,99999,g,invalid +C00,S0,353,g,valid +C03,S6,661,g,valid +C01,BAD,99999,g,invalid +C03,S2,163,g,valid +C03,S5,0.595,kg,valid +C03,BAD,99999,g,invalid +C02,S0,510,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0062/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ce55e8675800430889cb50a144989b326a647849 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0062/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0ed705d2ccbbf5fc01c38c428c1f6b1bb159715e --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 480.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 492.146, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 8.788, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 489.571, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1009.007, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 12.772, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 531.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 1862.187, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 53.205, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 518.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 973.341, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 14.527, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4336.681, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0062/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0062/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..8c09f498cd0a7f1f62f73f06cb6257b1858bde31 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C01,1059,52000,L +C00,4631,57000,L +C02,1611,30000,L +C03,4641,32000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..7df6a768c942ad527fe1ac2055a0b0c37393cbe3 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S3,0.898,kg,valid +C03,S2,139,g,valid +C00,S2,402,g,valid +C02,S0,728,g,valid +C03,S3,0.858,kg,valid +C01,S5,0.849,kg,valid +C01,S6,866,g,valid +C02,S5,0.108,kg,valid +C01,S0,617,g,valid +C03,BAD,99999,g,invalid +C01,S2,705,g,valid +C00,S4,533,g,valid +C03,S0,110,g,valid +C03,S4,822,g,valid +C03,S6,701,g,valid +C02,S2,171,g,valid +C02,S6,347,g,valid +C02,S4,136,g,valid +C00,S5,0.749,kg,valid +C03,S5,0.824,kg,valid +C00,BAD,99999,g,invalid +C02,S3,0.113,kg,valid +C01,S4,457,g,valid +C03,S1,0.654,kg,valid +C01,BAD,99999,g,invalid +C00,S6,534,g,valid +C02,S1,0.412,kg,valid +C02,BAD,99999,g,invalid +C01,S1,0.593,kg,valid +C00,S1,0.69,kg,valid +C01,S3,0.338,kg,valid +C00,S0,544,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0071/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..69e902528f10fe2deee7e937fd06aed59da81b0b --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0071/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e3c48d9f98ed1cbcc59cda44d0a1fa16d0b43f5e --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 621.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 2877.836, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 50.488, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 632.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 669.439, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 12.874, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 287.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 463.738, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 15.458, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 586.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 2723.604, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 85.113, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 6734.617, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0071/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0071/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/Dockerfile b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/workdir/cages.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/workdir/cages.csv new file mode 100644 index 0000000000000000000000000000000000000000..dee60982039243f65433b071066d4c2ff4c69964 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/workdir/cages.csv @@ -0,0 +1,5 @@ +cage_id,fish_count,volume,volume_unit +C02,1646,48000,L +C00,4709,95000,L +C01,3603,26000,L +C03,3224,96000,L diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/workdir/samples.csv b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/workdir/samples.csv new file mode 100644 index 0000000000000000000000000000000000000000..3135cb5c406130ffa3fbd04968ad2a95a59d7e68 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/environment/workdir/samples.csv @@ -0,0 +1,33 @@ +cage_id,sample_id,weight,weight_unit,status +C00,S3,0.551,kg,valid +C03,S4,291,g,valid +C00,S1,0.624,kg,valid +C00,S6,120,g,valid +C01,S5,0.473,kg,valid +C02,S0,879,g,valid +C02,S5,0.699,kg,valid +C03,S3,0.539,kg,valid +C01,S4,129,g,valid +C02,S6,719,g,valid +C01,S1,0.142,kg,valid +C03,S6,660,g,valid +C01,S6,369,g,valid +C03,BAD,99999,g,invalid +C00,S4,322,g,valid +C02,S3,0.133,kg,valid +C00,S2,306,g,valid +C01,S2,591,g,valid +C00,BAD,99999,g,invalid +C03,S1,0.386,kg,valid +C03,S5,0.408,kg,valid +C01,BAD,99999,g,invalid +C01,S0,316,g,valid +C03,S2,110,g,valid +C01,S3,0.393,kg,valid +C00,S5,0.329,kg,valid +C02,S4,270,g,valid +C02,S2,172,g,valid +C02,S1,0.536,kg,valid +C02,BAD,99999,g,invalid +C03,S0,668,g,valid +C00,S0,660,g,valid diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/instruction.md b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..050a9844817d9108602902c22313727649d3519c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/instruction.md @@ -0,0 +1,5 @@ +# Fishery Log: stock-sampling + +`cages.csv` gives fish counts and water volumes. `samples.csv` contains individual fish weights; use only `status=valid` samples. Assume the sample is representative of its cage. Return per cage `sample_n` (number of valid samples, integer), `mean_weight_g` (arithmetic mean sample weight), `stock_biomass_kg` = fish_count*mean_weight_g/1000, and `density_kg_m3` = stock biomass/water volume. These are point estimates under the stated assumption, not measured total biomass. + +Units: 1 tonne = 1000 kg; 1 kg = 1000 g; 1 recorded fishing day = 24 fishing hours; 1000 litres = 1 m3. Write `answer.json` with `results`, keyed by the indicated group id. Also return `total_primary`, the sum of `stock_biomass_kg` across result groups. All numeric outputs except integer `sample_n` use 3 decimals, accepted within 0.001. Do not round intermediate values. All records are synthetic. diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/solution/oracle.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..6d241c833cf313d5f25d7dbdd8d48ffd8a811992 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/solution/oracle.py @@ -0,0 +1,35 @@ +"""Independent fisheries calculations from records on disk.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return list(csv.DictReader(f)) + +def solve(): + out={} + if Path('feed.csv').exists(): + feeds=read('feed.csv') + for r in read('stocks.csv'): + key=r['pond_id'];production=(float(r['closing_kg'])-float(r['opening_kg']))+(float(r['harvested_kg'])-float(r['stocked_kg']));fed=0 + for row in feeds: + if row['pond_id']==key and row['status']=='fed':fed+=float(row['feed'])/(1000 if row['feed_unit']=='g' else 1) + out[key]=dict(net_production_kg=production,feed_kg=fed,fcr=fed/production) + primary='net_production_kg' + elif Path('trips.csv').exists(): + trips=[r for r in read('trips.csv') if r['status']=='completed'] + for key in sorted({r['vessel_id'] for r in trips}): + landed=effort=discards=0 + for r in trips: + if r['vessel_id']!=key:continue + landed+=float(r['landed'])*(1000 if r['mass_unit']=='tonne' else 1);effort+=float(r['fishing_effort'])*(24 if r['effort_unit']=='day' else 1);discards+=float(r['discard_kg']) + out[key]=dict(landed_kg=landed,effort_h=effort,cpue_kg_h=landed/effort,discard_kg=discards,total_removals_kg=landed+discards) + primary='landed_kg' + else: + samples=read('samples.csv') + for r in read('cages.csv'): + key=r['cage_id'];kg=[float(row['weight'])/(1000 if row['weight_unit']=='g' else 1) for row in samples if row['cage_id']==key and row['status']=='valid'];biomass=sum(kg)*int(r['fish_count'])/len(kg);volume=float(r['volume'])/(1000 if r['volume_unit']=='L' else 1) + out[key]=dict(sample_n=len(kg),mean_weight_g=1000*sum(kg)/len(kg),stock_biomass_kg=biomass,density_kg_m3=biomass/volume) + primary='stock_biomass_kg' + 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/fishery-log/fishery-log-stock-sampling-d3-t0080/solution/solve.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/task.toml b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cfa41e67e0f312754066f4e0612f985fee40c0ec --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "fishery-log" +tags = ["fishery-log", "stock-sampling", "isced-0831", "train"] +isced_f = "0831" +family = "stock-sampling" +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/fishery-log/fishery-log-stock-sampling-d3-t0080/tests/checks.json b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..21d5b23de1024b1ce99d04e1c6a33e92bd4e905c --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/tests/checks.json @@ -0,0 +1,117 @@ +[ + { + "path": "results.C00.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C00.mean_weight_g", + "type": "number", + "value": 416.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.stock_biomass_kg", + "type": "number", + "value": 1958.944, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C00.density_kg_m3", + "type": "number", + "value": 20.62, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C01.mean_weight_g", + "type": "number", + "value": 344.714, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.stock_biomass_kg", + "type": "number", + "value": 1242.006, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C01.density_kg_m3", + "type": "number", + "value": 47.769, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C02.mean_weight_g", + "type": "number", + "value": 486.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.stock_biomass_kg", + "type": "number", + "value": 801.367, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C02.density_kg_m3", + "type": "number", + "value": 16.695, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.sample_n", + "type": "int", + "value": 7, + "weight": 1.0 + }, + { + "path": "results.C03.mean_weight_g", + "type": "number", + "value": 437.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.stock_biomass_kg", + "type": "number", + "value": 1410.27, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.C03.density_kg_m3", + "type": "number", + "value": 14.69, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5412.586, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/tests/test.sh b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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/fishery-log/fishery-log-stock-sampling-d3-t0080/tests/verify.py b/tasks/fishery-log/fishery-log-stock-sampling-d3-t0080/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/fishery-log/fishery-log-stock-sampling-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()