Add grower-desk subset: 84 train and 24 eval tasks
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/Dockerfile +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/workdir/fertigation.csv +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/instruction.md +5 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/oracle.py +27 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/solve.sh +4 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/task.toml +25 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/checks.json +58 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/test.sh +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/verify.py +116 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/Dockerfile +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/workdir/fertigation.csv +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/instruction.md +5 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/oracle.py +27 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/solve.sh +4 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/task.toml +25 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/checks.json +58 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/test.sh +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/verify.py +116 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/Dockerfile +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/workdir/fertigation.csv +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/instruction.md +5 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/oracle.py +27 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/solve.sh +4 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/task.toml +25 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/checks.json +58 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/test.sh +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/verify.py +116 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/Dockerfile +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/workdir/fertigation.csv +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/instruction.md +5 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/oracle.py +27 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/solve.sh +4 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/task.toml +25 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/checks.json +58 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/test.sh +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/verify.py +116 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/Dockerfile +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/workdir/fertigation.csv +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/instruction.md +5 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/oracle.py +27 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/solve.sh +4 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/task.toml +25 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/checks.json +58 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/test.sh +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/verify.py +116 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/Dockerfile +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/workdir/fertigation.csv +3 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0018/instruction.md +5 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/oracle.py +27 -0
- tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/solve.sh +4 -0
tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/environment/workdir/fertigation.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop
|
| 2 |
+
T00,3000,161,45,g/L,planned,nursery stock
|
| 3 |
+
T01,2500,184,74,g/L,planned,nursery stock
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Grower Desk: fertigation
|
| 2 |
+
|
| 3 |
+
`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution.
|
| 4 |
+
|
| 5 |
+
Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions.
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent solution from nursery records."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('irrigation.csv').exists():
|
| 11 |
+
for r in read('irrigation.csv'):
|
| 12 |
+
crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10
|
| 13 |
+
out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h']))
|
| 14 |
+
primary='water_m3'
|
| 15 |
+
elif Path('fertigation.csv').exists():
|
| 16 |
+
for r in read('fertigation.csv'):
|
| 17 |
+
stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio
|
| 18 |
+
out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio)
|
| 19 |
+
primary='nutrient_g'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('propagation.csv'):
|
| 22 |
+
initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')]
|
| 23 |
+
out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s)
|
| 24 |
+
primary='saleable'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "grower-desk"
|
| 8 |
+
tags = ["grower-desk", "fertigation", "isced-0812", "eval"]
|
| 9 |
+
isced_f = "0812"
|
| 10 |
+
family = "fertigation"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10000
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.T00.nutrient_g",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 483.0,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.T00.stock_l",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 10.733,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.T00.makeup_water_l",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 2989.267,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.T00.dilution_factor",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 279.503,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.T01.nutrient_g",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 460.0,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.T01.stock_l",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 6.216,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.T01.makeup_water_l",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 2493.784,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.T01.dilution_factor",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 402.174,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/grower-desk/grower-desk-fertigation-d1-e0000/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/environment/workdir/fertigation.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop
|
| 2 |
+
T00,3600,64,29,g/L,planned,nursery stock
|
| 3 |
+
T01,1600,197,76,g/L,planned,nursery stock
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Grower Desk: fertigation
|
| 2 |
+
|
| 3 |
+
`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution.
|
| 4 |
+
|
| 5 |
+
Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions.
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent solution from nursery records."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('irrigation.csv').exists():
|
| 11 |
+
for r in read('irrigation.csv'):
|
| 12 |
+
crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10
|
| 13 |
+
out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h']))
|
| 14 |
+
primary='water_m3'
|
| 15 |
+
elif Path('fertigation.csv').exists():
|
| 16 |
+
for r in read('fertigation.csv'):
|
| 17 |
+
stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio
|
| 18 |
+
out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio)
|
| 19 |
+
primary='nutrient_g'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('propagation.csv'):
|
| 22 |
+
initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')]
|
| 23 |
+
out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s)
|
| 24 |
+
primary='saleable'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "grower-desk"
|
| 8 |
+
tags = ["grower-desk", "fertigation", "isced-0812", "eval"]
|
| 9 |
+
isced_f = "0812"
|
| 10 |
+
family = "fertigation"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10009
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.T00.nutrient_g",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 230.4,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.T00.stock_l",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 7.945,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.T00.makeup_water_l",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 3592.055,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.T00.dilution_factor",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 453.125,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.T01.nutrient_g",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 315.2,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.T01.stock_l",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 4.147,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.T01.makeup_water_l",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 1595.853,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.T01.dilution_factor",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 385.787,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/grower-desk/grower-desk-fertigation-d1-e0009/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/environment/workdir/fertigation.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop
|
| 2 |
+
T00,3700,103,61,g/L,planned,nursery stock
|
| 3 |
+
T01,4000,171,45,g/L,planned,nursery stock
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Grower Desk: fertigation
|
| 2 |
+
|
| 3 |
+
`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution.
|
| 4 |
+
|
| 5 |
+
Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions.
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent solution from nursery records."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('irrigation.csv').exists():
|
| 11 |
+
for r in read('irrigation.csv'):
|
| 12 |
+
crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10
|
| 13 |
+
out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h']))
|
| 14 |
+
primary='water_m3'
|
| 15 |
+
elif Path('fertigation.csv').exists():
|
| 16 |
+
for r in read('fertigation.csv'):
|
| 17 |
+
stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio
|
| 18 |
+
out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio)
|
| 19 |
+
primary='nutrient_g'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('propagation.csv'):
|
| 22 |
+
initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')]
|
| 23 |
+
out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s)
|
| 24 |
+
primary='saleable'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "grower-desk"
|
| 8 |
+
tags = ["grower-desk", "fertigation", "isced-0812", "eval"]
|
| 9 |
+
isced_f = "0812"
|
| 10 |
+
family = "fertigation"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10018
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.T00.nutrient_g",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 381.1,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.T00.stock_l",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 6.248,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.T00.makeup_water_l",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 3693.752,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.T00.dilution_factor",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 592.233,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.T01.nutrient_g",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 684.0,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.T01.stock_l",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 15.2,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.T01.makeup_water_l",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 3984.8,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.T01.dilution_factor",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 263.158,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/grower-desk/grower-desk-fertigation-d1-e0018/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/environment/workdir/fertigation.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop
|
| 2 |
+
T00,1500,111,60,g/L,planned,nursery stock
|
| 3 |
+
T01,3100,95,43,g/L,planned,nursery stock
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Grower Desk: fertigation
|
| 2 |
+
|
| 3 |
+
`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution.
|
| 4 |
+
|
| 5 |
+
Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions.
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent solution from nursery records."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('irrigation.csv').exists():
|
| 11 |
+
for r in read('irrigation.csv'):
|
| 12 |
+
crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10
|
| 13 |
+
out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h']))
|
| 14 |
+
primary='water_m3'
|
| 15 |
+
elif Path('fertigation.csv').exists():
|
| 16 |
+
for r in read('fertigation.csv'):
|
| 17 |
+
stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio
|
| 18 |
+
out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio)
|
| 19 |
+
primary='nutrient_g'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('propagation.csv'):
|
| 22 |
+
initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')]
|
| 23 |
+
out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s)
|
| 24 |
+
primary='saleable'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "grower-desk"
|
| 8 |
+
tags = ["grower-desk", "fertigation", "isced-0812", "train"]
|
| 9 |
+
isced_f = "0812"
|
| 10 |
+
family = "fertigation"
|
| 11 |
+
split = "train"
|
| 12 |
+
seed = 0
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.T00.nutrient_g",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 166.5,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.T00.stock_l",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 2.775,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.T00.makeup_water_l",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 1497.225,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.T00.dilution_factor",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 540.541,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.T01.nutrient_g",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 294.5,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.T01.stock_l",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 6.849,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.T01.makeup_water_l",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 3093.151,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.T01.dilution_factor",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 452.632,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/grower-desk/grower-desk-fertigation-d1-t0000/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/environment/workdir/fertigation.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop
|
| 2 |
+
T00,3000,199,76,g/L,planned,nursery stock
|
| 3 |
+
T01,2200,80,44,g/L,planned,nursery stock
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Grower Desk: fertigation
|
| 2 |
+
|
| 3 |
+
`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution.
|
| 4 |
+
|
| 5 |
+
Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions.
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent solution from nursery records."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('irrigation.csv').exists():
|
| 11 |
+
for r in read('irrigation.csv'):
|
| 12 |
+
crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10
|
| 13 |
+
out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h']))
|
| 14 |
+
primary='water_m3'
|
| 15 |
+
elif Path('fertigation.csv').exists():
|
| 16 |
+
for r in read('fertigation.csv'):
|
| 17 |
+
stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio
|
| 18 |
+
out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio)
|
| 19 |
+
primary='nutrient_g'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('propagation.csv'):
|
| 22 |
+
initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')]
|
| 23 |
+
out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s)
|
| 24 |
+
primary='saleable'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "grower-desk"
|
| 8 |
+
tags = ["grower-desk", "fertigation", "isced-0812", "train"]
|
| 9 |
+
isced_f = "0812"
|
| 10 |
+
family = "fertigation"
|
| 11 |
+
split = "train"
|
| 12 |
+
seed = 9
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.T00.nutrient_g",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 597.0,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.T00.stock_l",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 7.855,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.T00.makeup_water_l",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 2992.145,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.T00.dilution_factor",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 381.91,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.T01.nutrient_g",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 176.0,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.T01.stock_l",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 4.0,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.T01.makeup_water_l",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 2196.0,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.T01.dilution_factor",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 550.0,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/grower-desk/grower-desk-fertigation-d1-t0009/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/grower-desk/grower-desk-fertigation-d1-t0018/environment/workdir/fertigation.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tank_id,final_volume_l,target_mg_l,stock_concentration,stock_unit,status,crop
|
| 2 |
+
T00,2000,193,26,g/L,planned,nursery stock
|
| 3 |
+
T01,2600,188,38,g/L,planned,nursery stock
|
tasks/grower-desk/grower-desk-fertigation-d1-t0018/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Grower Desk: fertigation
|
| 2 |
+
|
| 3 |
+
`fertigation.csv` specifies final tank volumes and the desired concentration of one nutrient. The make-up water contains none of that nutrient; volumes are additive. Convert stock concentration to g/L. For each `tank_id` return `nutrient_g` = final litres*target mg/L/1000, `stock_l` = nutrient g/stock g/L, `makeup_water_l` = final volume minus stock volume, and `dilution_factor` = final volume/stock volume. Final volume already includes the stock solution.
|
| 4 |
+
|
| 5 |
+
Use `status=planned` rows only. Unit conversions: 1 ha = 10,000 m2; 1 m3 = 1000 litres; 1 g = 1000 mg. Write `answer.json` with `results`, keyed by record id. All outputs use 3 decimals, accepted within 0.001. Do not round intermediate values. Coefficients, targets and yields are supplied synthetic planning assumptions.
|
tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent solution from nursery records."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='planned']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('irrigation.csv').exists():
|
| 11 |
+
for r in read('irrigation.csv'):
|
| 12 |
+
crop=float(r['kc'])*float(r['eto_mm']);net=max(crop-float(r['effective_rain_mm']),0);gross=net/float(r['application_efficiency']);hectares=float(r['area'])/(10000 if r['area_unit']=='m2' else 1);vol=gross*hectares*10
|
| 13 |
+
out[r['zone_id']]=dict(crop_et_mm=crop,net_mm=net,gross_mm=gross,water_m3=vol,runtime_h=vol/float(r['flow_m3_h']))
|
| 14 |
+
primary='water_m3'
|
| 15 |
+
elif Path('fertigation.csv').exists():
|
| 16 |
+
for r in read('fertigation.csv'):
|
| 17 |
+
stock_mg=float(r['stock_concentration'])*(1000 if r['stock_unit']=='g/L' else 1);final=float(r['final_volume_l']);ratio=float(r['target_mg_l'])/stock_mg;stock=final*ratio
|
| 18 |
+
out[r['tank_id']]=dict(nutrient_g=stock*stock_mg/1000,stock_l=stock,makeup_water_l=final*(1-ratio),dilution_factor=1/ratio)
|
| 19 |
+
primary='nutrient_g'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('propagation.csv'):
|
| 22 |
+
initial=int(r['trays'])*int(r['cells_per_tray'])*int(r['seeds_per_cell']);g,t,s=[float(r[k])/100 for k in ('germination_percent','transplant_survival_percent','sale_grade_percent')]
|
| 23 |
+
out[r['lot_id']]=dict(germinated=initial*g,transplanted=initial*g*t,saleable=initial*g*t*s,overall_yield_percent=100*g*t*s)
|
| 24 |
+
primary='saleable'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/grower-desk/grower-desk-fertigation-d1-t0018/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|