birgermoell commited on
Commit
08bbe1a
·
verified ·
1 Parent(s): 6336e40

Add food-batch subset: 84 train and 24 eval tasks

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/food-batch/food-batch-blending-d1-e0000/environment/Dockerfile +3 -0
  2. tasks/food-batch/food-batch-blending-d1-e0000/environment/workdir/blends.csv +3 -0
  3. tasks/food-batch/food-batch-blending-d1-e0000/instruction.md +5 -0
  4. tasks/food-batch/food-batch-blending-d1-e0000/solution/oracle.py +33 -0
  5. tasks/food-batch/food-batch-blending-d1-e0000/solution/solve.sh +4 -0
  6. tasks/food-batch/food-batch-blending-d1-e0000/task.toml +25 -0
  7. tasks/food-batch/food-batch-blending-d1-e0000/tests/checks.json +58 -0
  8. tasks/food-batch/food-batch-blending-d1-e0000/tests/test.sh +3 -0
  9. tasks/food-batch/food-batch-blending-d1-e0000/tests/verify.py +116 -0
  10. tasks/food-batch/food-batch-blending-d1-e0009/environment/Dockerfile +3 -0
  11. tasks/food-batch/food-batch-blending-d1-e0009/environment/workdir/blends.csv +3 -0
  12. tasks/food-batch/food-batch-blending-d1-e0009/instruction.md +5 -0
  13. tasks/food-batch/food-batch-blending-d1-e0009/solution/oracle.py +33 -0
  14. tasks/food-batch/food-batch-blending-d1-e0009/solution/solve.sh +4 -0
  15. tasks/food-batch/food-batch-blending-d1-e0009/task.toml +25 -0
  16. tasks/food-batch/food-batch-blending-d1-e0009/tests/checks.json +58 -0
  17. tasks/food-batch/food-batch-blending-d1-e0009/tests/test.sh +3 -0
  18. tasks/food-batch/food-batch-blending-d1-e0009/tests/verify.py +116 -0
  19. tasks/food-batch/food-batch-blending-d1-e0018/environment/Dockerfile +3 -0
  20. tasks/food-batch/food-batch-blending-d1-e0018/environment/workdir/blends.csv +3 -0
  21. tasks/food-batch/food-batch-blending-d1-e0018/instruction.md +5 -0
  22. tasks/food-batch/food-batch-blending-d1-e0018/solution/oracle.py +33 -0
  23. tasks/food-batch/food-batch-blending-d1-e0018/solution/solve.sh +4 -0
  24. tasks/food-batch/food-batch-blending-d1-e0018/task.toml +25 -0
  25. tasks/food-batch/food-batch-blending-d1-e0018/tests/checks.json +58 -0
  26. tasks/food-batch/food-batch-blending-d1-e0018/tests/test.sh +3 -0
  27. tasks/food-batch/food-batch-blending-d1-e0018/tests/verify.py +116 -0
  28. tasks/food-batch/food-batch-blending-d1-t0000/environment/Dockerfile +3 -0
  29. tasks/food-batch/food-batch-blending-d1-t0000/environment/workdir/blends.csv +3 -0
  30. tasks/food-batch/food-batch-blending-d1-t0000/instruction.md +5 -0
  31. tasks/food-batch/food-batch-blending-d1-t0000/solution/oracle.py +33 -0
  32. tasks/food-batch/food-batch-blending-d1-t0000/solution/solve.sh +4 -0
  33. tasks/food-batch/food-batch-blending-d1-t0000/task.toml +25 -0
  34. tasks/food-batch/food-batch-blending-d1-t0000/tests/checks.json +58 -0
  35. tasks/food-batch/food-batch-blending-d1-t0000/tests/test.sh +3 -0
  36. tasks/food-batch/food-batch-blending-d1-t0000/tests/verify.py +116 -0
  37. tasks/food-batch/food-batch-blending-d1-t0009/environment/Dockerfile +3 -0
  38. tasks/food-batch/food-batch-blending-d1-t0009/environment/workdir/blends.csv +3 -0
  39. tasks/food-batch/food-batch-blending-d1-t0009/instruction.md +5 -0
  40. tasks/food-batch/food-batch-blending-d1-t0009/solution/oracle.py +33 -0
  41. tasks/food-batch/food-batch-blending-d1-t0009/solution/solve.sh +4 -0
  42. tasks/food-batch/food-batch-blending-d1-t0009/task.toml +25 -0
  43. tasks/food-batch/food-batch-blending-d1-t0009/tests/checks.json +58 -0
  44. tasks/food-batch/food-batch-blending-d1-t0009/tests/test.sh +3 -0
  45. tasks/food-batch/food-batch-blending-d1-t0009/tests/verify.py +116 -0
  46. tasks/food-batch/food-batch-blending-d1-t0018/environment/Dockerfile +3 -0
  47. tasks/food-batch/food-batch-blending-d1-t0018/environment/workdir/blends.csv +3 -0
  48. tasks/food-batch/food-batch-blending-d1-t0018/instruction.md +5 -0
  49. tasks/food-batch/food-batch-blending-d1-t0018/solution/oracle.py +33 -0
  50. tasks/food-batch/food-batch-blending-d1-t0018/solution/solve.sh +4 -0
tasks/food-batch/food-batch-blending-d1-e0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/food-batch/food-batch-blending-d1-e0000/environment/workdir/blends.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status
2
+ B00,460,kg,6,48,24,0,approved
3
+ B01,788,kg,3,41,20,0,approved
tasks/food-batch/food-batch-blending-d1-e0000/instruction.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Food Batch: blending
2
+
3
+ `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.
4
+
5
+ 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.
tasks/food-batch/food-batch-blending-d1-e0000/solution/oracle.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Independent mass balances from the supplied production records."""
2
+ import csv,json
3
+ from pathlib import Path
4
+
5
+ def read(name):
6
+ with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved']
7
+
8
+ def solve():
9
+ out={}
10
+ if Path('drying.csv').exists():
11
+ for row in read('drying.csv'):
12
+ mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1)
13
+ 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
14
+ out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water)
15
+ primary='product_kg'
16
+ elif Path('blends.csv').exists():
17
+ for row in read('blends.csv'):
18
+ 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
19
+ # Solve the component balance for the low ingredient first.
20
+ charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a
21
+ out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target)
22
+ primary='charge_kg'
23
+ else:
24
+ rows=read('recipes.csv')
25
+ for key in sorted({r['recipe_id'] for r in rows}):
26
+ 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)
27
+ for row in rs:
28
+ 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)
29
+ out[key]=values
30
+ primary='cost_crn'
31
+ return dict(results=out,total_primary=sum(x[primary] for x in out.values()))
32
+
33
+ if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
tasks/food-batch/food-batch-blending-d1-e0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/food-batch/food-batch-blending-d1-e0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "food-batch"
8
+ tags = ["food-batch", "blending", "isced-0721", "eval"]
9
+ isced_f = "0721"
10
+ family = "blending"
11
+ split = "eval"
12
+ seed = 10000
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/food-batch/food-batch-blending-d1-e0000/tests/checks.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "results.B00.charge_kg",
4
+ "type": "number",
5
+ "value": 460.0,
6
+ "abs_tol": 0.01,
7
+ "weight": 1.0
8
+ },
9
+ {
10
+ "path": "results.B00.high_kg",
11
+ "type": "number",
12
+ "value": 197.14,
13
+ "abs_tol": 0.01,
14
+ "weight": 1.0
15
+ },
16
+ {
17
+ "path": "results.B00.low_kg",
18
+ "type": "number",
19
+ "value": 262.86,
20
+ "abs_tol": 0.01,
21
+ "weight": 1.0
22
+ },
23
+ {
24
+ "path": "results.B00.retained_component_kg",
25
+ "type": "number",
26
+ "value": 110.4,
27
+ "abs_tol": 0.01,
28
+ "weight": 1.0
29
+ },
30
+ {
31
+ "path": "results.B01.charge_kg",
32
+ "type": "number",
33
+ "value": 788.0,
34
+ "abs_tol": 0.01,
35
+ "weight": 1.0
36
+ },
37
+ {
38
+ "path": "results.B01.high_kg",
39
+ "type": "number",
40
+ "value": 352.53,
41
+ "abs_tol": 0.01,
42
+ "weight": 1.0
43
+ },
44
+ {
45
+ "path": "results.B01.low_kg",
46
+ "type": "number",
47
+ "value": 435.47,
48
+ "abs_tol": 0.01,
49
+ "weight": 1.0
50
+ },
51
+ {
52
+ "path": "results.B01.retained_component_kg",
53
+ "type": "number",
54
+ "value": 157.6,
55
+ "abs_tol": 0.01,
56
+ "weight": 1.0
57
+ }
58
+ ]
tasks/food-batch/food-batch-blending-d1-e0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/food-batch/food-batch-blending-d1-e0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/food-batch/food-batch-blending-d1-e0009/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/food-batch/food-batch-blending-d1-e0009/environment/workdir/blends.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status
2
+ B00,711,kg,9,44,20,0,approved
3
+ B01,320,kg,3,46,25,0,approved
tasks/food-batch/food-batch-blending-d1-e0009/instruction.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Food Batch: blending
2
+
3
+ `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.
4
+
5
+ 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.
tasks/food-batch/food-batch-blending-d1-e0009/solution/oracle.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Independent mass balances from the supplied production records."""
2
+ import csv,json
3
+ from pathlib import Path
4
+
5
+ def read(name):
6
+ with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved']
7
+
8
+ def solve():
9
+ out={}
10
+ if Path('drying.csv').exists():
11
+ for row in read('drying.csv'):
12
+ mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1)
13
+ 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
14
+ out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water)
15
+ primary='product_kg'
16
+ elif Path('blends.csv').exists():
17
+ for row in read('blends.csv'):
18
+ 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
19
+ # Solve the component balance for the low ingredient first.
20
+ charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a
21
+ out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target)
22
+ primary='charge_kg'
23
+ else:
24
+ rows=read('recipes.csv')
25
+ for key in sorted({r['recipe_id'] for r in rows}):
26
+ 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)
27
+ for row in rs:
28
+ 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)
29
+ out[key]=values
30
+ primary='cost_crn'
31
+ return dict(results=out,total_primary=sum(x[primary] for x in out.values()))
32
+
33
+ if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
tasks/food-batch/food-batch-blending-d1-e0009/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/food-batch/food-batch-blending-d1-e0009/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "food-batch"
8
+ tags = ["food-batch", "blending", "isced-0721", "eval"]
9
+ isced_f = "0721"
10
+ family = "blending"
11
+ split = "eval"
12
+ seed = 10009
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/food-batch/food-batch-blending-d1-e0009/tests/checks.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "results.B00.charge_kg",
4
+ "type": "number",
5
+ "value": 711.0,
6
+ "abs_tol": 0.01,
7
+ "weight": 1.0
8
+ },
9
+ {
10
+ "path": "results.B00.high_kg",
11
+ "type": "number",
12
+ "value": 223.46,
13
+ "abs_tol": 0.01,
14
+ "weight": 1.0
15
+ },
16
+ {
17
+ "path": "results.B00.low_kg",
18
+ "type": "number",
19
+ "value": 487.54,
20
+ "abs_tol": 0.01,
21
+ "weight": 1.0
22
+ },
23
+ {
24
+ "path": "results.B00.retained_component_kg",
25
+ "type": "number",
26
+ "value": 142.2,
27
+ "abs_tol": 0.01,
28
+ "weight": 1.0
29
+ },
30
+ {
31
+ "path": "results.B01.charge_kg",
32
+ "type": "number",
33
+ "value": 320.0,
34
+ "abs_tol": 0.01,
35
+ "weight": 1.0
36
+ },
37
+ {
38
+ "path": "results.B01.high_kg",
39
+ "type": "number",
40
+ "value": 163.72,
41
+ "abs_tol": 0.01,
42
+ "weight": 1.0
43
+ },
44
+ {
45
+ "path": "results.B01.low_kg",
46
+ "type": "number",
47
+ "value": 156.28,
48
+ "abs_tol": 0.01,
49
+ "weight": 1.0
50
+ },
51
+ {
52
+ "path": "results.B01.retained_component_kg",
53
+ "type": "number",
54
+ "value": 80.0,
55
+ "abs_tol": 0.01,
56
+ "weight": 1.0
57
+ }
58
+ ]
tasks/food-batch/food-batch-blending-d1-e0009/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/food-batch/food-batch-blending-d1-e0009/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/food-batch/food-batch-blending-d1-e0018/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/food-batch/food-batch-blending-d1-e0018/environment/workdir/blends.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status
2
+ B00,817,kg,6,38,18,0,approved
3
+ B01,947,kg,5,37,21,0,approved
tasks/food-batch/food-batch-blending-d1-e0018/instruction.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Food Batch: blending
2
+
3
+ `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.
4
+
5
+ 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.
tasks/food-batch/food-batch-blending-d1-e0018/solution/oracle.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Independent mass balances from the supplied production records."""
2
+ import csv,json
3
+ from pathlib import Path
4
+
5
+ def read(name):
6
+ with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved']
7
+
8
+ def solve():
9
+ out={}
10
+ if Path('drying.csv').exists():
11
+ for row in read('drying.csv'):
12
+ mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1)
13
+ 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
14
+ out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water)
15
+ primary='product_kg'
16
+ elif Path('blends.csv').exists():
17
+ for row in read('blends.csv'):
18
+ 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
19
+ # Solve the component balance for the low ingredient first.
20
+ charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a
21
+ out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target)
22
+ primary='charge_kg'
23
+ else:
24
+ rows=read('recipes.csv')
25
+ for key in sorted({r['recipe_id'] for r in rows}):
26
+ 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)
27
+ for row in rs:
28
+ 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)
29
+ out[key]=values
30
+ primary='cost_crn'
31
+ return dict(results=out,total_primary=sum(x[primary] for x in out.values()))
32
+
33
+ if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
tasks/food-batch/food-batch-blending-d1-e0018/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/food-batch/food-batch-blending-d1-e0018/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "food-batch"
8
+ tags = ["food-batch", "blending", "isced-0721", "eval"]
9
+ isced_f = "0721"
10
+ family = "blending"
11
+ split = "eval"
12
+ seed = 10018
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/food-batch/food-batch-blending-d1-e0018/tests/checks.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "results.B00.charge_kg",
4
+ "type": "number",
5
+ "value": 817.0,
6
+ "abs_tol": 0.01,
7
+ "weight": 1.0
8
+ },
9
+ {
10
+ "path": "results.B00.high_kg",
11
+ "type": "number",
12
+ "value": 306.38,
13
+ "abs_tol": 0.01,
14
+ "weight": 1.0
15
+ },
16
+ {
17
+ "path": "results.B00.low_kg",
18
+ "type": "number",
19
+ "value": 510.62,
20
+ "abs_tol": 0.01,
21
+ "weight": 1.0
22
+ },
23
+ {
24
+ "path": "results.B00.retained_component_kg",
25
+ "type": "number",
26
+ "value": 147.06,
27
+ "abs_tol": 0.01,
28
+ "weight": 1.0
29
+ },
30
+ {
31
+ "path": "results.B01.charge_kg",
32
+ "type": "number",
33
+ "value": 947.0,
34
+ "abs_tol": 0.01,
35
+ "weight": 1.0
36
+ },
37
+ {
38
+ "path": "results.B01.high_kg",
39
+ "type": "number",
40
+ "value": 473.5,
41
+ "abs_tol": 0.01,
42
+ "weight": 1.0
43
+ },
44
+ {
45
+ "path": "results.B01.low_kg",
46
+ "type": "number",
47
+ "value": 473.5,
48
+ "abs_tol": 0.01,
49
+ "weight": 1.0
50
+ },
51
+ {
52
+ "path": "results.B01.retained_component_kg",
53
+ "type": "number",
54
+ "value": 198.87,
55
+ "abs_tol": 0.01,
56
+ "weight": 1.0
57
+ }
58
+ ]
tasks/food-batch/food-batch-blending-d1-e0018/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/food-batch/food-batch-blending-d1-e0018/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/food-batch/food-batch-blending-d1-t0000/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/food-batch/food-batch-blending-d1-t0000/environment/workdir/blends.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status
2
+ B00,1089,kg,4,32,25,0,approved
3
+ B01,538,kg,9,50,24,0,approved
tasks/food-batch/food-batch-blending-d1-t0000/instruction.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Food Batch: blending
2
+
3
+ `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.
4
+
5
+ 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.
tasks/food-batch/food-batch-blending-d1-t0000/solution/oracle.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Independent mass balances from the supplied production records."""
2
+ import csv,json
3
+ from pathlib import Path
4
+
5
+ def read(name):
6
+ with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved']
7
+
8
+ def solve():
9
+ out={}
10
+ if Path('drying.csv').exists():
11
+ for row in read('drying.csv'):
12
+ mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1)
13
+ 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
14
+ out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water)
15
+ primary='product_kg'
16
+ elif Path('blends.csv').exists():
17
+ for row in read('blends.csv'):
18
+ 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
19
+ # Solve the component balance for the low ingredient first.
20
+ charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a
21
+ out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target)
22
+ primary='charge_kg'
23
+ else:
24
+ rows=read('recipes.csv')
25
+ for key in sorted({r['recipe_id'] for r in rows}):
26
+ 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)
27
+ for row in rs:
28
+ 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)
29
+ out[key]=values
30
+ primary='cost_crn'
31
+ return dict(results=out,total_primary=sum(x[primary] for x in out.values()))
32
+
33
+ if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
tasks/food-batch/food-batch-blending-d1-t0000/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/food-batch/food-batch-blending-d1-t0000/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "food-batch"
8
+ tags = ["food-batch", "blending", "isced-0721", "train"]
9
+ isced_f = "0721"
10
+ family = "blending"
11
+ split = "train"
12
+ seed = 0
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/food-batch/food-batch-blending-d1-t0000/tests/checks.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "results.B00.charge_kg",
4
+ "type": "number",
5
+ "value": 1089.0,
6
+ "abs_tol": 0.01,
7
+ "weight": 1.0
8
+ },
9
+ {
10
+ "path": "results.B00.high_kg",
11
+ "type": "number",
12
+ "value": 816.75,
13
+ "abs_tol": 0.01,
14
+ "weight": 1.0
15
+ },
16
+ {
17
+ "path": "results.B00.low_kg",
18
+ "type": "number",
19
+ "value": 272.25,
20
+ "abs_tol": 0.01,
21
+ "weight": 1.0
22
+ },
23
+ {
24
+ "path": "results.B00.retained_component_kg",
25
+ "type": "number",
26
+ "value": 272.25,
27
+ "abs_tol": 0.01,
28
+ "weight": 1.0
29
+ },
30
+ {
31
+ "path": "results.B01.charge_kg",
32
+ "type": "number",
33
+ "value": 538.0,
34
+ "abs_tol": 0.01,
35
+ "weight": 1.0
36
+ },
37
+ {
38
+ "path": "results.B01.high_kg",
39
+ "type": "number",
40
+ "value": 196.83,
41
+ "abs_tol": 0.01,
42
+ "weight": 1.0
43
+ },
44
+ {
45
+ "path": "results.B01.low_kg",
46
+ "type": "number",
47
+ "value": 341.17,
48
+ "abs_tol": 0.01,
49
+ "weight": 1.0
50
+ },
51
+ {
52
+ "path": "results.B01.retained_component_kg",
53
+ "type": "number",
54
+ "value": 129.12,
55
+ "abs_tol": 0.01,
56
+ "weight": 1.0
57
+ }
58
+ ]
tasks/food-batch/food-batch-blending-d1-t0000/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/food-batch/food-batch-blending-d1-t0000/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/food-batch/food-batch-blending-d1-t0009/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/food-batch/food-batch-blending-d1-t0009/environment/workdir/blends.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status
2
+ B00,1001,kg,6,43,15,0,approved
3
+ B01,363,kg,4,50,25,0,approved
tasks/food-batch/food-batch-blending-d1-t0009/instruction.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Food Batch: blending
2
+
3
+ `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.
4
+
5
+ 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.
tasks/food-batch/food-batch-blending-d1-t0009/solution/oracle.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Independent mass balances from the supplied production records."""
2
+ import csv,json
3
+ from pathlib import Path
4
+
5
+ def read(name):
6
+ with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved']
7
+
8
+ def solve():
9
+ out={}
10
+ if Path('drying.csv').exists():
11
+ for row in read('drying.csv'):
12
+ mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1)
13
+ 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
14
+ out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water)
15
+ primary='product_kg'
16
+ elif Path('blends.csv').exists():
17
+ for row in read('blends.csv'):
18
+ 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
19
+ # Solve the component balance for the low ingredient first.
20
+ charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a
21
+ out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target)
22
+ primary='charge_kg'
23
+ else:
24
+ rows=read('recipes.csv')
25
+ for key in sorted({r['recipe_id'] for r in rows}):
26
+ 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)
27
+ for row in rs:
28
+ 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)
29
+ out[key]=values
30
+ primary='cost_crn'
31
+ return dict(results=out,total_primary=sum(x[primary] for x in out.values()))
32
+
33
+ if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
tasks/food-batch/food-batch-blending-d1-t0009/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py
tasks/food-batch/food-batch-blending-d1-t0009/task.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version = "1.0"
2
+
3
+ [metadata]
4
+ author_name = "Renaissance Labs"
5
+ author_email = "unknown"
6
+ difficulty = "easy"
7
+ category = "food-batch"
8
+ tags = ["food-batch", "blending", "isced-0721", "train"]
9
+ isced_f = "0721"
10
+ family = "blending"
11
+ split = "train"
12
+ seed = 9
13
+
14
+ [verifier]
15
+ timeout_sec = 120.0
16
+
17
+ [agent]
18
+ timeout_sec = 900.0
19
+
20
+ [environment]
21
+ build_timeout_sec = 600.0
22
+ cpus = 1
23
+ memory_mb = 1024
24
+ storage_mb = 2048
25
+ allow_internet = false
tasks/food-batch/food-batch-blending-d1-t0009/tests/checks.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "path": "results.B00.charge_kg",
4
+ "type": "number",
5
+ "value": 1001.0,
6
+ "abs_tol": 0.01,
7
+ "weight": 1.0
8
+ },
9
+ {
10
+ "path": "results.B00.high_kg",
11
+ "type": "number",
12
+ "value": 243.49,
13
+ "abs_tol": 0.01,
14
+ "weight": 1.0
15
+ },
16
+ {
17
+ "path": "results.B00.low_kg",
18
+ "type": "number",
19
+ "value": 757.51,
20
+ "abs_tol": 0.01,
21
+ "weight": 1.0
22
+ },
23
+ {
24
+ "path": "results.B00.retained_component_kg",
25
+ "type": "number",
26
+ "value": 150.15,
27
+ "abs_tol": 0.01,
28
+ "weight": 1.0
29
+ },
30
+ {
31
+ "path": "results.B01.charge_kg",
32
+ "type": "number",
33
+ "value": 363.0,
34
+ "abs_tol": 0.01,
35
+ "weight": 1.0
36
+ },
37
+ {
38
+ "path": "results.B01.high_kg",
39
+ "type": "number",
40
+ "value": 165.72,
41
+ "abs_tol": 0.01,
42
+ "weight": 1.0
43
+ },
44
+ {
45
+ "path": "results.B01.low_kg",
46
+ "type": "number",
47
+ "value": 197.28,
48
+ "abs_tol": 0.01,
49
+ "weight": 1.0
50
+ },
51
+ {
52
+ "path": "results.B01.retained_component_kg",
53
+ "type": "number",
54
+ "value": 90.75,
55
+ "abs_tol": 0.01,
56
+ "weight": 1.0
57
+ }
58
+ ]
tasks/food-batch/food-batch-blending-d1-t0009/tests/test.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
tasks/food-batch/food-batch-blending-d1-t0009/tests/verify.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Verifier for Renaissance Labs practice environments. Standard library only.
3
+
4
+ Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
5
+ The reward is the weighted share of checks that pass. A missing, unreadable or non-object
6
+ answer scores 0. Each check addresses one value in the answer by a dotted path.
7
+
8
+ Check types
9
+ int exact integer (a float with integral value is accepted; booleans are not)
10
+ number within abs_tol of value (default 1e-9); booleans and strings are rejected
11
+ str equal after trimming and case-folding
12
+ bool exact boolean
13
+ list ordered list; items compared as int/number/str according to "item" (default str)
14
+ set unordered collection of distinct strings (or ints)
15
+ custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
16
+ """
17
+ import argparse, json, math, os, sys
18
+
19
+ MISSING = object()
20
+
21
+ def lookup(obj, path):
22
+ cur = obj
23
+ for part in path.split("."):
24
+ if isinstance(cur, dict):
25
+ if part not in cur: return MISSING
26
+ cur = cur[part]
27
+ elif isinstance(cur, list):
28
+ try: cur = cur[int(part)]
29
+ except (ValueError, IndexError): return MISSING
30
+ else:
31
+ return MISSING
32
+ return cur
33
+
34
+ def is_num(x):
35
+ return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
36
+
37
+ def eq_int(got, want):
38
+ return is_num(got) and float(got) == float(int(got)) and int(got) == want
39
+
40
+ def eq_num(got, want, tol):
41
+ return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
42
+
43
+ def eq_str(got, want):
44
+ return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
45
+
46
+ def eq_item(got, want, kind, tol):
47
+ if kind == "int": return eq_int(got, want)
48
+ if kind == "number": return eq_num(got, want, tol)
49
+ return eq_str(got, want)
50
+
51
+ def run_check(answer, chk, validators):
52
+ t = chk["type"]
53
+ if t == "custom":
54
+ fn = getattr(validators, chk["name"], None) if validators else None
55
+ if fn is None: return 0.0
56
+ try: r = fn(answer, chk.get("args", {}))
57
+ except Exception: return 0.0
58
+ if r is True: return 1.0
59
+ if r is False or r is None: return 0.0
60
+ return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
61
+ got = lookup(answer, chk["path"])
62
+ if got is MISSING: return 0.0
63
+ want, tol = chk["value"], chk.get("abs_tol", 1e-9)
64
+ if t == "int": ok = eq_int(got, want)
65
+ elif t == "number": ok = eq_num(got, want, tol)
66
+ elif t == "str": ok = eq_str(got, want)
67
+ elif t == "bool": ok = isinstance(got, bool) and got is want
68
+ elif t == "list":
69
+ ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
70
+ elif t == "set":
71
+ kind = chk.get("item", "str")
72
+ if not isinstance(got, list): ok = False
73
+ else:
74
+ norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
75
+ g = [norm(x) for x in got]; w = [norm(x) for x in want]
76
+ ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
77
+ else: ok = False
78
+ return 1.0 if ok else 0.0
79
+
80
+ def grade(answer, checks, validators=None):
81
+ """Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
82
+ if not isinstance(answer, dict):
83
+ return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
84
+ total = sum(c.get("weight", 1.0) for c in checks)
85
+ got, details = 0.0, []
86
+ for c in checks:
87
+ s = run_check(answer, c, validators)
88
+ got += s * c.get("weight", 1.0)
89
+ details.append({"check": c.get("path", c.get("name")), "score": s})
90
+ return (round(got / total, 6) if total else 0.0), details
91
+
92
+ def main():
93
+ ap = argparse.ArgumentParser()
94
+ ap.add_argument("--answer", default="/app/answer.json")
95
+ ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
96
+ ap.add_argument("--out", default="/logs/verifier")
97
+ a = ap.parse_args()
98
+ checks = json.load(open(a.checks))
99
+ try:
100
+ with open(a.answer) as f: answer = json.load(f)
101
+ except Exception:
102
+ answer = None
103
+ validators = None
104
+ here = os.path.dirname(os.path.abspath(__file__))
105
+ if os.path.exists(os.path.join(here, "validators.py")):
106
+ sys.path.insert(0, here)
107
+ import validators # noqa
108
+ reward, details = grade(answer, checks, validators)
109
+ os.makedirs(a.out, exist_ok=True)
110
+ with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
111
+ with open(os.path.join(a.out, "reward.json"), "w") as f:
112
+ json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
113
+ print("reward", reward)
114
+
115
+ if __name__ == "__main__":
116
+ main()
tasks/food-batch/food-batch-blending-d1-t0018/environment/Dockerfile ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /app
3
+ COPY workdir/ /app/
tasks/food-batch/food-batch-blending-d1-t0018/environment/workdir/blends.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ batch_id,finished_mass,mass_unit,low_percent,high_percent,target_percent,uniform_process_loss_percent,status
2
+ B00,277,kg,10,31,23,0,approved
3
+ B01,946,kg,6,38,21,0,approved
tasks/food-batch/food-batch-blending-d1-t0018/instruction.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Food Batch: blending
2
+
3
+ `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.
4
+
5
+ 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.
tasks/food-batch/food-batch-blending-d1-t0018/solution/oracle.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Independent mass balances from the supplied production records."""
2
+ import csv,json
3
+ from pathlib import Path
4
+
5
+ def read(name):
6
+ with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='approved']
7
+
8
+ def solve():
9
+ out={}
10
+ if Path('drying.csv').exists():
11
+ for row in read('drying.csv'):
12
+ mass=float(row['input_mass'])*(1000 if row['mass_unit']=='tonne' else .001 if row['mass_unit']=='g' else 1)
13
+ 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
14
+ out[row['batch_id']]=dict(initial_dry_kg=dry,retained_dry_kg=retained,product_kg=retained+final_water,water_removed_kg=water-final_water)
15
+ primary='product_kg'
16
+ elif Path('blends.csv').exists():
17
+ for row in read('blends.csv'):
18
+ 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
19
+ # Solve the component balance for the low ingredient first.
20
+ charge=total/retain; a=(high*charge-target*charge)/(high-low); b=charge-a
21
+ out[row['batch_id']]=dict(charge_kg=charge,low_kg=a,high_kg=b,retained_component_kg=total*target)
22
+ primary='charge_kg'
23
+ else:
24
+ rows=read('recipes.csv')
25
+ for key in sorted({r['recipe_id'] for r in rows}):
26
+ 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)
27
+ for row in rs:
28
+ 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)
29
+ out[key]=values
30
+ primary='cost_crn'
31
+ return dict(results=out,total_primary=sum(x[primary] for x in out.values()))
32
+
33
+ if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
tasks/food-batch/food-batch-blending-d1-t0018/solution/solve.sh ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ cd /app
4
+ python3 /solution/oracle.py