diff --git a/tasks/food-batch/food-batch-blending-d1-e0000/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-e0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-e0000/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-e0000/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..297faeb06520f2603f7623a407bcd1751a9101ae --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0000/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,460,kg,6,48,24,0,approved +B01,788,kg,3,41,20,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-e0000/instruction.md b/tasks/food-batch/food-batch-blending-d1-e0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0000/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-e0000/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-e0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0000/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-e0000/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-e0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-e0000/task.toml b/tasks/food-batch/food-batch-blending-d1-e0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d1c042dfffb1a7cc5909f11d0a37c4e687ee30d7 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-e0000/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-e0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..84add56b1196af5cd1f37f0204feb3c68ea597ec --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0000/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 460.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 197.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 262.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 110.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 788.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 352.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 435.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 157.6, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-e0000/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-e0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-e0000/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-e0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-e0009/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-e0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-e0009/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-e0009/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..c2495b32342d7357e3b6dac6cf842242205f7ce7 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0009/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,711,kg,9,44,20,0,approved +B01,320,kg,3,46,25,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-e0009/instruction.md b/tasks/food-batch/food-batch-blending-d1-e0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0009/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-e0009/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-e0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0009/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-e0009/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-e0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-e0009/task.toml b/tasks/food-batch/food-batch-blending-d1-e0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..75a152ade81cb2b476bbe2a388c6247f73b09f85 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-e0009/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-e0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9bf0934d9bb05b45f300bc45ed44fd7cc882cb20 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0009/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 711.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 223.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 487.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 142.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 320.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 163.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 156.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 80.0, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-e0009/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-e0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-e0009/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-e0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-e0018/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-e0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-e0018/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-e0018/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..7f731da240c05414723c3af9f97f30c76fe8fe0a --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0018/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,817,kg,6,38,18,0,approved +B01,947,kg,5,37,21,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-e0018/instruction.md b/tasks/food-batch/food-batch-blending-d1-e0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0018/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-e0018/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-e0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0018/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-e0018/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-e0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-e0018/task.toml b/tasks/food-batch/food-batch-blending-d1-e0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2aeae16a2062ca0c3df2a4350d151c40be0ce30b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-e0018/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-e0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c4da11e09a0cd1db9ffaa365fb3afcaf653600db --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-e0018/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 817.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 306.38, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 510.62, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 147.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 947.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 473.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 473.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 198.87, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-e0018/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-e0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-e0018/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-e0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0000/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0000/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0000/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..5f00262dfb4363159b568ac3ad766ceb9c10d606 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0000/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,1089,kg,4,32,25,0,approved +B01,538,kg,9,50,24,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0000/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0000/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0000/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0000/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0000/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0000/task.toml b/tasks/food-batch/food-batch-blending-d1-t0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0625e295adcc3b17f9d65058eb2b26235509759e --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0000/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..920eda903eed181a9a73f3de55b20743e806f0a0 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0000/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1089.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 816.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 272.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 272.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 538.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 196.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 341.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 129.12, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0000/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0000/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0009/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0009/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0009/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..3590102c07dd7127bc9a653c0b1bfeb92fc3138b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0009/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,1001,kg,6,43,15,0,approved +B01,363,kg,4,50,25,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0009/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0009/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0009/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0009/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0009/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0009/task.toml b/tasks/food-batch/food-batch-blending-d1-t0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..07f53cd8126d99956f6cadd39454d1dda7c69e06 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0009/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9df2c6e61b7e86be245c8f7e1de442bbad8eef4a --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0009/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1001.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 243.49, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 757.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 150.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 363.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 165.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 197.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 90.75, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0009/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0009/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0018/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0018/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0018/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..5ca8c3faa1508dc535a78fababb139eddfe9731b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0018/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,277,kg,10,31,23,0,approved +B01,946,kg,6,38,21,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0018/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0018/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0018/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0018/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0018/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0018/task.toml b/tasks/food-batch/food-batch-blending-d1-t0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d307447328231d5ace9232e06a17eacdca7c7495 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0018/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..70143513716daadbc25216d5e93566129995b366 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0018/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 277.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 171.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 105.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 63.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 946.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 443.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 502.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 198.66, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0018/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0018/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0027/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0027/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0027/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0027/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0027/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..8d2a2cfe239c3ab19fb26d887f9ad68e1bf1eeb5 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0027/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,960,kg,3,45,17,0,approved +B01,620,kg,7,48,19,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0027/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0027/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0027/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0027/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0027/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0027/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0027/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0027/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0027/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0027/task.toml b/tasks/food-batch/food-batch-blending-d1-t0027/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bfee66c07b478d5790323a504a061b41f5ad47ac --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0027/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0027/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0027/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d01b21cf4698db3735efaa0793fc5bc59a2a0a4b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0027/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 960.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 320.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 640.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 163.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 620.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 181.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 438.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 117.8, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0027/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0027/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0027/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0027/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0036/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0036/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0036/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0036/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0036/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..580521c60f696f9575bbd9233013a64dac5b346c --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0036/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,1032,kg,8,37,16,0,approved +B01,704,kg,9,33,15,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0036/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0036/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0036/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0036/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0036/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0036/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0036/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0036/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0036/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0036/task.toml b/tasks/food-batch/food-batch-blending-d1-t0036/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5dc82d2593c066414b67afd04c65e89a0e5d258d --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0036/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0036/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0036/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5bdc7dc10fe17c291e8d4c95414cb09c5f4557f5 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0036/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1032.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 284.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 747.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 165.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 704.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 176.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 528.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 105.6, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0036/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0036/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0036/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0036/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0045/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0045/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0045/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0045/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0045/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..d5bd9aec2462bb6becce866aeafeb41a174a9117 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0045/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,934,kg,12,41,18,0,approved +B01,217,kg,10,42,24,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0045/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0045/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0045/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0045/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0045/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0045/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0045/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0045/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0045/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0045/task.toml b/tasks/food-batch/food-batch-blending-d1-t0045/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b668c7c58ffb022524b71f743dfb80b2b8857ac4 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0045/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0045/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0045/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d84ec81c3ba0b52c49ee2f75d610c2b72d9eaf70 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0045/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 934.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 193.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 740.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 168.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 217.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 94.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 122.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 52.08, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0045/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0045/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0045/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0045/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0054/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0054/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0054/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0054/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0054/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..21326ea62e0dd1673f98d02421ce839ea41a7699 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0054/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,532,kg,11,36,20,0,approved +B01,434,kg,8,38,18,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0054/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0054/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0054/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0054/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0054/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0054/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0054/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0054/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0054/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0054/task.toml b/tasks/food-batch/food-batch-blending-d1-t0054/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..078b04149d465eb1d8238d8372ea4370ef80521d --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0054/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0054/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0054/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f701cff6735a4811f0b3786e4c1a1364b08f7fec --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0054/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 532.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 191.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 340.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 106.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 434.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 144.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 289.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 78.12, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0054/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0054/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0054/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0054/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0063/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0063/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0063/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0063/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0063/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..cbf17b7b3bb38a5bb92e31990109f11bd48b93e2 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0063/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,598,kg,8,30,25,0,approved +B01,386,kg,8,48,22,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0063/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0063/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0063/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0063/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0063/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0063/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0063/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0063/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0063/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0063/task.toml b/tasks/food-batch/food-batch-blending-d1-t0063/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..be15e6be64da5eee10b4fbdd934b82d7627c5508 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0063/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0063/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0063/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ca068047d693141bd0d674f96a834022a4dcbf86 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0063/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 598.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 462.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 135.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 149.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 386.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 135.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 250.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 84.92, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0063/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0063/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0063/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0063/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0072/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0072/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0072/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0072/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0072/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..ce8244beea92c218b9f15f3190415f05ed47eb5c --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0072/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,203,kg,7,48,15,0,approved +B01,497,kg,10,49,19,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0072/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0072/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0072/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0072/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0072/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0072/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0072/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0072/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0072/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0072/task.toml b/tasks/food-batch/food-batch-blending-d1-t0072/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d23f0eb6d0ea7dec796677ffbd3d3be7d3d3d332 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0072/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0072/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0072/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..065eb5cc9b491b97f4e9e640bbed72112f4cb5eb --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0072/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 203.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 39.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 163.39, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 30.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 497.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 114.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 382.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 94.43, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0072/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0072/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0072/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0072/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0081/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d1-t0081/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0081/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d1-t0081/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d1-t0081/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..f70ec94ac51a55a8ee91c22e38af6a7fd9c5fd7c --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0081/environment/workdir/blends.csv @@ -0,0 +1,3 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,1094,kg,3,48,19,0,approved +B01,214,kg,6,40,16,0,approved diff --git a/tasks/food-batch/food-batch-blending-d1-t0081/instruction.md b/tasks/food-batch/food-batch-blending-d1-t0081/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0081/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d1-t0081/solution/oracle.py b/tasks/food-batch/food-batch-blending-d1-t0081/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0081/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d1-t0081/solution/solve.sh b/tasks/food-batch/food-batch-blending-d1-t0081/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0081/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d1-t0081/task.toml b/tasks/food-batch/food-batch-blending-d1-t0081/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d0ffe4e2c5901c19bb5119cae6780fb5d9a49f10 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0081/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d1-t0081/tests/checks.json b/tasks/food-batch/food-batch-blending-d1-t0081/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bdd1bbcf55762aab0ecd958b94e98ad0fe2d1730 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d1-t0081/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1094.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 388.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 705.02, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 207.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 214.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 62.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 151.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 34.24, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d1-t0081/tests/test.sh b/tasks/food-batch/food-batch-blending-d1-t0081/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d1-t0081/tests/verify.py b/tasks/food-batch/food-batch-blending-d1-t0081/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-e0003/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-e0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-e0003/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-e0003/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..0ed4c2638569d1b067917484b1781c9e9accc86d --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0003/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +TRIAL,99999,kg,7,47,25,0,trial +B00,909,kg,7,47,25,0,approved +B02,1155,kg,3,38,19,0,approved +B01,526,kg,2,42,22,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-e0003/instruction.md b/tasks/food-batch/food-batch-blending-d2-e0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0003/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-e0003/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-e0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0003/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-e0003/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-e0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-e0003/task.toml b/tasks/food-batch/food-batch-blending-d2-e0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..794b7a4b7cc5cfda6fa6cadd249f1462e72fdc97 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-e0003/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-e0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d7c347567dbf1a345471cf2cdc428296944f521d --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0003/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 909.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 409.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 499.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 227.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 526.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 263.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 263.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 115.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 1155.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 528.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 627.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 219.45, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-e0003/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-e0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-e0003/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-e0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-e0012/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-e0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-e0012/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-e0012/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..e891978ebc71b4326a3e5bf2d10497ba3d0ceaea --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0012/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +TRIAL,99999,kg,6,49,16,0,trial +B00,229,kg,6,49,16,0,approved +B02,205,kg,4,48,15,0,approved +B01,1149,kg,7,34,15,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-e0012/instruction.md b/tasks/food-batch/food-batch-blending-d2-e0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0012/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-e0012/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-e0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0012/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-e0012/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-e0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-e0012/task.toml b/tasks/food-batch/food-batch-blending-d2-e0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1e4e8ac2011cad094bec2c5e120378a4117f9453 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-e0012/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-e0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4b4747a3e3463c0c4aab24deeace3e2e7bf709f6 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0012/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 229.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 53.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 175.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 36.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 1149.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 340.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 808.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 172.35, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 205.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 51.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 153.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 30.75, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-e0012/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-e0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-e0012/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-e0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-e0021/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-e0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-e0021/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-e0021/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..63952153fe1f383563ccfbf2f2540249db3b1fb8 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0021/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,423,kg,2,41,22,0,approved +B01,677,kg,5,30,22,0,approved +B02,924,kg,11,39,18,0,approved +TRIAL,99999,kg,2,41,22,0,trial diff --git a/tasks/food-batch/food-batch-blending-d2-e0021/instruction.md b/tasks/food-batch/food-batch-blending-d2-e0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0021/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-e0021/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-e0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0021/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-e0021/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-e0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-e0021/task.toml b/tasks/food-batch/food-batch-blending-d2-e0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2a0d905faf42267aa5ea480eb207a585d85180ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-e0021/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-e0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5ad9458151edf4a2334740c754edcc4ff3647ed9 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-e0021/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 423.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 216.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 206.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 93.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 677.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 460.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 216.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 148.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 924.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 231.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 693.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 166.32, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-e0021/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-e0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-e0021/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-e0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0003/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0003/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0003/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..53d3a1ac24952fd8f5019a71c94d3421d78c60cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0003/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B02,299,kg,10,46,23,0,approved +B01,555,kg,10,45,21,0,approved +TRIAL,99999,kg,9,46,19,0,trial +B00,996,kg,9,46,19,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-t0003/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0003/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0003/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0003/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0003/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0003/task.toml b/tasks/food-batch/food-batch-blending-d2-t0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d4db34867b7eca000102dcb80ab4e9e3b908484c --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0003/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3d13ca3d3e1e3e32d6823c7b9dce4184b79ee89f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0003/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 996.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 269.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 726.81, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 189.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 555.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 174.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 380.57, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 116.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 299.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 107.97, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 191.03, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 68.77, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0003/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0003/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0012/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0012/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0012/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..ef4a8359d11b7ab1f713ac4cb2c718cc14381252 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0012/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +TRIAL,99999,kg,6,50,19,0,trial +B00,932,kg,6,50,19,0,approved +B02,279,kg,10,47,15,0,approved +B01,733,kg,4,49,15,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-t0012/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0012/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0012/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0012/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0012/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0012/task.toml b/tasks/food-batch/food-batch-blending-d2-t0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2fb51b0558a58bfb5f07d2ab7f4f0d886d3d868d --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0012/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..afe9381578dc3d6f7d47c3a418b2893a32dd83b7 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0012/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 932.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 275.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 656.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 177.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 733.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 179.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 553.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 109.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 279.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 37.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 241.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 41.85, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0012/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0012/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0021/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0021/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0021/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..1de1071065e6d47d8d58f7de1c7fb6b6e9e50cd0 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0021/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B02,805,kg,6,45,16,0,approved +B00,337,kg,11,32,16,0,approved +B01,888,kg,4,44,19,0,approved +TRIAL,99999,kg,11,32,16,0,trial diff --git a/tasks/food-batch/food-batch-blending-d2-t0021/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0021/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0021/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0021/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0021/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0021/task.toml b/tasks/food-batch/food-batch-blending-d2-t0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dc29e7930c5c6133e9c1c233a9e046813bfe0c1b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0021/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..531a9df7e9206b443ae8fa0410c33ff8d8913f49 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0021/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 337.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 80.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 256.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 53.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 888.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 333.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 555.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 168.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 805.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 206.41, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 598.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 128.8, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0021/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0021/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0030/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0030/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0030/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0030/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0030/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..dcff5e54f604f2976434e985c66cd0cc7f6140c6 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0030/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B01,472,kg,7,43,17,0,approved +B02,1124,kg,11,35,15,0,approved +TRIAL,99999,kg,6,34,15,0,trial +B00,786,kg,6,34,15,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-t0030/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0030/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0030/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0030/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0030/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0030/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0030/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0030/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0030/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0030/task.toml b/tasks/food-batch/food-batch-blending-d2-t0030/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dc35539668d94a3b8872824f5487c1db7ee17e1b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0030/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0030/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0030/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..59315e5ec9277c3d68bc753b41377b5a28641598 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0030/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 786.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 252.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 533.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 117.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 472.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 131.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 340.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 80.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 1124.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 187.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 936.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 168.6, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0030/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0030/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0030/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0030/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0039/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0039/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0039/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0039/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0039/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..efa6236b792825960eb8646733788bff2f36b733 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0039/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B02,666,kg,10,43,20,0,approved +B01,553,kg,3,48,21,0,approved +TRIAL,99999,kg,3,42,17,0,trial +B00,940,kg,3,42,17,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-t0039/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0039/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0039/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0039/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0039/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0039/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0039/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0039/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0039/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0039/task.toml b/tasks/food-batch/food-batch-blending-d2-t0039/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..80180008d8dc47632e016f812a063e21d38b3309 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0039/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0039/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0039/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e82287d9b5a16064d3dca3dae1a3b52d4f8aaf3b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0039/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 940.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 337.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 602.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 159.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 553.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 221.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 331.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 116.13, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 666.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 201.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 464.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 133.2, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0039/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0039/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0039/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0039/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0048/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0048/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0048/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0048/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0048/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..c796189504c989f0b96b8097337ae9581a14b4cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0048/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B01,896,kg,12,33,19,0,approved +B02,557,kg,8,30,24,0,approved +TRIAL,99999,kg,8,50,24,0,trial +B00,1159,kg,8,50,24,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-t0048/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0048/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0048/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0048/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0048/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0048/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0048/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0048/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0048/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0048/task.toml b/tasks/food-batch/food-batch-blending-d2-t0048/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..18952c7de6cdb6101ab747b3c949167c7c8109ea --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0048/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0048/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0048/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..84f18325b421259c77a77b2d71ecac63be431cc0 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0048/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1159.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 441.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 717.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 278.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 896.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 298.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 597.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 170.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 557.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 405.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 151.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 133.68, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0048/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0048/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0048/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0048/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0057/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0057/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0057/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0057/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0057/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..3138b6e2fcd56ebb9a4eea6781be5c414790325f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0057/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B01,682,kg,11,43,15,0,approved +B02,729,kg,9,34,15,0,approved +B00,894,kg,9,31,21,0,approved +TRIAL,99999,kg,9,31,21,0,trial diff --git a/tasks/food-batch/food-batch-blending-d2-t0057/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0057/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0057/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0057/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0057/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0057/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0057/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0057/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0057/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0057/task.toml b/tasks/food-batch/food-batch-blending-d2-t0057/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e23acc9cd7de5ecf847874ed508d8a49439bd469 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0057/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0057/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0057/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ed6aff59abf9a1a28ca433f009ba816756a3b004 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0057/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 894.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 487.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 406.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 187.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 682.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 85.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 596.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 102.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 729.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 174.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 554.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 109.35, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0057/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0057/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0057/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0057/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0066/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0066/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0066/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0066/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0066/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..afc12bc91047d5458f67a0e47876ca2e2407ff59 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0066/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B02,1166,kg,11,47,23,0,approved +B01,798,kg,6,32,18,0,approved +B00,1043,kg,4,34,25,0,approved +TRIAL,99999,kg,4,34,25,0,trial diff --git a/tasks/food-batch/food-batch-blending-d2-t0066/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0066/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0066/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0066/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0066/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0066/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0066/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0066/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0066/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0066/task.toml b/tasks/food-batch/food-batch-blending-d2-t0066/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..841730fb844ee0355c6282570a693bf9d40f1617 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0066/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0066/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0066/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..50f895c94784da8974e54d79907ae30cf02ff1a0 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0066/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1043.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 730.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 312.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 260.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 798.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 368.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 429.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 143.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 1166.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 388.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 777.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 268.18, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0066/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0066/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0066/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0066/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0075/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d2-t0075/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0075/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d2-t0075/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d2-t0075/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..467f442b2beb21bda0afcdb685d687c584c37332 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0075/environment/workdir/blends.csv @@ -0,0 +1,5 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +TRIAL,99999,kg,9,34,16,0,trial +B02,723,kg,6,30,18,0,approved +B01,590,kg,11,39,24,0,approved +B00,1165,kg,9,34,16,0,approved diff --git a/tasks/food-batch/food-batch-blending-d2-t0075/instruction.md b/tasks/food-batch/food-batch-blending-d2-t0075/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..631b98d7e929c31e80b4d7035eb51fabe685e542 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0075/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d2-t0075/solution/oracle.py b/tasks/food-batch/food-batch-blending-d2-t0075/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0075/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d2-t0075/solution/solve.sh b/tasks/food-batch/food-batch-blending-d2-t0075/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0075/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d2-t0075/task.toml b/tasks/food-batch/food-batch-blending-d2-t0075/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..413fe5af4577c8db58f8074bd30ec346da86c374 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0075/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d2-t0075/tests/checks.json b/tasks/food-batch/food-batch-blending-d2-t0075/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..adb9f7653137348cbbaf892ae8b07abad72b0be6 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d2-t0075/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1165.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 326.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 838.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 186.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 590.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 273.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 316.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 141.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 723.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 361.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 361.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 130.14, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d2-t0075/tests/test.sh b/tasks/food-batch/food-batch-blending-d2-t0075/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d2-t0075/tests/verify.py b/tasks/food-batch/food-batch-blending-d2-t0075/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-e0006/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-e0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-e0006/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-e0006/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..729471e88fc92cf19920336e8ff08e1562ccc721 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0006/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B01,1106000,g,12,42,18,2,approved +TRIAL,99999,kg,9,41,18,2,trial +B02,633,kg,2,33,19,4,approved +B03,326000,g,8,34,18,6,approved +B00,1039,kg,9,41,18,2,approved diff --git a/tasks/food-batch/food-batch-blending-d3-e0006/instruction.md b/tasks/food-batch/food-batch-blending-d3-e0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0006/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-e0006/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-e0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0006/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-e0006/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-e0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-e0006/task.toml b/tasks/food-batch/food-batch-blending-d3-e0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..af6ba0da0cf673e0a81bbb1193306a8a88ff035b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-e0006/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-e0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..88a1cc273b9c5e696833c18dcb8877f1cbffa9cc --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0006/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1060.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 298.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 762.02, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 187.02, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 1128.57, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 225.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 902.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 199.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 659.38, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 361.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 297.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 120.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 346.81, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 133.39, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 213.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 58.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3194.96, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-e0006/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-e0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-e0006/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-e0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-e0015/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-e0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-e0015/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-e0015/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..b47c0afc7ed9ec8817285f731b751e4070298aeb --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0015/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B03,464000,g,7,33,17,2,approved +B01,987000,g,6,34,15,6,approved +B02,442,kg,5,41,24,4,approved +B00,578,kg,12,46,18,4,approved +TRIAL,99999,kg,12,46,18,4,trial diff --git a/tasks/food-batch/food-batch-blending-d3-e0015/instruction.md b/tasks/food-batch/food-batch-blending-d3-e0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0015/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-e0015/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-e0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0015/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-e0015/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-e0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-e0015/task.toml b/tasks/food-batch/food-batch-blending-d3-e0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..82d4e212a734b545c32db7cb7e6ae23c17f33d4c --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "eval"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-e0015/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-e0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..023b428c6cde4be24c4dbfc6fb81b2be6e8feb83 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-e0015/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 602.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 106.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 495.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 104.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 1050.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 337.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 712.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 148.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 460.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 243.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 217.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 106.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 473.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 182.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 291.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 78.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 2585.97, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-e0015/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-e0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-e0015/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-e0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0006/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0006/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0006/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..d763dcfbd70cf4e73750d148a2a60c3aab5e330f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0006/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +TRIAL,99999,kg,8,39,16,4,trial +B03,732000,g,3,34,17,6,approved +B02,607,kg,8,50,25,4,approved +B00,548,kg,8,39,16,4,approved +B01,804000,g,3,48,17,2,approved diff --git a/tasks/food-batch/food-batch-blending-d3-t0006/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0006/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0006/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0006/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0006/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0006/task.toml b/tasks/food-batch/food-batch-blending-d3-t0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9df04ef40da53d41a1d4ef87537e387054798844 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0006/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cc3f758c5ff6935f9c5a6c0d98e0e8c34dfd7e68 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0006/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 570.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 147.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 423.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 87.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 820.41, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 255.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 565.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 136.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 632.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 255.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 376.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 151.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 778.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 351.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 427.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 124.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 2802.26, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0006/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0006/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0015/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0015/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0015/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..6ec983d7cfc0933154c62ee438c7a2359bf692e0 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0015/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B01,988000,g,6,40,21,2,approved +B02,1173,kg,3,48,20,6,approved +B00,913,kg,7,30,21,6,approved +TRIAL,99999,kg,7,30,21,6,trial +B03,1112000,g,10,47,24,4,approved diff --git a/tasks/food-batch/food-batch-blending-d3-t0015/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0015/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0015/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0015/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0015/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0015/task.toml b/tasks/food-batch/food-batch-blending-d3-t0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..400974d89d90086f7107e0fbcb50e69ce17adf73 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0015/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..45093828b6b3252a71311cf34ed546c1536a5d9b --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0015/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 971.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 591.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 380.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 191.73, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 1008.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 444.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 563.39, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 207.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 1247.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 471.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 776.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 234.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 1158.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 438.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 720.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 266.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4385.65, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0015/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0015/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0024/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0024/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0024/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0024/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0024/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..dbc1e04af63379567ba8d033ba046d26414fa799 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0024/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +TRIAL,99999,kg,9,32,20,6,trial +B03,703000,g,9,42,23,6,approved +B01,440000,g,12,46,18,2,approved +B00,838,kg,9,32,20,6,approved +B02,1099,kg,12,45,21,4,approved diff --git a/tasks/food-batch/food-batch-blending-d3-t0024/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0024/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0024/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0024/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0024/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0024/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0024/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0024/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0024/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0024/task.toml b/tasks/food-batch/food-batch-blending-d3-t0024/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5c1b245dc7e3b0c27cf909531f667c2b5b01c5c3 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0024/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0024/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0024/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..57dbd4f1c3a70ef57f61b6c0fc20927e8ce95378 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0024/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 891.49, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 426.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 465.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 167.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 448.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 79.23, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 369.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 79.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 1144.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 312.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 832.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 230.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 747.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 317.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 430.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 161.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3233.13, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0024/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0024/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0024/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0024/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0033/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0033/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0033/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0033/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0033/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..b448627628aff5c8437198a97e4430b3868c4589 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0033/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B03,301000,g,6,41,21,6,approved +B02,1028,kg,8,49,19,4,approved +B00,966,kg,7,43,23,6,approved +TRIAL,99999,kg,7,43,23,6,trial +B01,984000,g,7,35,23,6,approved diff --git a/tasks/food-batch/food-batch-blending-d3-t0033/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0033/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0033/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0033/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0033/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0033/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0033/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0033/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0033/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0033/task.toml b/tasks/food-batch/food-batch-blending-d3-t0033/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9e9074054cd3455cecc3241fddba980e95bbd838 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0033/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0033/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0033/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2996b86b7461c37fab8e2853723c60b7b19050e2 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0033/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 1027.66, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 456.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 570.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 222.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 1046.81, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 598.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 448.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 226.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 1070.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 287.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 783.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 195.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 320.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 137.23, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 182.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 63.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3465.51, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0033/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0033/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0033/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0033/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0042/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0042/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0042/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0042/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0042/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..d113d4419e89444909db537969a9bd941f43812c --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0042/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B03,1158000,g,11,47,15,6,approved +B01,1053000,g,4,48,23,4,approved +B00,397,kg,6,46,24,6,approved +TRIAL,99999,kg,6,46,24,6,trial +B02,1091,kg,11,42,23,6,approved diff --git a/tasks/food-batch/food-batch-blending-d3-t0042/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0042/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0042/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0042/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0042/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0042/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0042/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0042/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0042/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0042/task.toml b/tasks/food-batch/food-batch-blending-d3-t0042/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..37f8e3c0a0cf6d91c416587472d73821cd888d8f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0042/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0042/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0042/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..59517f3170e6edcfd988cfea71ce195d7aed8bd2 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0042/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 422.34, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 190.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 232.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 95.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 1096.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 473.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 623.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 242.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 1160.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 449.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 711.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 250.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 1231.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 136.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 1095.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 173.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3911.77, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0042/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0042/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0042/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0042/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0051/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0051/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0051/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0051/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0051/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..c8f12552e0ffe4c8330555df893f72ee3fdd202c --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0051/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B02,748,kg,9,38,17,4,approved +B03,1005000,g,4,33,15,6,approved +B00,907,kg,10,34,23,6,approved +B01,652000,g,7,33,22,6,approved +TRIAL,99999,kg,10,34,23,6,trial diff --git a/tasks/food-batch/food-batch-blending-d3-t0051/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0051/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0051/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0051/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0051/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0051/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0051/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0051/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0051/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0051/task.toml b/tasks/food-batch/food-batch-blending-d3-t0051/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2e01731974db85f9399bcd5ded2b8a62911a3f0e --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0051/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0051/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0051/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..48d4b7eafcfc656802f68b98f52c0128e5802669 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0051/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 964.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 522.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 442.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 208.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 693.62, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 400.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 293.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 143.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 779.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 214.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 564.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 127.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 1069.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 405.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 663.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 150.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3506.83, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0051/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0051/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0051/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0051/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0060/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0060/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0060/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0060/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0060/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..d3c29e3289ccca90ef44d6899e2302eda16c3599 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0060/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B00,905,kg,4,45,22,6,approved +B03,974000,g,9,34,22,2,approved +B01,1095000,g,6,30,18,4,approved +B02,901,kg,6,49,24,6,approved +TRIAL,99999,kg,4,45,22,6,trial diff --git a/tasks/food-batch/food-batch-blending-d3-t0060/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0060/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0060/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0060/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0060/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0060/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0060/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0060/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0060/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0060/task.toml b/tasks/food-batch/food-batch-blending-d3-t0060/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..91f35b60dd4d327c3c6aca7ce12bcd887bda70c1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0060/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0060/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0060/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..866182bdc5fb908d42e5d0c21323f5cb42c4e1b3 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0060/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 962.77, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 422.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 540.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 199.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 1140.62, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 570.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 570.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 197.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 958.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 401.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 557.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 216.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 993.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 516.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 477.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 214.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4055.78, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0060/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0060/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0060/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0060/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0069/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0069/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0069/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0069/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0069/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..b42bed35c126cb7c1f88a17133ac971124ec9326 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0069/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B02,601,kg,6,44,25,4,approved +B00,640,kg,11,44,23,6,approved +B03,356000,g,5,42,23,4,approved +TRIAL,99999,kg,11,44,23,6,trial +B01,708000,g,5,39,15,2,approved diff --git a/tasks/food-batch/food-batch-blending-d3-t0069/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0069/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0069/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0069/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0069/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0069/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0069/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0069/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0069/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0069/task.toml b/tasks/food-batch/food-batch-blending-d3-t0069/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..446069cd1eab3c98767b3b3f633690c5efb66e26 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0069/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0069/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0069/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..998bdadb1cf9d4823ba51ae853a3185d2f4913c1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0069/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 680.85, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 247.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 433.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 147.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 722.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 212.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 509.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 106.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 626.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 313.02, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 313.02, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 150.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 370.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 180.41, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 190.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 81.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 2400.18, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0069/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0069/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0069/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0069/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0078/environment/Dockerfile b/tasks/food-batch/food-batch-blending-d3-t0078/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0078/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-blending-d3-t0078/environment/workdir/blends.csv b/tasks/food-batch/food-batch-blending-d3-t0078/environment/workdir/blends.csv new file mode 100644 index 0000000000000000000000000000000000000000..99731fca9f08d36c5166b69fc786297792e45404 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0078/environment/workdir/blends.csv @@ -0,0 +1,6 @@ +batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status +B02,319,kg,3,37,21,4,approved +TRIAL,99999,kg,8,34,20,2,trial +B01,289000,g,12,50,22,2,approved +B03,855000,g,2,47,22,2,approved +B00,699,kg,8,34,20,2,approved diff --git a/tasks/food-batch/food-batch-blending-d3-t0078/instruction.md b/tasks/food-batch/food-batch-blending-d3-t0078/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..64e26be5dcc224326479d8902ac51d8437e0a3f1 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0078/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: blending + +`blends.csv` gives two ingredient concentrations (mass percentages of one component), the target concentration and finished mass. Find the masses to charge before a uniform process loss that removes the same fraction of both ingredients and their components. For each batch id return `charge_kg` = finished/(1-loss/100), `high_kg` = charge*(target-low)/(high-low), `low_kg` = charge-high mass, and `retained_component_kg` = finished*target/100. Targets lie strictly between the two ingredient concentrations. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `charge_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-blending-d3-t0078/solution/oracle.py b/tasks/food-batch/food-batch-blending-d3-t0078/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0078/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-blending-d3-t0078/solution/solve.sh b/tasks/food-batch/food-batch-blending-d3-t0078/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0078/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-blending-d3-t0078/task.toml b/tasks/food-batch/food-batch-blending-d3-t0078/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0b1a3fc7e22f42f5f64d282618a3d07fb3a41e7a --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0078/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "blending", "isced-0721", "train"] +isced_f = "0721" +family = "blending" +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/food-batch/food-batch-blending-d3-t0078/tests/checks.json b/tasks/food-batch/food-batch-blending-d3-t0078/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b764425b7e541ae3639931b7e6fd08ffa48d0dab --- /dev/null +++ b/tasks/food-batch/food-batch-blending-d3-t0078/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.charge_kg", + "type": "number", + "value": 713.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.high_kg", + "type": "number", + "value": 329.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.low_kg", + "type": "number", + "value": 384.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_component_kg", + "type": "number", + "value": 139.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.charge_kg", + "type": "number", + "value": 294.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.high_kg", + "type": "number", + "value": 77.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.low_kg", + "type": "number", + "value": 217.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_component_kg", + "type": "number", + "value": 63.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.charge_kg", + "type": "number", + "value": 332.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.high_kg", + "type": "number", + "value": 175.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.low_kg", + "type": "number", + "value": 156.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_component_kg", + "type": "number", + "value": 66.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.charge_kg", + "type": "number", + "value": 872.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.high_kg", + "type": "number", + "value": 387.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.low_kg", + "type": "number", + "value": 484.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_component_kg", + "type": "number", + "value": 188.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 2212.9, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-blending-d3-t0078/tests/test.sh b/tasks/food-batch/food-batch-blending-d3-t0078/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-blending-d3-t0078/tests/verify.py b/tasks/food-batch/food-batch-blending-d3-t0078/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-blending-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/food-batch/food-batch-drying-d1-e0001/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-e0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-e0001/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-e0001/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..f29a41b1b9e74cc8103f173881847b98cefaf059 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0001/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2787,kg,59,10,0,approved +B01,2237,kg,31,11,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-e0001/instruction.md b/tasks/food-batch/food-batch-drying-d1-e0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0001/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-e0001/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-e0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0001/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-e0001/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-e0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-e0001/task.toml b/tasks/food-batch/food-batch-drying-d1-e0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d66673218e89e9c640f37c0c89483393513391c1 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-e0001/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-e0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e605d8c83368f165ddac1fe64c3b5d263d547bbf --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0001/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1142.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1142.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1269.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1517.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1543.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1543.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1734.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 502.7, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-e0001/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-e0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-e0001/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-e0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-e0010/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-e0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-e0010/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-e0010/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..f7bcaf42a802e9ae68c5a490c412ecb87b5ae904 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0010/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,1727,kg,30,12,0,approved +B01,2488,kg,55,8,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-e0010/instruction.md b/tasks/food-batch/food-batch-drying-d1-e0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0010/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-e0010/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-e0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0010/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-e0010/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-e0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-e0010/task.toml b/tasks/food-batch/food-batch-drying-d1-e0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..63eef18f871427bfd77d4701ce0581ed626aa83b --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-e0010/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-e0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b529366088ad07f08bf9a09d06dccad49c5128c4 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0010/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1208.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1208.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1373.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 353.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1119.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1119.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1216.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 1271.04, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-e0010/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-e0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-e0010/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-e0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-e0019/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-e0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-e0019/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-e0019/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..50d9c8861583fbd4248da44dca15e87275412e63 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0019/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,1048,kg,55,17,0,approved +B01,768,kg,39,10,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-e0019/instruction.md b/tasks/food-batch/food-batch-drying-d1-e0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0019/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-e0019/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-e0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0019/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-e0019/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-e0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-e0019/task.toml b/tasks/food-batch/food-batch-drying-d1-e0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0ba1d736169158227131daae346ef663cf0ce3bb --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-e0019/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-e0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bf8e41f2fe82bdb15d99c4c4d0b1b979517ebb93 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-e0019/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 471.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 471.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 568.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 479.81, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 468.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 468.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 520.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 247.47, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-e0019/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-e0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-e0019/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-e0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0001/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0001/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0001/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..265055354b364ea0c247b8c09dd4163aa05b01b7 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0001/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2859,kg,50,16,0,approved +B01,1862,kg,31,10,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0001/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0001/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0001/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0001/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0001/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0001/task.toml b/tasks/food-batch/food-batch-drying-d1-t0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..821a69d6b25f99e73917c139e0369f1d64a1e150 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0001/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b9f6a08f5fa5939aa54033eafdaf91e8120169bc --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0001/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1429.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1429.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1701.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1157.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1284.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1284.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1427.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 434.47, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0001/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0001/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0010/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0010/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0010/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..016a7829144d8ef26f27e1a12cabb67632f45eac --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0010/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2624,kg,55,15,0,approved +B01,2416,kg,55,8,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0010/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0010/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0010/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0010/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0010/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0010/task.toml b/tasks/food-batch/food-batch-drying-d1-t0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8212eba0fd466edf510905bc02e43a22e29b6901 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0010/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cd6ee0524d9313f6f92d7a981c8c12b3a25ffe29 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0010/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1180.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1180.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1389.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1234.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1087.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1087.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1181.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 1234.26, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0010/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0010/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0019/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0019/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0019/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..f52661059138364e316c635dbe0018764ac79ebb --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0019/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2959,kg,57,18,0,approved +B01,888,kg,49,10,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0019/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0019/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0019/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0019/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0019/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0019/task.toml b/tasks/food-batch/food-batch-drying-d1-t0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5cae67d331b6b6e187b9e8d11c88d356a1329b6f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0019/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c983bd5084c2a17d0ff67a82abd72b34b639697f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0019/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1272.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1272.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1551.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1407.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 452.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 452.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 503.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 384.8, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0019/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0019/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0028/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0028/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0028/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0028/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0028/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..59c46669e17c602a65e78637aa8bfcdf1a0a802b --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0028/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2759,kg,59,16,0,approved +B01,2404,kg,32,17,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0028/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0028/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0028/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0028/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0028/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0028/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0028/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0028/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0028/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0028/task.toml b/tasks/food-batch/food-batch-drying-d1-t0028/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..643932db30d653a16fea6c9f41dc4127959c7710 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0028/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0028/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0028/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9b95d44f4ce7815a50c39d01ebca2d8f8da2cd3e --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0028/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1131.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1131.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1346.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1412.35, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1634.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1634.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1969.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 434.46, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0028/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0028/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0028/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0028/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0037/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0037/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0037/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0037/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0037/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..fa44599a964e8a3b7b5bf8db8e82882298e73be1 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0037/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,1938,kg,33,10,0,approved +B01,892,kg,32,16,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0037/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0037/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0037/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0037/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0037/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0037/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0037/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0037/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0037/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0037/task.toml b/tasks/food-batch/food-batch-drying-d1-t0037/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..889fe87fa4e88b155b54710cb7a5ea964e5e120c --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0037/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0037/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0037/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e389f2217c5bd13b68c5840581e85a882e9cacf9 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0037/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1298.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1298.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1442.73, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 495.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 606.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 606.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 722.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 169.9, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0037/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0037/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0037/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0037/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0046/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0046/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0046/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0046/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0046/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..29cddc7b90a6d3fc02890759f88494436438f316 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0046/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,671,kg,43,8,0,approved +B01,811,kg,49,16,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0046/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0046/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0046/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0046/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0046/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0046/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0046/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0046/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0046/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0046/task.toml b/tasks/food-batch/food-batch-drying-d1-t0046/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4a2efc905664fd02dcae690e7a95cd3b9b8161b5 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0046/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0046/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0046/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..782c38db8ebbfce867866affa5fd254cf038ebc8 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0046/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 382.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 382.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 415.73, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 255.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 413.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 413.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 492.39, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 318.61, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0046/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0046/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0046/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0046/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0055/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0055/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0055/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0055/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0055/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..9dfe270810265b321a0283e0cd20d697b4f093ae --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0055/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2326,kg,56,16,0,approved +B01,1038,kg,30,13,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0055/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0055/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0055/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0055/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0055/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0055/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0055/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0055/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0055/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0055/task.toml b/tasks/food-batch/food-batch-drying-d1-t0055/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..60c7c15f60301fd4627ae059b308faff160e0894 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0055/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0055/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0055/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7cf1953a2aba83094d45af505637b08d837e6f18 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0055/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1023.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1023.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1218.38, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1107.62, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 726.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 726.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 835.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 202.83, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0055/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0055/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0055/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0055/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0064/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0064/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0064/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0064/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0064/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..32ffef55c676dd94f0021f9bdb7a3e2737f9aea4 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0064/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,1056,kg,58,14,0,approved +B01,800,kg,51,16,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0064/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0064/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0064/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0064/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0064/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0064/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0064/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0064/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0064/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0064/task.toml b/tasks/food-batch/food-batch-drying-d1-t0064/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9479b1ba26989c4932ab709b5a57d957a24790e9 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0064/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0064/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0064/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..deced5a8cc20d7173aa1ad1648ecb2c111134e54 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0064/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 443.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 443.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 515.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 540.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 392.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 392.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 466.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 333.33, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0064/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0064/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0064/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0064/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0073/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0073/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0073/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0073/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0073/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..91ee9d96388ed8bbdec83414341dc06bd408ef4d --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0073/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2139,kg,39,15,0,approved +B01,2162,kg,48,15,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0073/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0073/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0073/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0073/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0073/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0073/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0073/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0073/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0073/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0073/task.toml b/tasks/food-batch/food-batch-drying-d1-t0073/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d488f10ebd2266fb961a89cba62915b81bbf285b --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0073/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0073/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0073/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0f62b43f4647bc1facb0f94762f94a7ac852a023 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0073/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1304.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1304.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1535.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 603.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1124.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1124.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1322.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 839.36, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0073/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0073/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0073/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0073/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0082/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d1-t0082/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0082/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d1-t0082/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d1-t0082/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..0a59ab0e74996965300ef65e687f3390454ef926 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0082/environment/workdir/drying.csv @@ -0,0 +1,3 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2424,kg,54,10,0,approved +B01,1229,kg,31,17,0,approved diff --git a/tasks/food-batch/food-batch-drying-d1-t0082/instruction.md b/tasks/food-batch/food-batch-drying-d1-t0082/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0082/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d1-t0082/solution/oracle.py b/tasks/food-batch/food-batch-drying-d1-t0082/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0082/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d1-t0082/solution/solve.sh b/tasks/food-batch/food-batch-drying-d1-t0082/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0082/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d1-t0082/task.toml b/tasks/food-batch/food-batch-drying-d1-t0082/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1396a88b01a80e0fa0350519253b91e90d08e3aa --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0082/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d1-t0082/tests/checks.json b/tasks/food-batch/food-batch-drying-d1-t0082/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8a1df5dfd334215b1fe87f6247591f6456ab49ad --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d1-t0082/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1115.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1115.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1238.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1185.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 848.01, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 848.01, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1021.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 207.3, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d1-t0082/tests/test.sh b/tasks/food-batch/food-batch-drying-d1-t0082/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d1-t0082/tests/verify.py b/tasks/food-batch/food-batch-drying-d1-t0082/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-e0004/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-e0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-e0004/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-e0004/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..9d435b22bb17875bb3912e343f56e93a968e1552 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0004/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2140,kg,57,18,0,approved +CANCELLED,99999,kg,57,18,0,cancelled +B01,760,kg,44,13,0,approved +B02,2210,kg,41,10,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-e0004/instruction.md b/tasks/food-batch/food-batch-drying-d2-e0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0004/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-e0004/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-e0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0004/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-e0004/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-e0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-e0004/task.toml b/tasks/food-batch/food-batch-drying-d2-e0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..61a890222a071cc27921d8d9e721a015fa28ffd2 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-e0004/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-e0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8081e8c5efbb84e067f2afd12b9dd43530721f78 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0004/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 920.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 920.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1122.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1017.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 425.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 425.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 489.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 270.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1303.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1303.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1448.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 761.22, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-e0004/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-e0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-e0004/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-e0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-e0013/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-e0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-e0013/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-e0013/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..cf2086cc483c30c3c5edd6f39abeafc82ba037d1 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0013/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +CANCELLED,99999,kg,37,15,0,cancelled +B01,2655,kg,51,8,0,approved +B02,2020,kg,47,8,0,approved +B00,2014,kg,37,15,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-e0013/instruction.md b/tasks/food-batch/food-batch-drying-d2-e0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0013/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-e0013/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-e0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0013/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-e0013/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-e0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-e0013/task.toml b/tasks/food-batch/food-batch-drying-d2-e0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..498a31b091e0f8eed71894c0792913f5759c6d77 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-e0013/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-e0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b1fa679404595eb13987c33ce687130778bc3ece --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0013/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1268.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1268.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1492.73, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 521.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1300.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1300.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1414.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 1240.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1070.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1070.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1163.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 856.3, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-e0013/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-e0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-e0013/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-e0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-e0022/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-e0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-e0022/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-e0022/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..07fe88cb55b96d4832d7dc256dd7d2b18f6013b2 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0022/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B01,1855,kg,30,11,0,approved +CANCELLED,99999,kg,48,13,0,cancelled +B02,1289,kg,50,17,0,approved +B00,2126,kg,48,13,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-e0022/instruction.md b/tasks/food-batch/food-batch-drying-d2-e0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0022/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-e0022/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-e0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0022/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-e0022/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-e0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-e0022/task.toml b/tasks/food-batch/food-batch-drying-d2-e0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..65d07d503c06c1c6042ed0d34eaabf4e9962315e --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-e0022/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-e0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..50033ced285eae443d2bc62e3281fef16663aee8 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-e0022/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1105.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1105.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1270.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 855.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1298.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1298.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1458.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 396.01, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 644.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 644.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 776.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 512.49, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-e0022/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-e0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-e0022/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-e0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0004/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0004/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0004/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..1496c10b0cff2adfdaabeae56f5b0d5fdb58e801 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0004/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,1708,kg,52,10,0,approved +CANCELLED,99999,kg,52,10,0,cancelled +B01,1467,kg,41,11,0,approved +B02,2264,kg,30,17,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-t0004/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0004/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0004/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0004/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0004/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0004/task.toml b/tasks/food-batch/food-batch-drying-d2-t0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..98b2bcc232e096e7a6496243f128a527bd377d2e --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0004/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e09c0c95ce2ed14ecb818c07d56af925ce06a948 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0004/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 819.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 819.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 910.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 797.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 865.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 865.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 972.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 494.49, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1584.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1584.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1909.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 354.6, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0004/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0004/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0013/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0013/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0013/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..b399c12262fd03b22c0457cccb563c54621267fe --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0013/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B02,1576,kg,39,14,0,approved +B00,1990,kg,58,13,0,approved +B01,2286,kg,56,12,0,approved +CANCELLED,99999,kg,58,13,0,cancelled diff --git a/tasks/food-batch/food-batch-drying-d2-t0013/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0013/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0013/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0013/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0013/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0013/task.toml b/tasks/food-batch/food-batch-drying-d2-t0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9d2c578e1c9a1d62660787a582743f773f943a98 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0013/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..90aad0f6bd75973010ce33cfcc5393fac92840a9 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0013/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 835.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 835.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 960.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1029.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1005.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1005.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1143.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 1143.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 961.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 961.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1117.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 458.14, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0013/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0013/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0022/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0022/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0022/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..cff1188b854606ca2a87f8a03c4334fa41d18ddc --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0022/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B02,2230,kg,45,18,0,approved +B01,1550,kg,47,11,0,approved +B00,528,kg,43,15,0,approved +CANCELLED,99999,kg,43,15,0,cancelled diff --git a/tasks/food-batch/food-batch-drying-d2-t0022/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0022/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0022/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0022/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0022/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0022/task.toml b/tasks/food-batch/food-batch-drying-d2-t0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5d600e8c614f981876c9eb7bcd435739f3fc8199 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0022/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ec52d7f119c9e3a6e5c9b2e857dcf5292281a680 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0022/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 300.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 300.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 354.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 173.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 821.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 821.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 923.03, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 626.97, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1226.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1226.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1495.73, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 734.27, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0022/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0022/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0031/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0031/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0031/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0031/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0031/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..32b6d39debf4805684af8106de2ca03050da9b83 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0031/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,570,kg,56,13,0,approved +CANCELLED,99999,kg,56,13,0,cancelled +B01,582,kg,48,14,0,approved +B02,1117,kg,39,13,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-t0031/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0031/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0031/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0031/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0031/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0031/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0031/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0031/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0031/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0031/task.toml b/tasks/food-batch/food-batch-drying-d2-t0031/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7bf05f8dca1bac6a3948129b25f9f8df66c41464 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0031/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0031/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0031/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f50b7e391d3503025ca930c3864121208d74b050 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0031/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 250.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 250.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 288.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 281.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 302.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 302.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 351.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 230.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 681.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 681.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 783.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 333.82, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0031/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0031/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0031/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0031/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0040/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0040/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0040/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0040/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0040/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..efceeeeba62af69cdcc747c7d732209b3bbd97e7 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0040/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,1545,kg,46,14,0,approved +B02,683,kg,47,14,0,approved +CANCELLED,99999,kg,46,14,0,cancelled +B01,2639,kg,50,16,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-t0040/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0040/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0040/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0040/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0040/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0040/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0040/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0040/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0040/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0040/task.toml b/tasks/food-batch/food-batch-drying-d2-t0040/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3052e8b68604ebeff978d48a44f61510a678bcc1 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0040/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0040/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0040/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8855dfd5d7edac4a9bb87ae364253f0699c2f432 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0040/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 834.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 834.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 970.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 574.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1319.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1319.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1570.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 1068.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 361.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 361.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 420.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 262.08, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0040/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0040/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0040/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0040/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0049/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0049/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0049/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0049/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0049/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..622a6e1e1bfaee77468c31b0e397aea962e0c873 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0049/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B02,1321,kg,49,14,0,approved +B00,2540,kg,48,17,0,approved +CANCELLED,99999,kg,48,17,0,cancelled +B01,1624,kg,32,17,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-t0049/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0049/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0049/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0049/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0049/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0049/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0049/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0049/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0049/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0049/task.toml b/tasks/food-batch/food-batch-drying-d2-t0049/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ca069d27bba30a3dbfda99996a516240205eca8a --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0049/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0049/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0049/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4ae838ed0c1de2e53954ebc10e6b4799a0e3d0dd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0049/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1320.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1320.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1591.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 948.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1104.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1104.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1330.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 293.49, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 673.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 673.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 783.38, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 537.62, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0049/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0049/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0049/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0049/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0058/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0058/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0058/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0058/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0058/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..9226c1118527eb0ef7bdfcc332de3c8ae2594177 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0058/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,947,kg,36,10,0,approved +B01,2256,kg,30,17,0,approved +B02,2128,kg,47,15,0,approved +CANCELLED,99999,kg,36,10,0,cancelled diff --git a/tasks/food-batch/food-batch-drying-d2-t0058/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0058/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0058/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0058/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0058/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0058/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0058/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0058/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0058/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0058/task.toml b/tasks/food-batch/food-batch-drying-d2-t0058/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6a5be499bac4ffa2c01eba7e6f0c04aad21b85b8 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0058/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0058/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0058/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9794e5080c1f07abcbdfd929fbb3975bda148fcb --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0058/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 606.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 606.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 673.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 273.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1579.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1579.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1902.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 353.35, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1127.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1127.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1326.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 801.13, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0058/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0058/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0058/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0058/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0067/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0067/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0067/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0067/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0067/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..a189b29b49bb3740b924f9c1daa12a10819d15d4 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0067/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2465,kg,59,15,0,approved +B01,1848,kg,58,16,0,approved +B02,2530,kg,55,16,0,approved +CANCELLED,99999,kg,59,15,0,cancelled diff --git a/tasks/food-batch/food-batch-drying-d2-t0067/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0067/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0067/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0067/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0067/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0067/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0067/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0067/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0067/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0067/task.toml b/tasks/food-batch/food-batch-drying-d2-t0067/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a76ad63ade2c8e680f461af39510542cac0b2162 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0067/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0067/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0067/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2b0d2a261496de8022724c052859e9c468dd643f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0067/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1010.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1010.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1189.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1276.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 776.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 776.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 924.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 924.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1138.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1138.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1355.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 1174.64, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0067/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0067/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0067/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0067/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0076/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d2-t0076/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0076/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d2-t0076/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d2-t0076/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..029265e016b69a5d2641e127c0536b090ce63064 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0076/environment/workdir/drying.csv @@ -0,0 +1,5 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +CANCELLED,99999,kg,41,18,0,cancelled +B00,1032,kg,41,18,0,approved +B02,1631,kg,59,14,0,approved +B01,1060,kg,33,11,0,approved diff --git a/tasks/food-batch/food-batch-drying-d2-t0076/instruction.md b/tasks/food-batch/food-batch-drying-d2-t0076/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..35a43879d3bc2c059dac98750d26a7aae70535a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0076/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d2-t0076/solution/oracle.py b/tasks/food-batch/food-batch-drying-d2-t0076/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0076/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d2-t0076/solution/solve.sh b/tasks/food-batch/food-batch-drying-d2-t0076/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0076/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d2-t0076/task.toml b/tasks/food-batch/food-batch-drying-d2-t0076/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e7a0b77e6d567a63960eb274e3db8888f3cd2d11 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0076/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d2-t0076/tests/checks.json b/tasks/food-batch/food-batch-drying-d2-t0076/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3411dd0f793b2db05fa117aa5dd93e86489f203f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d2-t0076/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 608.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 608.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 742.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 289.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 710.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 710.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 797.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 262.02, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 668.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 668.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 777.57, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 853.43, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d2-t0076/tests/test.sh b/tasks/food-batch/food-batch-drying-d2-t0076/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d2-t0076/tests/verify.py b/tasks/food-batch/food-batch-drying-d2-t0076/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-e0007/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-e0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-e0007/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-e0007/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..73e2c85c8020d383e4795b4afd1c6d8c1dbe4183 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0007/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +CANCELLED,99999,kg,38,13,3,cancelled +B03,1.219,tonne,48,18,3,approved +B00,2076,kg,38,13,3,approved +B01,2.608,tonne,56,13,5,approved +B02,1275,kg,44,15,2,approved diff --git a/tasks/food-batch/food-batch-drying-d3-e0007/instruction.md b/tasks/food-batch/food-batch-drying-d3-e0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0007/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-e0007/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-e0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0007/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-e0007/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-e0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-e0007/task.toml b/tasks/food-batch/food-batch-drying-d3-e0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5f1dc976075ce29c41fe10d3eb56d1b9151111b9 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-e0007/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-e0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d1e8282e63751acbcc5aa4e9d2d7e36055164e7c --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0007/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1287.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1248.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1435.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 602.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1147.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1090.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1253.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 1297.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 714.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 699.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 823.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 437.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 633.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 614.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 749.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 450.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4261.14, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-e0007/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-e0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-e0007/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-e0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-e0016/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-e0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-e0016/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-e0016/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..a6401adae1a01ddcfd3390e63892e9ca492080fa --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0016/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B03,1.795,tonne,32,15,2,approved +B02,888,kg,30,18,2,approved +CANCELLED,99999,kg,50,17,2,cancelled +B01,0.789,tonne,30,17,1,approved +B00,1271,kg,50,17,2,approved diff --git a/tasks/food-batch/food-batch-drying-d3-e0016/instruction.md b/tasks/food-batch/food-batch-drying-d3-e0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0016/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-e0016/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-e0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0016/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-e0016/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-e0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-e0016/task.toml b/tasks/food-batch/food-batch-drying-d3-e0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c49940fcf528c56b6333cd4ae5995237fd4b4b64 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "eval"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-e0016/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-e0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..818899e35c3820b9040af89e9f4c1e7c018894a6 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-e0016/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 635.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 622.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 750.35, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 507.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 552.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 546.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 658.77, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 124.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 621.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 609.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 742.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 132.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 1220.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 1196.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 1407.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 363.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3559.28, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-e0016/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-e0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-e0016/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-e0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0007/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0007/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0007/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..540338f643d4d9f1dae4a939ecf7dd76c2e8baa1 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0007/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +CANCELLED,99999,kg,32,12,2,cancelled +B03,2.661,tonne,36,9,5,approved +B00,2382,kg,32,12,2,approved +B02,2385,kg,41,15,3,approved +B01,2.321,tonne,54,14,3,approved diff --git a/tasks/food-batch/food-batch-drying-d3-t0007/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0007/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0007/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0007/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0007/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0007/task.toml b/tasks/food-batch/food-batch-drying-d3-t0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..eddc72b131239fc1e76b9a2d182e1e64ddb91db9 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0007/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8a9b95b025c2d5fe3e0c1102dc9077bd0bcc44e4 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0007/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1619.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1587.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1803.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 545.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1067.66, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1035.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1204.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 1084.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1407.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1364.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1605.81, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 736.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 1703.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 1617.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 1777.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 797.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 6391.75, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0007/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0007/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0016/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0016/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0016/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..8700d9c7be83f05483cd51d0a4451e03cdadadf9 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0016/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B03,1.09,tonne,31,9,3,approved +B02,620,kg,52,8,2,approved +B00,2788,kg,42,8,3,approved +B01,1.081,tonne,59,14,5,approved +CANCELLED,99999,kg,42,8,3,cancelled diff --git a/tasks/food-batch/food-batch-drying-d3-t0016/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0016/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0016/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0016/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0016/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0016/task.toml b/tasks/food-batch/food-batch-drying-d3-t0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1b7bcfe50be43c63a29d3c373ebe7bbdac45d9db --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0016/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..72c10feeb6d166da8d609b28af9b9c691849fd44 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0016/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1617.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1568.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1704.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 1034.57, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 443.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 421.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 489.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 569.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 297.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 291.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 317.01, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 297.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 752.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 729.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 801.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 265.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3313.21, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0016/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0016/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0025/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0025/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0025/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0025/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0025/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..a7a546f7db1087e157aaac6fcb3e05b6c5fba8bc --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0025/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B01,2.189,tonne,40,17,1,approved +B00,881,kg,47,12,1,approved +CANCELLED,99999,kg,47,12,1,cancelled +B03,1.304,tonne,55,13,3,approved +B02,1784,kg,38,16,5,approved diff --git a/tasks/food-batch/food-batch-drying-d3-t0025/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0025/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0025/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0025/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0025/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0025/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0025/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0025/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0025/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0025/task.toml b/tasks/food-batch/food-batch-drying-d3-t0025/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4636af0f575ad891a52a553839ed80e5ed78b65d --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0025/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0025/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0025/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..99d7727deec48efa2c8a3561f56d9d1bce9b9135 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0025/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 466.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 462.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 525.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 351.03, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1313.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1300.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1566.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 609.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1106.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1050.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1250.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 477.77, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 586.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 569.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 654.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 632.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 3997.05, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0025/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0025/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0025/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0025/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0034/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0034/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0034/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0034/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0034/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..ce689fba96a2a2345eba350e4be397cd5f4eed16 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0034/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,1307,kg,50,18,5,approved +B02,2156,kg,38,9,1,approved +B01,2.538,tonne,42,17,5,approved +B03,2.896,tonne,42,14,2,approved +CANCELLED,99999,kg,50,18,5,cancelled diff --git a/tasks/food-batch/food-batch-drying-d3-t0034/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0034/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0034/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0034/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0034/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0034/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0034/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0034/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0034/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0034/task.toml b/tasks/food-batch/food-batch-drying-d3-t0034/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..674d91abb846ed6a0ebbde9d74ec8724c2cc2809 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0034/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0034/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0034/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1af01f66751c8783466d98aa47ccb7fe513eb7e9 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0034/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 653.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 620.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 757.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 517.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1472.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1398.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1684.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 779.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1336.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1323.35, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1454.23, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 688.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 1679.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 1646.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 1914.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 948.35, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5810.26, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0034/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0034/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0034/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0034/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0043/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0043/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0043/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0043/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0043/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..283024e17c7b60d0f10ccfc94742e6249613242f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0043/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +CANCELLED,99999,kg,33,15,5,cancelled +B00,2877,kg,33,15,5,approved +B01,1.348,tonne,43,17,3,approved +B03,1.811,tonne,46,10,3,approved +B02,2039,kg,41,18,2,approved diff --git a/tasks/food-batch/food-batch-drying-d3-t0043/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0043/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0043/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0043/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0043/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0043/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0043/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0043/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0043/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0043/task.toml b/tasks/food-batch/food-batch-drying-d3-t0043/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..941471be8393ad43ee3fc09128ad76d6e17aaa6b --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0043/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0043/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0043/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6691fd1ca3d97252f84561e64e14c0275774cfbb --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0043/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1927.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1831.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 2154.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 626.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 768.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 745.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 897.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 426.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1203.01, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1178.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1437.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 577.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 977.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 948.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 1054.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 727.66, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5544.07, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0043/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0043/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0043/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0043/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0052/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0052/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0052/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0052/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0052/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..be603902736083c68e5ca04c2a229ce765d79afe --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0052/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B03,0.759,tonne,34,11,3,approved +CANCELLED,99999,kg,54,17,2,cancelled +B02,1898,kg,44,15,3,approved +B00,1910,kg,54,17,2,approved +B01,1.884,tonne,39,16,2,approved diff --git a/tasks/food-batch/food-batch-drying-d3-t0052/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0052/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0052/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0052/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0052/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0052/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0052/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0052/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0052/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0052/task.toml b/tasks/food-batch/food-batch-drying-d3-t0052/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9ee034f4ad447a8da8c7f4b77203a6962d7bcaab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0052/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0052/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0052/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b87e7aff5be18b0f6138681e978d8c1e9a718d6d --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0052/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 878.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 861.03, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1037.38, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 855.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1149.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1126.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 1340.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 520.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1062.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1030.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1212.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 653.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 500.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 485.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 545.97, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 198.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4137.07, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0052/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0052/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0052/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0052/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0061/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0061/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0061/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0061/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0061/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..455893e86ec57deb0395efb97d87ab0ed2301d4e --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0061/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +CANCELLED,99999,kg,33,11,3,cancelled +B00,2512,kg,33,11,3,approved +B01,2.663,tonne,35,16,2,approved +B02,737,kg,34,17,2,approved +B03,2.898,tonne,53,12,2,approved diff --git a/tasks/food-batch/food-batch-drying-d3-t0061/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0061/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0061/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0061/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0061/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0061/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0061/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0061/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0061/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0061/task.toml b/tasks/food-batch/food-batch-drying-d3-t0061/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dcce04742638ca8c10958981987de319fd87c604 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0061/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0061/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0061/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..60f1605e5458daf013116e133e53128920cd07c4 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0061/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1683.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1632.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1834.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 627.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 1730.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 1696.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 2019.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 608.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 486.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 476.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 574.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 152.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 1362.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 1334.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 1516.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 1353.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5944.93, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0061/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0061/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0061/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0061/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0070/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0070/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0070/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0070/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0070/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..b8f062dd0b265b8ba26cdeb771ac6a051992f9d0 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0070/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B00,2645,kg,32,9,1,approved +CANCELLED,99999,kg,32,9,1,cancelled +B02,2929,kg,58,13,1,approved +B01,1.138,tonne,38,15,5,approved +B03,1.279,tonne,41,8,3,approved diff --git a/tasks/food-batch/food-batch-drying-d3-t0070/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0070/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0070/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0070/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0070/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0070/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0070/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0070/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0070/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0070/task.toml b/tasks/food-batch/food-batch-drying-d3-t0070/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a6af5bb6a41ffba9bbb88f1d7ed37951c9297d31 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0070/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0070/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0070/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a044f7b7f42e0682277c669b220a3c8629ea35f4 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0070/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1798.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1780.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1956.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 670.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 705.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 670.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 788.57, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 314.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1230.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1217.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1399.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 1516.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 754.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 731.97, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 795.62, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 460.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 4940.77, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0070/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0070/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0070/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0070/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0079/environment/Dockerfile b/tasks/food-batch/food-batch-drying-d3-t0079/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0079/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-drying-d3-t0079/environment/workdir/drying.csv b/tasks/food-batch/food-batch-drying-d3-t0079/environment/workdir/drying.csv new file mode 100644 index 0000000000000000000000000000000000000000..09760b7caa49a3c22619e4dc3b3b5e8c57d0564e --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0079/environment/workdir/drying.csv @@ -0,0 +1,6 @@ +batch_id,input_mass,mass_unit,initial_moisture_percent,target_moisture_percent,dry_solids_loss_percent,status +B01,1.794,tonne,56,13,5,approved +B03,2.325,tonne,36,13,1,approved +B00,2494,kg,43,16,3,approved +CANCELLED,99999,kg,43,16,3,cancelled +B02,2999,kg,59,10,1,approved diff --git a/tasks/food-batch/food-batch-drying-d3-t0079/instruction.md b/tasks/food-batch/food-batch-drying-d3-t0079/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb926ef704dd19f44a77ba157a3e0f34d583f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0079/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: drying + +`drying.csv` lists drying batches. Moisture percentages are wet-basis (water mass / total mass). For each batch id return `initial_dry_kg` = input mass*(1-initial moisture/100), `retained_dry_kg` = initial dry mass*(1-dry solids loss/100), `product_kg` = retained dry mass/(1-target moisture/100), and `water_removed_kg` = initial water mass minus product water mass. Dry-solids loss removes dry matter only; it does not carry water. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `product_kg` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-drying-d3-t0079/solution/oracle.py b/tasks/food-batch/food-batch-drying-d3-t0079/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0079/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-drying-d3-t0079/solution/solve.sh b/tasks/food-batch/food-batch-drying-d3-t0079/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0079/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-drying-d3-t0079/task.toml b/tasks/food-batch/food-batch-drying-d3-t0079/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..118c0d199e110e9325f7a2210893c973f6f1730e --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0079/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "drying", "isced-0721", "train"] +isced_f = "0721" +family = "drying" +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/food-batch/food-batch-drying-d3-t0079/tests/checks.json b/tasks/food-batch/food-batch-drying-d3-t0079/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d4b258053a8aa7300c8761c6820bacf9337d449a --- /dev/null +++ b/tasks/food-batch/food-batch-drying-d3-t0079/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.B00.initial_dry_kg", + "type": "number", + "value": 1421.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.retained_dry_kg", + "type": "number", + "value": 1378.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.product_kg", + "type": "number", + "value": 1641.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B00.water_removed_kg", + "type": "number", + "value": 809.77, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.initial_dry_kg", + "type": "number", + "value": 789.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.retained_dry_kg", + "type": "number", + "value": 749.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.product_kg", + "type": "number", + "value": 861.94, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B01.water_removed_kg", + "type": "number", + "value": 892.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.initial_dry_kg", + "type": "number", + "value": 1229.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.retained_dry_kg", + "type": "number", + "value": 1217.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.product_kg", + "type": "number", + "value": 1352.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B02.water_removed_kg", + "type": "number", + "value": 1634.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.initial_dry_kg", + "type": "number", + "value": 1488.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.retained_dry_kg", + "type": "number", + "value": 1473.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.product_kg", + "type": "number", + "value": 1693.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.B03.water_removed_kg", + "type": "number", + "value": 616.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 5549.32, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-drying-d3-t0079/tests/test.sh b/tasks/food-batch/food-batch-drying-d3-t0079/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-drying-d3-t0079/tests/verify.py b/tasks/food-batch/food-batch-drying-d3-t0079/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-drying-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/food-batch/food-batch-recipe-scaling-d1-e0002/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..7a61093369e44d6335cee0735113ea9219316295 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,8,11.0,kg,874,0,approved +R00,I1,7,11.5,kg,874,0,approved +R00,I2,5,10.0,kg,874,0,approved +R01,I0,8,4.0,kg,353,0,approved +R01,I1,8,14.1,kg,353,0,approved +R01,I2,8,3.6,kg,353,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3d41ffd8f8126d1ffc5ea6c809b36d9ce41aa16a --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-e0002/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..fa50a09e078edcfd16d6a72b06d8aa9755811c7c --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 874.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 9548.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 349.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 305.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 218.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 353.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 2553.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 117.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 117.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 117.67, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-e0002/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-e0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-e0011/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2a1d2ce9a240ace85f3c36fabbe4e5fdf3dc8d33 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,9,4.1,kg,880,0,approved +R00,I1,5,8.9,kg,880,0,approved +R00,I2,4,14.1,kg,880,0,approved +R01,I0,7,10.9,kg,302,0,approved +R01,I1,7,14.7,kg,302,0,approved +R01,I2,7,6.4,kg,302,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9cbce8213a83c6e28e759e52a58ee08fca7036ce --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-e0011/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2e865e25af44bcfc385ea3cc78743522ea947647 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 880.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 6736.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 440.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 244.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 195.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 302.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 3221.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 100.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 100.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 100.67, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-e0011/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-e0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-e0020/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2ce038702c787750939579bde05ced6a7d6d84ce --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,6,4.7,kg,418,0,approved +R00,I1,9,11.5,kg,418,0,approved +R00,I2,9,5.8,kg,418,0,approved +R01,I0,7,14.2,kg,821,0,approved +R01,I1,6,9.6,kg,821,0,approved +R01,I2,4,15.0,kg,821,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3cc71d0292380dbf7457b985aac45690bb66eb31 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-e0020/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a9c5ae10ab9eacbf9615b35a8273bb1134b0c0ec --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 418.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 3202.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 104.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 156.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 156.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 821.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 10479.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 338.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 289.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 193.18, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-e0020/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-e0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0002/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a151e2f373a2aa3048566067c7408a2f7134c95b --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,3,5.7,kg,374,0,approved +R00,I1,5,13.9,kg,374,0,approved +R00,I2,7,2.1,kg,374,0,approved +R01,I0,7,3.7,kg,644,0,approved +R01,I1,5,6.5,kg,644,0,approved +R01,I2,8,10.7,kg,644,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0a5c0f7010258bd22b18ee6c280317aca3f88ada --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0002/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2b4ea2e3ec1da2a57c64148792c9b777f37f3c73 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 374.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 2525.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 74.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 124.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 174.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 644.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 4636.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 225.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 161.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 257.6, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0002/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0011/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..5e4cf351f4a282193705ef2238fe1b6b8c5142a9 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,9,2.7,kg,225,0,approved +R00,I1,4,11.9,kg,225,0,approved +R00,I2,9,14.7,kg,225,0,approved +R01,I0,6,11.4,kg,682,0,approved +R01,I1,7,14.1,kg,682,0,approved +R01,I2,8,14.4,kg,682,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c1f97db1953d17df2916a0af7e66eb944eff0cfe --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0011/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..874c7b46c3eb421b40d853ca3c9e94e5ba8be26c --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 225.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 2088.41, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 92.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 40.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 92.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 682.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 9168.03, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 194.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 227.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 259.81, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0011/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0020/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..d735527185e0baeefe357288a0057b7fd4ab6fea --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,9,9.9,kg,827,0,approved +R00,I1,4,5.6,kg,827,0,approved +R00,I2,5,4.5,kg,827,0,approved +R01,I0,2,6.2,kg,337,0,approved +R01,I1,5,12.2,kg,337,0,approved +R01,I2,3,10.6,kg,337,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e4130660642f2283f92a24e2593c8ce00da82c45 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0020/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8e4a637c20fe1be2f2accfcfd8dbc2dc713256db --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 827.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 6156.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 413.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 183.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 229.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 337.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 3545.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 67.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 168.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 101.1, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0020/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0029/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..f8dd0d820c3c29e9964c4c635e16fa094154f47a --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,6,14.4,kg,405,0,approved +R00,I1,3,10.4,kg,405,0,approved +R00,I2,2,14.1,kg,405,0,approved +R01,I0,7,12.4,kg,786,0,approved +R01,I1,6,7.6,kg,786,0,approved +R01,I2,5,8.0,kg,786,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2b8d43a8ab8905a7a61f76fe2279242362716335 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0029/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..833aa2f108a4fd73ffc20cd759058b51fd93ae49 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 405.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5368.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 220.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 110.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 73.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 786.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 7528.13, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 305.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 262.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 218.33, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0029/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0029/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0038/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..5b0dde4273be94231335df18928f9c6944b525f9 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,7,4.9,kg,488,0,approved +R00,I1,7,4.3,kg,488,0,approved +R00,I2,7,8.4,kg,488,0,approved +R01,I0,5,12.3,kg,369,0,approved +R01,I1,5,11.9,kg,369,0,approved +R01,I2,5,8.7,kg,369,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..995aefc5f380449d29466709c05ea032cadaec87 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0038/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f4e96f8edead48d826ce9fdd1b544f58d912667f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 488.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 2862.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 162.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 162.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 162.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 369.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 4046.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 123.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 123.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 123.0, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0038/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0038/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0047/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..e0eefe58b11b629e7daa29017e45788861524776 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,9,6.3,kg,236,0,approved +R00,I1,5,13.7,kg,236,0,approved +R00,I2,4,5.1,kg,236,0,approved +R01,I0,3,10.4,kg,290,0,approved +R01,I1,5,12.2,kg,290,0,approved +R01,I2,5,10.8,kg,290,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..095e6c36a68c25e1f04d7d43141e35a8700b38d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0047/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..dc9544afc00fda7299a5fcb136e1501768c47ef7 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 236.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 1908.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 118.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 65.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 52.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 290.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 3261.38, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 66.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 111.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 111.54, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0047/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0047/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0056/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..c7a8c31cf05842077ce285a5ce45c66fd9860622 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,8,11.7,kg,678,0,approved +R00,I1,8,8.2,kg,678,0,approved +R00,I2,6,8.9,kg,678,0,approved +R01,I0,8,4.1,kg,708,0,approved +R01,I1,4,6.2,kg,708,0,approved +R01,I2,2,14.3,kg,708,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b4aeae42bd6bf0725ad3dbad3975f7e644c4990e --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0056/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..95113a7ac543ce4c90602dc451b57b1d25d7b444 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 678.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 6551.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 246.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 246.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 184.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 708.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 4359.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 404.57, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 202.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 101.14, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0056/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0056/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0065/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..9a8a28e069d6eb8e7ed3d8d14758e757ba4cbb61 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,5,10.5,kg,501,0,approved +R00,I1,3,10.0,kg,501,0,approved +R00,I2,2,13.0,kg,501,0,approved +R01,I0,4,5.8,kg,559,0,approved +R01,I1,5,9.7,kg,559,0,approved +R01,I2,5,8.7,kg,559,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fed6c425d175b507cca23995a7da444334f1ba78 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0065/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..18d34c07baa7fc59912d0078f99a5af77be2b34f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 501.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5435.85, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 250.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 150.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 100.2, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 559.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 4599.77, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 159.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 199.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 199.64, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0065/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0065/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0074/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..1219223795ee4688709bbe1821b53bec7ba013a9 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,3,13.7,kg,329,0,approved +R00,I1,4,10.8,kg,329,0,approved +R00,I2,8,12.4,kg,329,0,approved +R01,I0,7,2.0,kg,498,0,approved +R01,I1,3,13.7,kg,498,0,approved +R01,I2,8,4.7,kg,498,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..363ea9c2e248679a5c900211dea04e522f147c86 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0074/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..fc5337f09d56221d4dc5f41dd43e320af2af554a --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 329.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 4024.77, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 65.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 87.73, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 175.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 498.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 2564.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 193.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 83.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 221.33, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0074/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0074/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0083/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..ddc6b25985af8aebeaa052a92d1041d6a43ff316 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/environment/workdir/recipes.csv @@ -0,0 +1,7 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I0,9,7.2,kg,634,0,approved +R00,I1,9,14.0,kg,634,0,approved +R00,I2,6,5.2,kg,634,0,approved +R01,I0,3,8.6,kg,298,0,approved +R01,I1,4,6.4,kg,298,0,approved +R01,I2,7,6.5,kg,298,0,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..abdd94965ecd40a22c75a8ae440b1371f0e83b8e --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d1-t0083/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9086ca477e4ba75ed8a45c9e7d595206535c107d --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 634.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5864.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 237.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 237.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 158.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 298.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 2062.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 63.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 85.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 149.0, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d1-t0083/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d1-t0083/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-e0005/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a7a95ef7d99bc9211d61bcac06bb43c737bd191b --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I1,8,6.3,kg,217,10,approved +R00,I2,7,10.7,kg,263,5,approved +R01,I1,8,10.2,kg,828,8,approved +R01,I2,4,14.8,kg,828,8,approved +R02,I0,7,4.8,kg,217,10,approved +R01,I0,6,7.4,kg,828,8,approved +R00,VOID,999,12.8,kg,263,5,cancelled +R02,I2,2,13.4,kg,217,10,approved +R00,I1,6,9.2,kg,263,5,approved +R00,I0,4,12.8,kg,263,5,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1ee3cf85e3a8289442ddec1dd1eea32260ddd711 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-e0005/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cf49503fc4a3c8f9744549430df6c7a7cc2c470c --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 276.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 2952.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 65.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 97.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 113.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 900.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 9260.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 300.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 400.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 200.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 241.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 1571.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 99.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 113.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 28.37, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-e0005/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-e0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-e0014/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..c7cea85a4b4553833f7dcdcd340844f80daa01b4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I1,4,12.3,kg,596,5,approved +R01,I0,9,7.0,kg,620,2,approved +R00,I0,2,10.5,kg,318,8,approved +R02,I2,4,9.5,kg,596,5,approved +R02,I0,9,9.4,kg,596,5,approved +R01,I1,5,3.8,kg,620,2,approved +R00,I2,2,4.5,kg,318,8,approved +R00,VOID,999,10.5,kg,318,8,cancelled +R01,I2,7,14.1,kg,620,2,approved +R00,I1,9,7.4,kg,318,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3c88e692a0eb6657831b292b7f4bf4793e449d1d --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-e0014/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..64f15490c804c89bd23dc5d5af16efb6eb9c51d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 345.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 2568.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 53.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 239.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 53.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 632.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 5443.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 271.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 150.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 210.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 627.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 6340.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 332.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 147.62, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 147.62, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-e0014/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-e0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-e0023/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2cc6435b01fb45fed7f9dd75f98138add83df977 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R01,I2,2,6.9,kg,450,2,approved +R02,I1,2,5.4,kg,268,2,approved +R02,I2,2,2.7,kg,268,2,approved +R02,I0,2,13.3,kg,268,2,approved +R01,I0,2,7.5,kg,450,2,approved +R00,I0,2,11.5,kg,659,2,approved +R01,I1,6,10.5,kg,450,2,approved +R00,I1,6,14.7,kg,659,2,approved +R00,VOID,999,11.5,kg,659,2,cancelled +R00,I2,2,4.4,kg,659,2,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..86f2071267bfc35f31f3dfd595be145573299775 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-e0023/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1a089864c72ed65775c88e7ed7bf7740432722f0 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 672.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 8069.39, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 134.49, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 403.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 134.49, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 459.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 4215.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 91.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 275.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 91.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 273.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 1950.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 91.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 91.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 91.16, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-e0023/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-e0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0005/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..c5f2d2a00b2842d4b20ebbf38613b98f02fb0f31 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I0,8,6.7,kg,344,8,approved +R00,I1,8,9.7,kg,559,10,approved +R02,I1,9,6.7,kg,344,8,approved +R01,I2,8,4.0,kg,386,5,approved +R00,VOID,999,7.7,kg,559,10,cancelled +R01,I0,4,8.9,kg,386,5,approved +R02,I2,6,5.1,kg,344,8,approved +R01,I1,4,6.8,kg,386,5,approved +R00,I2,3,7.8,kg,559,10,approved +R00,I0,4,7.7,kg,559,10,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3d66e213eaded37c4da7bb7c8a65a0178af7bfa4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0005/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..caff53ce47d59306b91512acef13b9831ffc63c3 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 621.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5457.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 165.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 331.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 124.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 406.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 2407.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 101.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 101.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 203.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 373.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 2349.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 130.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 146.31, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 97.54, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0005/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0014/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..d1b2a7472feb91a30266eefa97be43127d11316e --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I1,6,13.6,kg,873,2,approved +R00,I0,4,4.8,kg,771,8,approved +R02,I0,8,14.7,kg,873,2,approved +R00,I1,2,9.6,kg,771,8,approved +R01,I2,3,5.6,kg,418,10,approved +R02,I2,6,11.0,kg,873,2,approved +R00,I2,9,6.1,kg,771,8,approved +R00,VOID,999,4.8,kg,771,8,cancelled +R01,I0,2,10.8,kg,418,10,approved +R01,I1,7,6.6,kg,418,10,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e25e775142fb83ee539665ad23328788b43d9433 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0014/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5427ab180f79ce1a10005d37daf61b5fa06bf8cc --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 838.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5212.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 223.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 111.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 502.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 464.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 3274.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 77.41, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 270.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 116.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 890.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 11812.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 356.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 267.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 267.24, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0014/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0023/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..196007e74f8c7c6d66e56d2e0d3d72dff17976f0 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,VOID,999,9.4,kg,818,2,cancelled +R02,I0,7,5.4,kg,875,10,approved +R00,I0,5,9.4,kg,818,2,approved +R00,I2,6,13.1,kg,818,2,approved +R02,I1,5,14.0,kg,875,10,approved +R00,I1,9,12.3,kg,818,2,approved +R01,I0,2,10.8,kg,861,8,approved +R01,I1,5,11.5,kg,861,8,approved +R01,I2,2,5.1,kg,861,8,approved +R02,I2,6,8.3,kg,875,10,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..83304c65dcdeb308f07bc71e5a6b479b8cd9e52b --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0023/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..695199923890f20da1a8652057e9268b470ba93e --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 834.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 9861.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 208.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 375.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 250.41, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 935.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 9285.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 207.97, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 519.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 207.97, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 972.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 8512.35, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 378.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 270.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 324.07, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0023/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0032/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..c8fde82345c150afa25db60d5a189ec236b2d398 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I1,8,13.8,kg,620,10,approved +R01,I0,9,14.5,kg,518,5,approved +R02,I2,3,13.4,kg,882,8,approved +R00,I0,3,14.9,kg,620,10,approved +R01,I2,5,2.2,kg,518,5,approved +R01,I1,8,8.1,kg,518,5,approved +R02,I1,8,2.1,kg,882,8,approved +R02,I0,8,9.2,kg,882,8,approved +R00,I2,4,9.4,kg,620,10,approved +R00,VOID,999,14.9,kg,620,10,cancelled diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8a6e178cdef6f51d964f39184adde255235890dc --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0032/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..baaef85e3dc0efd19c92e1844734ad2c9618188c --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 688.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 8849.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 137.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 367.41, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 183.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 545.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 5113.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 223.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 198.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 123.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 958.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 6589.77, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 403.66, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 403.66, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 151.37, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0032/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0032/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0041/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a3e1a8151ace1ce4d527f33c6af8f5de1c78aaa6 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R01,I0,4,7.2,kg,877,8,approved +R00,I0,8,3.9,kg,360,10,approved +R00,I2,6,4.6,kg,360,10,approved +R00,VOID,999,3.9,kg,360,10,cancelled +R01,I2,8,11.3,kg,877,8,approved +R00,I1,5,5.1,kg,360,10,approved +R02,I1,4,14.7,kg,882,2,approved +R01,I1,2,2.4,kg,877,8,approved +R02,I0,5,13.9,kg,882,2,approved +R02,I2,5,14.9,kg,882,2,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..13c66f624f8d87418532b0e2a66f5b05a755e9bf --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0041/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c476205a11762e4f8fdca816b8043ec5508bcf62 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 400.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 1774.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 168.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 105.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 126.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 953.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 8443.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 272.36, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 136.18, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 544.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 900.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 13037.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 321.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 257.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 321.43, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0041/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0041/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0050/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..dbc0a11ccc641b4146488c519bc9293c52417785 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R01,I1,7,12.1,kg,498,2,approved +R00,I0,5,7.7,kg,612,10,approved +R02,I2,3,11.1,kg,762,10,approved +R02,I1,9,9.0,kg,762,10,approved +R00,VOID,999,7.7,kg,612,10,cancelled +R01,I2,5,6.3,kg,498,2,approved +R00,I1,9,12.0,kg,612,10,approved +R00,I2,7,9.6,kg,612,10,approved +R02,I0,3,7.7,kg,762,10,approved +R01,I0,5,7.2,kg,498,2,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2d07a58cda38aa8917ca374b293d29417009028a --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0050/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..28008c0720291260e9b0ce3ea2422f5df4742a0a --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 680.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 6919.81, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 161.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 291.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 226.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 508.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 4549.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 149.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 209.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 149.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 846.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 7755.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 169.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 508.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 169.33, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0050/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0050/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0059/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..dfd48bf3e1c4c11fdbfa323d1eadf998da7aab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,VOID,999,4.8,kg,532,2,cancelled +R02,I0,8,2.2,kg,773,8,approved +R00,I2,5,12.4,kg,532,2,approved +R00,I0,7,4.8,kg,532,2,approved +R02,I2,8,14.6,kg,773,8,approved +R01,I2,6,8.4,kg,263,8,approved +R01,I1,9,12.9,kg,263,8,approved +R02,I1,4,13.6,kg,773,8,approved +R00,I1,3,13.9,kg,532,2,approved +R01,I0,5,2.6,kg,263,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..61902bcb77541ed522ae471a9d8044a42d8b808d --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0059/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..96fb2ceda13a87321783fe5af51f2f51f604a2e2 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 542.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 4968.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 253.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 108.57, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 180.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 285.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 2565.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 71.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 128.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 85.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 840.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 7931.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 336.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 168.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 336.09, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0059/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0059/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0068/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..b56c9e5529dcd694326177e95923650edc865792 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R01,I2,2,5.4,kg,313,2,approved +R02,I0,5,11.5,kg,840,8,approved +R01,I1,5,5.6,kg,313,2,approved +R00,I2,3,7.9,kg,235,8,approved +R00,VOID,999,4.1,kg,235,8,cancelled +R01,I0,7,14.6,kg,313,2,approved +R00,I1,2,13.8,kg,235,8,approved +R00,I0,3,4.1,kg,235,8,approved +R02,I1,7,6.3,kg,840,8,approved +R02,I2,5,12.2,kg,840,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9c3f1cc05be023bd414228c38280ba3bb6a9fa31 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0068/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ae9f7cff50e0118d6efae64230c4b822799c3303 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 255.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 2030.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 95.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 63.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 95.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 319.39, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 3216.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 159.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 114.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 45.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 913.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 8732.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 268.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 375.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 268.54, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0068/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0068/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0077/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..3994db0b185883d7e6293c5f616867b54617975e --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/environment/workdir/recipes.csv @@ -0,0 +1,11 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I2,6,4.7,kg,716,5,approved +R02,I1,9,14.6,kg,575,8,approved +R00,VOID,999,5.7,kg,716,5,cancelled +R01,I0,8,5.3,kg,584,10,approved +R01,I1,8,12.6,kg,584,10,approved +R02,I0,7,11.1,kg,575,8,approved +R00,I1,3,2.2,kg,716,5,approved +R00,I0,2,5.7,kg,716,5,approved +R01,I2,4,10.4,kg,584,10,approved +R02,I2,2,8.2,kg,575,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cd74c81ef44ccff86154d2ac66bd23b16ca2b9d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..be9639faf80bc03d87b7d5c1c3104ccb0f28d1c6 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d2-t0077/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2ec979ddebc526ef704c7d47a78461a2d4a7a33b --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 753.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 3165.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 137.03, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 205.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 411.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 648.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 5995.73, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 259.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 259.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 129.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 625.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 7829.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 243.06, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 312.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 69.44, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d2-t0077/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d2-t0077/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-e0008/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..36f73420ccf026f634a2b2c3c964ccce97952e2f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I2,8,10.1,kg,734,8,approved +R00,I0,5,7.4,kg,825,8,approved +R02,I1,8,0.0027,g,734,8,approved +R01,I2,5,8.5,kg,861,8,approved +R01,I0,6,11.1,kg,861,8,approved +R03,I1,5,0.008,g,567,10,approved +R03,I0,8,14.0,kg,567,10,approved +R03,I2,2,4.6,kg,567,10,approved +R02,I0,5,11.0,kg,734,8,approved +R00,VOID,999,7.4,kg,825,8,cancelled +R00,I1,8,0.008,g,825,8,approved +R00,I2,3,6.0,kg,825,8,approved +R01,I1,7,0.0086,g,861,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3684d1a0ab391e4e7aa157efc6f11338b6e52918 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-e0008/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d026a6e2859264e80e8684a836781652dbd8ea1a --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 896.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 6669.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 280.23, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 448.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 168.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 935.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 8802.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 311.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 363.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 259.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 797.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 5979.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 189.96, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 303.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 303.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 630.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 6770.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 336.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 210.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 84.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 28222.17, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-e0008/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-e0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-e0017/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..912fc7e3ac366187b23bebc221e8e723be61f138 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I2,8,8.7,kg,446,8,approved +R03,I0,5,2.5,kg,885,10,approved +R01,I1,4,0.013800000000000002,g,622,2,approved +R02,I0,3,7.7,kg,380,10,approved +R00,I1,8,0.0023,g,446,8,approved +R01,I0,2,10.2,kg,622,2,approved +R03,I1,2,0.0147,g,885,10,approved +R02,I2,4,4.5,kg,380,10,approved +R01,I2,3,6.8,kg,622,2,approved +R03,I2,3,8.6,kg,885,10,approved +R00,VOID,999,13.9,kg,446,8,cancelled +R02,I1,7,0.0087,g,380,10,approved +R00,I0,3,13.9,kg,446,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5d8d4ca2dc9e0f7cb158eb9240737734a48028e7 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "eval"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-e0017/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..40f2b53361401827c62cf37a326fea44f3690f79 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 484.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 3309.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 76.54, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 204.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 204.12, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 634.69, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 6770.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 141.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 282.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 211.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 422.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 3076.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 90.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 211.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 120.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 983.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 6657.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 491.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 196.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 295.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 19812.7, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-e0017/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-e0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0008/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..e92ed382fb0b6671f100d756414cca0cac3bbb40 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R01,I0,7,13.4,kg,574,10,approved +R00,VOID,999,9.2,kg,475,8,cancelled +R03,I1,8,0.002,g,727,2,approved +R03,I2,3,3.1,kg,727,2,approved +R00,I2,9,2.4,kg,475,8,approved +R02,I1,2,0.0043,g,294,10,approved +R03,I0,4,4.6,kg,727,2,approved +R02,I0,4,2.8,kg,294,10,approved +R00,I0,3,9.2,kg,475,8,approved +R01,I1,6,0.005900000000000001,g,574,10,approved +R01,I2,7,12.9,kg,574,10,approved +R02,I2,2,12.8,kg,294,10,approved +R00,I1,3,0.0091,g,475,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..86d323bc766d5c34bfd7b3172a9d3dc523cf56a1 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0008/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..aeab835b7dbd38ddc3514d78e1d3e95c956e2cae --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 516.3, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 2633.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 103.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 103.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 309.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 637.78, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 6999.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 223.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 191.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 223.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 326.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 1853.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 163.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 81.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 81.67, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 741.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 2161.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 197.82, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 395.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 148.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 13647.81, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0008/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0017/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..0113c00ce92a41d434af7db31cd68e058b3a094e --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I2,4,11.0,kg,424,2,approved +R03,I0,2,14.0,kg,822,5,approved +R03,I1,9,0.009300000000000001,g,822,5,approved +R01,I0,2,8.2,kg,701,5,approved +R00,I1,8,0.0126,g,478,5,approved +R00,I0,2,5.4,kg,478,5,approved +R03,I2,4,14.3,kg,822,5,approved +R01,I2,5,2.1,kg,701,5,approved +R02,I1,6,0.0050999999999999995,g,424,2,approved +R00,VOID,999,5.4,kg,478,5,cancelled +R01,I1,9,0.0103,g,701,5,approved +R00,I2,4,12.0,kg,478,5,approved +R02,I0,7,10.0,kg,424,2,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d014eb2cbba7861cac99631ef68b4639d5fbb25d --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0017/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0eb9107cfbe5fb64cb1861a039d944f212711576 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 503.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5736.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 71.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 287.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 143.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 737.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 5515.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 92.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 415.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 230.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 432.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 3680.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 178.15, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 152.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 101.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 865.26, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 9742.86, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 115.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 519.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 230.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 24674.72, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0017/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0026/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..e588c225a83fe4a61de1c369c99d65ace6c0caea --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I2,5,14.8,kg,483,5,approved +R03,I2,9,3.0,kg,395,10,approved +R01,I0,3,14.9,kg,618,2,approved +R03,I0,9,6.7,kg,395,10,approved +R02,I0,6,8.3,kg,420,8,approved +R01,I1,8,0.0048,g,618,2,approved +R01,I2,2,13.5,kg,618,2,approved +R02,I1,4,0.0032,g,420,8,approved +R00,I0,2,2.2,kg,483,5,approved +R02,I2,4,14.2,kg,420,8,approved +R03,I1,8,0.0115,g,395,10,approved +R00,VOID,999,2.2,kg,483,5,cancelled +R00,I1,4,0.0143,g,483,5,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5918da1939b3dcfe25ad21410acef6027fa92908 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0026/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..75f45b1c9ae37337a9f2c406e360b1c3ce20d348 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 508.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 6267.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 92.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 184.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 231.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 630.61, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 5340.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 145.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 388.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 97.02, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 456.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 3893.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 195.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 130.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 130.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 438.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 3026.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 151.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 135.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 151.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 18528.37, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0026/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0026/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0035/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..f89a6f9002ceeac54b4dfe1a6c897b3497ff5303 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I1,9,0.0064,g,777,10,approved +R01,I0,7,8.5,kg,817,8,approved +R02,I0,4,5.5,kg,811,2,approved +R00,I0,4,4.9,kg,777,10,approved +R02,I2,5,6.9,kg,811,2,approved +R01,I2,4,14.7,kg,817,8,approved +R03,I1,3,0.0064,g,849,2,approved +R00,VOID,999,4.9,kg,777,10,cancelled +R02,I1,2,0.013800000000000002,g,811,2,approved +R00,I2,6,6.3,kg,777,10,approved +R03,I0,6,4.2,kg,849,2,approved +R01,I1,5,0.0060999999999999995,g,817,8,approved +R03,I2,4,2.8,kg,849,2,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b5d72459c68155db35ff1a11b32dec846c78a164 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0035/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..664d3b4206451e142049c616a4c95b82a2318cc3 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 863.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5225.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 181.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 408.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 272.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 888.04, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 8258.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 388.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 277.51, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 222.01, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 827.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 6327.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 300.93, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 150.46, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 376.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 866.33, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 3705.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 399.84, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 199.92, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 266.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 23516.46, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0035/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0035/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0044/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..a8ef1abe4c5676bb43e3f3c532999618f60e6212 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,VOID,999,13.8,kg,779,2,cancelled +R01,I0,7,9.4,kg,544,2,approved +R02,I2,2,12.0,kg,712,10,approved +R03,I1,8,0.006900000000000001,g,561,5,approved +R01,I1,9,0.0022,g,544,2,approved +R00,I2,3,12.0,kg,779,2,approved +R00,I0,4,13.8,kg,779,2,approved +R03,I2,9,13.8,kg,561,5,approved +R02,I0,3,14.5,kg,712,10,approved +R01,I2,8,12.2,kg,544,2,approved +R03,I0,2,2.9,kg,561,5,approved +R00,I1,7,0.005,g,779,2,approved +R02,I1,4,0.0028,g,712,10,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c8e6887c0c6aa607f0fef8e67c227d4e9e92f2d4 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0044/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b5a78b04eecf563e29a93530bc148c69635de04e --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 794.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 7165.44, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 227.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 397.45, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 170.34, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 555.1, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 4237.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 161.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 208.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 185.03, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 791.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 6917.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 263.7, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 351.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 175.8, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 590.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 5756.08, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 62.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 248.64, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 279.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 24076.62, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0044/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0044/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0053/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..50c88f57a23feaee328666329ed5cb368ce79818 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R00,I1,8,0.0022,g,221,10,approved +R01,I0,3,7.6,kg,329,2,approved +R02,I0,6,13.7,kg,277,2,approved +R01,I1,4,0.009300000000000001,g,329,2,approved +R03,I2,9,14.2,kg,645,5,approved +R01,I2,8,7.7,kg,329,2,approved +R00,I0,8,5.0,kg,221,10,approved +R02,I2,8,13.9,kg,277,2,approved +R03,I1,7,0.014199999999999999,g,645,5,approved +R02,I1,7,0.0036,g,277,2,approved +R00,VOID,999,5.0,kg,221,10,cancelled +R00,I2,9,6.8,kg,221,10,approved +R03,I0,9,8.5,kg,645,5,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5dc4ba9bb30f88cc0405bbc10d784a8c408fcecf --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0053/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ec1c4d2b2527b29fbf025a44da37fbb168a83176 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 245.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 1166.88, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 78.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 78.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 88.4, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 335.71, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 2721.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 67.14, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 89.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 179.05, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 282.65, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 2942.28, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 80.76, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 94.22, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 107.68, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 678.95, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 8247.85, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 244.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 190.11, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 244.42, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 15078.54, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0053/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0053/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0062/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..2a0bc418171d2020416cdc47e522519eba0db64f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I1,7,0.0065,g,691,8,approved +R02,I0,7,5.0,kg,691,8,approved +R00,I0,3,7.4,kg,855,5,approved +R01,I1,9,0.0126,g,769,8,approved +R03,I2,5,12.0,kg,320,10,approved +R00,I2,3,4.7,kg,855,5,approved +R03,I1,9,0.0103,g,320,10,approved +R01,I2,8,13.4,kg,769,8,approved +R01,I0,4,9.0,kg,769,8,approved +R00,VOID,999,7.4,kg,855,5,cancelled +R02,I2,9,11.7,kg,691,8,approved +R03,I0,9,11.3,kg,320,10,approved +R00,I1,3,0.0066,g,855,5,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..38aec44eba08bf5b915d83bea9cea70190ad401b --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0062/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..91cae62eab4030a04db4e79ce1741f041e809399 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 900.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 5610.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 300.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 300.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 300.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 835.87, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 10213.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 159.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 358.23, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 318.43, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 751.09, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 6067.48, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 228.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 228.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 293.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 355.56, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 3932.75, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 139.13, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 139.13, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 77.29, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 25823.76, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0062/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0062/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0071/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..f989f5aaa10bf063fc9c65d9c4c96718c431336c --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R01,I0,5,14.2,kg,315,5,approved +R03,I1,5,0.0141,g,748,2,approved +R00,I1,2,0.0149,g,862,5,approved +R03,I0,8,6.7,kg,748,2,approved +R01,I2,5,15.0,kg,315,5,approved +R03,I2,9,10.7,kg,748,2,approved +R02,I1,4,0.013,g,685,2,approved +R00,I2,8,6.2,kg,862,5,approved +R00,VOID,999,3.3,kg,862,5,cancelled +R02,I0,4,10.4,kg,685,2,approved +R00,I0,4,3.3,kg,862,5,approved +R01,I1,7,0.0057,g,315,5,approved +R02,I2,3,2.4,kg,685,2,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2a8afcefd49758123ab6fc3b597cb152afee3fb2 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0071/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..efad61a3d8b77409903e0c3d22e68accb61a439f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 907.37, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 6001.59, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 259.25, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 129.62, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 518.5, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 331.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 3625.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 97.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 136.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 97.52, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 698.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 6405.19, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 254.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 254.17, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 190.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 763.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 7646.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 277.55, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 173.47, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 312.24, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 23679.23, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0071/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0071/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0080/environment/Dockerfile b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/environment/workdir/recipes.csv b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/environment/workdir/recipes.csv new file mode 100644 index 0000000000000000000000000000000000000000..611708afad9de393885cd5b4e5d61bf0139e7ab8 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/environment/workdir/recipes.csv @@ -0,0 +1,14 @@ +recipe_id,ingredient_id,parts,unit_cost,cost_per,finished_kg,process_loss_percent,status +R02,I1,5,0.013099999999999999,g,620,8,approved +R03,I1,5,0.0108,g,715,5,approved +R00,I0,5,8.8,kg,441,5,approved +R00,VOID,999,8.8,kg,441,5,cancelled +R03,I0,2,7.3,kg,715,5,approved +R01,I2,7,8.5,kg,244,2,approved +R03,I2,3,5.0,kg,715,5,approved +R01,I1,6,0.0026,g,244,2,approved +R00,I2,2,12.3,kg,441,5,approved +R00,I1,8,0.0036,g,441,5,approved +R01,I0,5,11.6,kg,244,2,approved +R02,I2,6,3.4,kg,620,8,approved +R02,I0,5,13.1,kg,620,8,approved diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/instruction.md b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b624abde67254795f191050840c001263a62186 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/instruction.md @@ -0,0 +1,5 @@ +# Food Batch: recipe-scaling + +`recipes.csv` gives mass parts and ingredient unit costs in fictional crowns (CRN). Within each recipe, finished kg and process loss are repeated. Return per recipe id `charge_kg` = finished/(1-loss/100), `ingredient_I0_kg`, `ingredient_I1_kg`, `ingredient_I2_kg` = charge*ingredient parts/sum parts, and `cost_crn` = total ingredient purchase cost. `cost_per` is the mass unit to which `unit_cost` applies; convert to cost per kg first. Loss occurs after purchasing and mixing all ingredients. + +Only `status=approved` rows belong to the production plan. 1 tonne = 1000 kg; 1 g = 0.001 kg. Write `answer.json` with `results`, keyed by the indicated id. Also return `total_primary`, the sum of `cost_crn` over result groups. Every numeric output is in 2 decimals, accepted within 0.01. Do not round intermediate values. All process data and targets are synthetic planning assumptions; no food-safety judgement is requested. diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/solution/oracle.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..7003460851f93cbbf89a59efa304bfffb171118f --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/solution/oracle.py @@ -0,0 +1,33 @@ +"""Independent mass balances from the supplied production records.""" +import csv,json +from pathlib import Path + +def read(name): + with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved'] + +def solve(): + out={} + if Path('drying.csv').exists(): + for row in read('drying.csv'): + mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1) + water=mass*float(row['initial_moisture_percent'])/100; dry=mass-water; retained=dry-dry*float(row['dry_solids_loss_percent'])/100; ratio=float(row['target_moisture_percent'])/(100-float(row['target_moisture_percent'])); final_water=retained*ratio + out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water) + primary='product_kg' + elif Path('blends.csv').exists(): + for row in read('blends.csv'): + total=float(row['finished_mass'])*(.001 if row['mass_unit']=='g' else 1000 if row['mass_unit']=='tonne' else 1);low,high,target=[float(row[k])/100 for k in ('low_percent','high_percent','target_percent')];retain=1-float(row['uniform_process_loss_percent'])/100 + # Solve the component balance for the low ingredient first. + charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a + out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target) + primary='charge_kg' + else: + rows=read('recipes.csv') + for key in sorted({r['recipe_id'] for r in rows}): + rs=[r for r in rows if r['recipe_id']==key]; charge=float(rs[0]['finished_kg'])*100/(100-float(rs[0]['process_loss_percent'])); partmass=charge/sum(float(r['parts']) for r in rs);values=dict(charge_kg=charge,cost_crn=0) + for row in rs: + mass=partmass*float(row['parts']);values['ingredient_'+row['ingredient_id']+'_kg']=mass;values['cost_crn']+=mass*float(row['unit_cost'])*(1000 if row['cost_per']=='g' else .001 if row['cost_per']=='tonne' else 1) + out[key]=values + primary='cost_crn' + return dict(results=out,total_primary=sum(x[primary] for x in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/solution/solve.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/task.toml b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9932efbe8e23933640670995bead7c483542544b --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "food-batch" +tags = ["food-batch", "recipe-scaling", "isced-0721", "train"] +isced_f = "0721" +family = "recipe-scaling" +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/food-batch/food-batch-recipe-scaling-d3-t0080/tests/checks.json b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bf690793fc96fd9eb0ad4b42a559583554e59ac9 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.R00.charge_kg", + "type": "number", + "value": 464.21, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.cost_crn", + "type": "number", + "value": 3014.27, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I0_kg", + "type": "number", + "value": 154.74, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I1_kg", + "type": "number", + "value": 247.58, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R00.ingredient_I2_kg", + "type": "number", + "value": 61.89, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.charge_kg", + "type": "number", + "value": 248.98, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.cost_crn", + "type": "number", + "value": 1841.07, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I0_kg", + "type": "number", + "value": 69.16, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I1_kg", + "type": "number", + "value": 82.99, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R01.ingredient_I2_kg", + "type": "number", + "value": 96.83, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.charge_kg", + "type": "number", + "value": 673.91, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.cost_crn", + "type": "number", + "value": 6376.9, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I0_kg", + "type": "number", + "value": 210.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I1_kg", + "type": "number", + "value": 210.6, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R02.ingredient_I2_kg", + "type": "number", + "value": 252.72, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.charge_kg", + "type": "number", + "value": 752.63, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.cost_crn", + "type": "number", + "value": 6292.0, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I0_kg", + "type": "number", + "value": 150.53, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I1_kg", + "type": "number", + "value": 376.32, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "results.R03.ingredient_I2_kg", + "type": "number", + "value": 225.79, + "abs_tol": 0.01, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 17524.24, + "abs_tol": 0.01, + "weight": 1.0 + } +] diff --git a/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/tests/test.sh b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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/food-batch/food-batch-recipe-scaling-d3-t0080/tests/verify.py b/tasks/food-batch/food-batch-recipe-scaling-d3-t0080/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/food-batch/food-batch-recipe-scaling-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()