diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..e853a5943ed74a50a30cbe1c4831859c331aadf3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,61,1.27,m,140,100,accepted,grey +F01,58,1.48,m,301,100,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7bc600979236f717def6f83e174b3ba00e546d45 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b4e1315dc87cceb90cb35fdf7147ad2474bf8a63 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 77.47, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 10.846, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 77.47, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 10.846, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 85.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 25.838, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 85.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 25.838, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..d74e08bdc5fab6359e40205911897a346ba5fdfa --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,329,1.58,m,241,100,accepted,navy +F01,80,1.35,m,186,100,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b3bb6c4b1749f436181085598d7d552356973e96 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1062c04a3295877986f66a0f612be34d5d619468 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 519.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 125.277, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 519.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 125.277, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 108.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 20.088, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 108.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 20.088, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..09a6209828805ee94e16f3ebb11eb16ccb7bda76 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,343,2.05,m,332,100,accepted,cream +F01,306,2.12,m,106,100,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..becd3a99aa2ef49b3a4abeeaebf1d37447042cb1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1f05c312530237620f259193f4dd2c6d883328ea --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 703.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 233.446, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 703.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 233.446, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 648.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 68.764, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 648.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 68.764, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..9d2ee900377039a54c7a83f482221dda61a2b380 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,329,1.38,m,343,100,accepted,grey +F01,143,1.9,m,248,100,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..76f09a9c6ece070c144f92f79d70846aa6afa592 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d984ed335f84670076e8dfea5a72045a79420a11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 454.02, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 155.729, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 454.02, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 155.729, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 271.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 67.382, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 271.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 67.382, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..00c6defaab0be79ea637c7332fb52cc8a6f025b6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,57,1.53,m,290,100,accepted,grey +F01,104,1.78,m,280,100,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0d2be32bdeadc9bfcc8bcf6475727d403ef46e3b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1c4b8518d8a0f596ff272d572599a7b785dd512f --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 87.21, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 25.291, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 87.21, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 25.291, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 185.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 51.834, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 185.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 51.834, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..64a9c4e34d85454b124ac2ee4320424ab3274e14 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,248,1.87,m,198,100,accepted,cream +F01,126,2.15,m,172,100,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2396fd5fdc6ef2548bf3bf3434ffb5feb298cec0 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0018/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..36ec4b65d98819ff2791e51a24dce0e2ce4715e9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 463.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 91.824, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 463.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 91.824, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 270.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 46.595, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 270.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 46.595, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0018/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0027/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..5f0b33295baf91bc6629239a81f567f539473f15 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,236,1.57,m,341,100,accepted,grey +F01,384,2.1,m,344,100,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7a8752880f935ece177aa24704a264c07b8b8b71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0027/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6faf4d8fdc40843e0d321c9e114bdd05aae59b7a --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 370.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 126.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 370.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 126.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 806.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 277.402, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 806.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 277.402, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0027/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0027/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0036/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..dc188eabc2f4a30d3aa27c1787eeed43cb0b0e5b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,192,1.53,m,118,100,accepted,navy +F01,131,1.77,m,347,100,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..316882f7179ced38eac2b8ab6d518197a910a834 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0036/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..2f9336cca60b27f4dd812975eecebab1b4f36fca --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 293.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 34.664, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 293.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 34.664, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 231.87, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 80.459, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 231.87, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 80.459, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0036/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0036/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0045/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..d5673b258d307e0c062f2de76b24a9ff146462a8 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,171,2.06,m,218,100,accepted,grey +F01,294,2.03,m,331,100,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..84c7cb48906871a1cbfd06fa704c2b6341c7482f --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0045/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..23286ad5f0e7fd75b2cd8f65aa2d3b340f6bd4d3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 352.26, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 76.793, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 352.26, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 76.793, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 596.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 197.547, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 596.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 197.547, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0045/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0045/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0054/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..201559e25ace4f6e220a6fef511e1d4904df364c --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,127,2.08,m,122,100,accepted,cream +F01,153,1.98,m,252,100,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..af240754a3b8dbc7fb434a2b4e3e9fb0abac9d64 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0054/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..278adfd65a7635826da9cc93ed862c16b610bf35 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 264.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 32.228, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 264.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 32.228, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 302.94, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 76.341, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 302.94, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 76.341, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0054/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0054/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0063/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..34bc4f32c04a1dd94649a01f7d7d4dd8b9eab9d7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,114,1.63,m,315,100,accepted,grey +F01,106,1.92,m,313,100,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6393f3777d19112c6e653f3b95a174664a8c8d5e --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0063/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..dec74f578f6dbcc0cc946cab1849b4f275b910c6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 185.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 58.533, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 185.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 58.533, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 203.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 63.702, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 203.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 63.702, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0063/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0063/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0072/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..712df3d9cf82c1a0d1697b7accd7d6d789136b78 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,180,1.52,m,293,100,accepted,cream +F01,92,1.87,m,153,100,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f29884db51eac24f7f9d354239811c073b6b6843 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0072/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ee8be732e1357508eb9ac0fc4b0b50f6c885e63c --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 273.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 80.165, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 273.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 80.165, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 172.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 26.322, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 172.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 26.322, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0072/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0072/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0081/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..915d8bc21bc59dfdd08abbba52f7ad3eb5a5b534 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/environment/workdir/rolls.csv @@ -0,0 +1,3 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,77,1.82,m,167,100,accepted,grey +F01,188,1.78,m,138,100,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..14729c56061e67773c7046ffee3e3644a1f43391 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d1-t0081/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a9d58f675ce95b37dc684eb58ab3c9f06c317888 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/tests/checks.json @@ -0,0 +1,58 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 140.14, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 23.403, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 140.14, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 23.403, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 334.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 46.18, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 334.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 46.18, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d1-t0081/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d1-t0081/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-e0003/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..2db889070836426378d5053dd4a3abcaa8286d34 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F01,82,1.28,m,329,95,accepted,grey +F00,272,1.23,m,135,95,accepted,grey +REJECT,9999,1.23,m,135,95,rejected,grey +F02,255,1.2,m,319,85,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d73c0cf5692b520c327c3760a0ef6e60d8964de4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-e0003/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..52543abab6478b9fc1ab3476d25256c8dbdf6f02 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 334.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 45.166, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 317.832, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 42.907, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 104.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 34.532, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 99.712, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 32.805, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 306.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 97.614, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 260.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 82.972, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-e0003/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-e0012/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..1639e0f0b91b401a07a0d61ca180ea240d9f6a69 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F01,357,1.27,m,266,90,accepted,navy +REJECT,9999,2.13,m,283,95,rejected,cream +F02,223,1.67,m,227,98,accepted,cream +F00,186,2.13,m,283,95,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d32eddbe4bf19881107f1bca88b5a94a7a1df84a --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-e0012/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..8de51078fb02973a75cf04fa44aed64f9934be89 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 396.18, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 112.119, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 376.371, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 106.513, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 453.39, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 120.602, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 408.051, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 108.542, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 372.41, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 84.537, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 364.962, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 82.846, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-e0012/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-e0021/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..4761d9d04f21ef48463454a34d56a18924f5132e --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F02,328,2.03,m,169,85,accepted,grey +F00,97,1.97,m,173,95,accepted,cream +F01,230,1.26,m,246,85,accepted,grey +REJECT,9999,1.97,m,173,95,rejected,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0e0945929021ef38588986fad2039459b4cbca91 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-e0021/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..188add4bda7431ae3eeb9d7bce2f3f4f11da406f --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 191.09, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 33.059, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 181.535, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 31.406, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 289.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 71.291, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 246.33, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 60.597, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 665.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 112.527, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 565.964, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 95.648, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-e0021/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-e0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0003/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..b4d93ec5c30d02003846885c59b8002fb0c835a3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,346,1.95,m,227,95,accepted,grey +F01,275,2.05,m,302,85,accepted,grey +REJECT,9999,1.95,m,227,95,rejected,grey +F02,378,1.64,m,257,95,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d23e4a6ce12434e1c5030d5b7b18d6ceb503ec89 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0003/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c8f3ff9c23199594718702783d2f83f0ee862099 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 674.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 153.157, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 640.965, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 145.499, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 563.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 170.252, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 479.188, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 144.715, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 619.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 159.319, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 588.924, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 151.353, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0003/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0003/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0012/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..d085fb0a2ca875c10905890d25fa37fd37e630d6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +REJECT,9999,1.56,m,133,98,rejected,grey +F00,227,1.56,m,133,98,accepted,grey +F01,375,1.73,m,128,95,accepted,grey +F02,312,1.58,m,147,90,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c98fddb552f5635f1a2cd40e664b6fff3c16fe01 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0012/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..fafe954c379f7d2fa15ea2c8e5f2342798a437a7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 354.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 47.098, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 347.038, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 46.156, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 648.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 83.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 616.312, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 78.888, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 492.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 72.465, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 443.664, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 65.219, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0012/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0012/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0021/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..2567b506a87248c15d04eefd9b90e9a7e65d4265 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +REJECT,9999,1.56,m,175,98,rejected,cream +F01,73,1.58,m,245,85,accepted,grey +F02,399,2.16,m,214,95,accepted,grey +F00,262,1.56,m,175,98,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c92931f2c373399604df5dbb3e7aeb0fcb044ac4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0021/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..82e610f41fb0c8f101fcf72dd738e413692b0860 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 408.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 71.526, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 400.546, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 70.095, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 115.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 28.258, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 98.039, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 24.02, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 861.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 184.434, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 818.748, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 175.212, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0021/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0021/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0030/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..da46d5cfbc9b384a86e18ee8635928c8de65de5b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +REJECT,9999,1.57,m,212,95,rejected,navy +F00,308,1.57,m,212,95,accepted,navy +F01,242,2.07,m,278,90,accepted,grey +F02,102,2.01,m,219,98,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..037b0a94fc54a64128abbae812661504fbd28b38 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0030/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..eba321e61f4580b7d928a7d7b55d9c385749019d --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 483.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 102.515, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 459.382, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 97.389, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 500.94, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 139.261, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 450.846, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 125.335, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 205.02, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 44.899, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 200.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 44.001, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0030/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0030/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0039/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..45e8955c6f7b3f74879dca618cec462e3b18fbd3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F01,328,1.37,m,183,85,accepted,grey +REJECT,9999,2.15,m,156,98,rejected,cream +F00,82,2.15,m,156,98,accepted,cream +F02,260,2.0,m,231,95,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..59049820510d3f2ce45d2e94de72ed212fa97a27 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0039/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4d3c131c40c25636279443798b0f4f3d5a139be4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 176.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 27.503, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 172.774, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 26.953, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 449.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 82.233, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 381.956, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 69.898, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 520.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 120.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 494.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 114.114, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0039/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0039/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0048/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..d4739e518d75e83f6bae4a62fe54250cb9459bca --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F02,390,2.18,m,321,98,accepted,navy +F00,369,1.45,m,336,95,accepted,grey +F01,263,2.0,m,146,85,accepted,cream +REJECT,9999,1.45,m,336,95,rejected,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c41184a14ce2968a6122b8aa81e9e155853b996b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0048/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d5919e7135da8c95ec510536c8254001e849cbf5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 535.05, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 179.777, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 508.297, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 170.788, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 526.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 76.796, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 447.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 65.277, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 850.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 272.914, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 833.196, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 267.456, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0048/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0048/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0057/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..dafbe5ebbed3a474306caa379b418d078d59ac45 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F02,91,2.13,m,316,90,accepted,navy +F00,383,1.48,m,183,98,accepted,grey +REJECT,9999,1.48,m,183,98,rejected,grey +F01,50,1.77,m,193,85,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b9ffc7ff3719c0d49d95e8a3b7c2b62501855ae9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0057/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6e8063a1961d539ac039b92a32e9665136da6e78 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 566.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 103.732, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 555.503, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 101.657, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 88.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 17.081, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 75.225, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 14.518, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 193.83, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 61.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 174.447, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 55.125, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0057/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0057/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0066/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..ca46a37f03acad0d89507898af3f1356b898dabb --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F01,280,2.18,m,331,95,accepted,grey +REJECT,9999,1.2,m,232,85,rejected,cream +F00,310,1.2,m,232,85,accepted,cream +F02,289,2.0,m,235,90,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..99e47086ccbe6d0ecc7f418a22af5e62a44067eb --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0066/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7392586842f09ecadeaccd5192db65e34e2629a5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 372.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 86.304, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 316.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 73.358, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 610.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 202.042, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 579.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 191.94, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 578.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 135.83, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 520.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 122.247, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0066/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0066/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0075/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..0b73b4c33839e22235e52bf9c8e16525200d7634 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/environment/workdir/rolls.csv @@ -0,0 +1,5 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +REJECT,9999,1.9,m,241,85,rejected,navy +F02,282,1.4,m,225,95,accepted,grey +F01,185,1.78,m,102,90,accepted,navy +F00,391,1.9,m,241,85,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..98cd287d16800ad6ddbcb60698f1a7f526aa0042 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..66711118d62d68589646282602e78790ba27fffa --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d2-t0075/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..62dbfec852fe5c98c011981bd6682b2261a9165c --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/tests/checks.json @@ -0,0 +1,86 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 742.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 179.039, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 631.465, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 152.183, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 329.3, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 33.589, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 296.37, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 30.23, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 394.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 88.83, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 375.06, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 84.388, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d2-t0075/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d2-t0075/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-e0006/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..a02f579eed0d579159675033383abe7af9ae7b71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +REJECT,9999,1.64,m,291,85,rejected,navy +F03,347,191.0,cm,142,85,accepted,grey +F01,284,213.0,cm,292,85,accepted,grey +F00,207,1.64,m,291,85,accepted,navy +F02,301,1.27,m,324,98,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..059405d303508f55e78d98bfa0f447fe51946a0f --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-e0006/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..eb2e7f38eec73562643ac5e253b5960137325e96 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 339.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 98.789, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 288.558, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 83.97, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 604.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 176.637, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 514.182, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 150.141, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 382.27, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 123.855, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 374.625, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 121.378, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 662.77, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 94.113, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 563.354, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 79.996, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 435.486, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-e0006/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-e0015/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..716d4d7ac41cae2af49f50189205a9c0b24bff9e --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F03,148,215.0,cm,269,95,accepted,navy +F01,335,149.0,cm,157,85,accepted,grey +REJECT,9999,1.83,m,335,95,rejected,grey +F00,135,1.83,m,335,95,accepted,grey +F02,181,2.11,m,186,95,accepted,navy diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8247a5400c41e9f85e936eef16e1c62341dc5cd5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-e0015/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..22314b622ae9965a9ad20aea8469e6d63aac7bb4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 247.05, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 82.762, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 234.697, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 78.624, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 499.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 78.367, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 424.277, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 66.612, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 381.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 71.035, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 362.814, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 67.483, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 318.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 85.596, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 302.29, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 81.316, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 294.035, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-e0015/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-e0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0006/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..309a76662034d04284c179851af4780300cf8314 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F01,276,189.0,cm,273,98,accepted,cream +F00,117,1.24,m,167,98,accepted,navy +F02,283,1.41,m,287,95,accepted,navy +REJECT,9999,1.24,m,167,98,rejected,navy +F03,79,183.0,cm,256,98,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bf9805bb2fee6ec53bd8b30f5be466c3e5d0a4eb --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0006/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c06c94297f17481698fff98d9c1433514960a0db --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 145.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 24.228, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 142.178, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 23.744, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 521.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 142.408, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 511.207, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 139.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 399.03, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 114.522, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 379.078, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 108.796, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 144.57, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 37.01, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 141.679, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 36.27, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 308.369, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0006/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0006/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0015/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..5df960c32c5d550b1933d2dac7d4ce98a06ef92f --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F02,350,1.2,m,210,90,accepted,navy +REJECT,9999,1.74,m,343,85,rejected,grey +F03,204,206.99999999999997,cm,231,98,accepted,cream +F00,189,1.74,m,343,85,accepted,grey +F01,337,198.0,cm,225,90,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9ff3b60c6aa4ec4874223373b5220cf76766e17a --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0015/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bc816e0b9b0ea309132e3b63121916c903831a92 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 328.86, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 112.799, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 279.531, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 95.879, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 667.26, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 150.133, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 600.534, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 135.12, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 420.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 88.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 378.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 79.38, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 422.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 97.547, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 413.834, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 95.596, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 405.975, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0015/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0015/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0024/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..751d6833e761db558749ac634d44112bcaa9ee44 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +REJECT,9999,1.34,m,340,85,rejected,grey +F03,312,145.0,cm,245,90,accepted,grey +F00,176,1.34,m,340,85,accepted,grey +F01,322,129.0,cm,130,98,accepted,navy +F02,273,2.05,m,160,85,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..960ce7f3cd88888ee73c1388e355042a99adae24 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0024/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bd2646bf53fe6e554592fd1d90024f7221274127 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 235.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 80.186, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 200.464, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 68.158, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 415.38, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 53.999, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 407.072, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 52.919, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 559.65, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 89.544, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 475.702, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 76.112, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 452.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 110.838, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 407.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 99.754, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 296.944, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0024/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0024/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0033/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..e057de45fc1f92918d67faa1aae7615f9554b018 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F03,226,140.0,cm,220,98,accepted,cream +F00,265,1.4,m,199,95,accepted,grey +F01,333,192.0,cm,202,95,accepted,grey +F02,192,1.2,m,274,90,accepted,grey +REJECT,9999,1.4,m,199,95,rejected,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e9ffbe344d8b1b022d6b89f59f6472e3c1f3dad8 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0033/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..378247f1f66f14946cd365178c9c4c05205b149e --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 371.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 73.829, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 352.45, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 70.138, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 639.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 129.151, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 607.392, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 122.693, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 230.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 63.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 207.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 56.817, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 316.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 69.608, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 310.072, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 68.216, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 317.863, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0033/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0033/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0042/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..4dbf4c901f3e086f3e478ef07f8481877326f567 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +REJECT,9999,1.21,m,173,95,rejected,grey +F03,125,199.0,cm,221,98,accepted,navy +F02,245,1.52,m,110,90,accepted,grey +F01,168,158.0,cm,339,90,accepted,navy +F00,307,1.21,m,173,95,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f7675670604d3a83fd85efcdfa6580cedda20d5a --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0042/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e356e6429ff78ea99af62de0133fb0655531fecd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 371.47, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 64.264, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 352.896, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 61.051, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 265.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 89.984, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 238.896, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 80.986, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 372.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 40.964, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 335.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 36.868, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 248.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 54.974, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 243.775, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 53.874, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 232.779, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0042/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0042/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0051/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..ad3bf78d0f5aba90f9cf40104b72d020908357d4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F02,290,1.48,m,224,95,accepted,cream +REJECT,9999,1.99,m,312,95,rejected,navy +F00,278,1.99,m,312,95,accepted,navy +F03,166,206.0,cm,174,98,accepted,navy +F01,87,219.0,cm,114,98,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..95b686f0375ceb1e6f4f33e57a868f4b62f0b459 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0051/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..fd913ddd3a32709c3189083161b9ae1bfcfe77de --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 553.22, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 172.605, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 525.559, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 163.974, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 190.53, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 21.72, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 186.719, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 21.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 429.2, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 96.141, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 407.74, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 91.334, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 341.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 59.501, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 335.121, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 58.311, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 334.905, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0051/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0051/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0060/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..dc3332894d2303b03f8a760268038059a50ed81c --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F02,344,1.69,m,126,95,accepted,grey +REJECT,9999,1.88,m,248,95,rejected,grey +F00,66,1.88,m,248,95,accepted,grey +F01,310,164.0,cm,252,90,accepted,cream +F03,273,180.0,cm,303,98,accepted,grey diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a7904653a5031e79a4f03d199501d218b36d5a76 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0060/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..515496ff07cb6c68e1be0c0d646e6de2fd8e535e --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 124.08, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 30.772, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 117.876, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 29.233, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 508.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 128.117, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 457.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 115.305, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 581.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 73.251, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 552.292, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 69.589, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 491.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 148.894, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 481.572, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 145.916, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 360.043, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0060/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0060/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0069/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..9878613d3b42c7a2d0d43b4ab54196eca76b9257 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F00,299,1.21,m,156,85,accepted,cream +F02,153,1.56,m,201,85,accepted,navy +F01,194,150.0,cm,239,90,accepted,navy +F03,216,156.0,cm,338,95,accepted,grey +REJECT,9999,1.21,m,156,85,rejected,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7e2dbdb76dc8ce00fd1c22593c9d4d451c51eaa1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0069/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e76ab996ffa6eef6889f54c08dda8b328ae7eef9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 361.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 56.439, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 307.522, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 47.973, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 291.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 69.549, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 261.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 62.594, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 238.68, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 47.975, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 202.878, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 40.778, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 336.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 113.892, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 320.112, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 108.198, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 259.544, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0069/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0069/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0078/environment/Dockerfile b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/environment/workdir/rolls.csv b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/environment/workdir/rolls.csv new file mode 100644 index 0000000000000000000000000000000000000000..49e1493aa5b179b71b0ec6a42d5495b7314117ff --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/environment/workdir/rolls.csv @@ -0,0 +1,6 @@ +roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour +F01,122,209.0,cm,337,95,accepted,navy +REJECT,9999,1.99,m,286,90,rejected,grey +F00,55,1.99,m,286,90,accepted,grey +F03,144,209.0,cm,316,98,accepted,navy +F02,258,1.83,m,115,98,accepted,cream diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/instruction.md b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..225e1bcaf9430f9ecbfe71e83c6324c8f57a398b --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: fabric-mass + +`rolls.csv` gives fabric lengths, widths and areal mass in grams per square metre (`gsm`). Assume uniform GSM across the entire roll. For each `roll_id` return `gross_area_m2` = length*width, `gross_mass_kg` = area*gsm/1000, and `usable_area_m2` and `usable_mass_kg` = gross values*usable_percent/100. The usable percentage is a measured quality yield, not a width adjustment. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `usable_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/solution/oracle.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/solution/solve.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/task.toml b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..42d8f6598d2a6c5defa8347eefac28c367a9c198 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "fabric-mass", "isced-0723", "train"] +isced_f = "0723" +family = "fabric-mass" +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/textile-lab/textile-lab-fabric-mass-d3-t0078/tests/checks.json b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..85698475b0fc48187438b45223d4de0a5d6defcc --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/tests/checks.json @@ -0,0 +1,121 @@ +[ + { + "path": "results.F00.gross_area_m2", + "type": "number", + "value": 109.45, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.gross_mass_kg", + "type": "number", + "value": 31.303, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_area_m2", + "type": "number", + "value": 98.505, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F00.usable_mass_kg", + "type": "number", + "value": 28.172, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_area_m2", + "type": "number", + "value": 254.98, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.gross_mass_kg", + "type": "number", + "value": 85.928, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_area_m2", + "type": "number", + "value": 242.231, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F01.usable_mass_kg", + "type": "number", + "value": 81.632, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_area_m2", + "type": "number", + "value": 472.14, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.gross_mass_kg", + "type": "number", + "value": 54.296, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_area_m2", + "type": "number", + "value": 462.697, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F02.usable_mass_kg", + "type": "number", + "value": 53.21, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_area_m2", + "type": "number", + "value": 300.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.gross_mass_kg", + "type": "number", + "value": 95.103, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_area_m2", + "type": "number", + "value": 294.941, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.F03.usable_mass_kg", + "type": "number", + "value": 93.201, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 256.216, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/tests/test.sh b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-fabric-mass-d3-t0078/tests/verify.py b/tasks/textile-lab/textile-lab-fabric-mass-d3-t0078/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-fabric-mass-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/textile-lab/textile-lab-shrinkage-d1-e0001/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..59eb9bc13848ad190e5c9487ed89f1b573e86a70 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,8.6,1.7,m,11,11,206,accepted +P01,6.5,2.4,m,10,10,244,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2cbeadd8289e3d00c5fc6459d7aee753e570146e --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-e0001/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cf23791f43c1f63af1ecaa63ff1ed3ad4d8a0af5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 9.663, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 18.457, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 20.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 260.068, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 7.222, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 19.259, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 19.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 301.235, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-e0001/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-e0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-e0010/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..c946a2ad5ea20abc22224af6ee10a29f5c70e5fe --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,3.3,2.3,m,7,7,159,accepted +P01,8.2,1.4,m,2,2,184,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1c5798037e466fefba1dbfd7eb394f18ecac0023 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-e0010/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..928358131e09747f1c1a84d6c7f057f71699d030 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 3.548, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.473, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 8.776, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 13.51, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 183.836, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 8.367, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 11.953, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 3.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 191.587, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-e0010/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-e0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-e0019/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..61cb343d97d7296b0c3dcaaaa5b3bc016ec8a352 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,4.3,1.6,m,3,3,189,accepted +P01,5.5,2.3,m,6,6,120,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e911b8c7260d54e8cf62c6d11637b6430544b65c --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-e0019/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1ff5696bc5755ff47464627c46092b958adf90b5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 4.433, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.649, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 7.312, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 5.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 200.872, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 5.851, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.447, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 14.316, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 11.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 135.808, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-e0019/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-e0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0001/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..bb4455d8dc1614a083f020f49a1d703758b2aae7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,8.2,1.0,m,4,4,253,accepted +P01,3.6,2.1,m,11,11,223,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0d748687b03162018d9bb878eb15b7b02c47b2e1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0001/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6a4897b55bbd09c6963e9896bcc0a8f4d60215ee --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.542, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.042, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 8.898, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 7.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 274.523, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 4.045, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 9.544, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 20.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 281.53, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0001/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0001/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0010/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..a05d3421241508ebd8efd2db32b1ce4b52ca699a --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,7.6,1.3,m,12,12,256,accepted +P01,7.9,1.0,m,8,8,272,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..216e055fed782701c4b8989c4bd5a28fbce6c96d --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0010/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..97eb71b5f2a6e4d74dda250796dfc3d70296f058 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.636, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.477, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 12.758, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 22.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 330.579, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 8.587, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.087, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 9.334, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 15.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 321.361, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0010/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0010/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0019/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..8866bb77b0b9dfbd4d26e1182f197da6e78e0857 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,3.6,2.3,m,3,3,136,accepted +P01,8.7,1.6,m,11,11,200,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..37737010aa233c37ccae687bc61466986f890fbb --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0019/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c462a01b922207cff5bedac8c2cd21f46c63cc4e --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 3.711, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.371, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 8.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 5.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 144.542, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 9.775, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.798, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 17.574, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 20.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 252.493, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0019/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0019/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0028/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..9ae84b5fb8978759e26fe06cd898daccb9e8e0c0 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,4.2,2.0,m,8,8,281,accepted +P01,8.5,1.2,m,5,5,145,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3b6986585915d7012010720eed4d5f2de32e61b5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0028/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..bc8a79d6ffdfbd638e74444c6568f632303aaacf --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 4.565, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.174, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 9.924, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 15.36, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 331.994, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 8.947, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.263, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 11.302, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 9.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 160.665, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0028/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0028/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0037/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..ab3b4a5a41306662f3e4f94da835fbe37e51e29e --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,7.7,2.3,m,6,6,213,accepted +P01,4.8,1.6,m,9,9,189,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bcd4c79006132afc6351c6bf3277a5ea374d96d3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0037/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0962190f15624bf093f4fb24c74009cf3a400395 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.191, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.447, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 20.043, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 11.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 241.059, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 5.275, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.758, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 9.274, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 17.19, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 228.233, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0037/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0037/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0046/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..10364c3f08bb8a1a2aa494b655322b43ced5c2ef --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,8.1,1.0,m,6,6,243,accepted +P01,8.9,2.5,m,6,6,289,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5cf58ca691f15b61bafd0ff037d23b4b9370156e --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0046/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9bc3bc9738f3a7fcac0b477bcced69688c3a96af --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.617, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.064, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 9.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 11.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 275.011, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 9.468, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.66, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 25.181, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 11.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 327.071, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0046/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0046/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0055/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..caad89bbf95a1652a3d2a4a15c53155556eb94b3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,3.6,1.8,m,6,6,193,accepted +P01,5.2,2.3,m,3,3,172,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f7db0d86b1536d948e2c167363924573b852b9b4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0055/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..3b965953b4edc9e19a129b11eae9b1b5e02c9cf8 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 3.83, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.915, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 7.334, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 11.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 218.425, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 5.361, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.371, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 12.711, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 5.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 182.804, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0055/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0055/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0064/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..4e859419ad4d6026f83447cab78272d3075d0956 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,7.7,2.2,m,11,11,296,accepted +P01,2.5,2.3,m,2,2,222,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c9bc5f10c0a7c3e1e560789ae920cf0dcd3608fc --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0064/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c96c2b4c88e05bf935916f40f467cb04c9bdb0b2 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.652, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.472, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 21.386, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 20.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 373.69, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 2.551, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 5.987, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 3.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 231.154, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0064/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0064/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0073/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..34461826fa4e271c587f04c596be77b0c8b9b2e9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,4.6,1.2,m,4,4,182,accepted +P01,2.7,1.1,m,9,9,136,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..458e885446c6accec2a01b8b00ffb62aca9cadb3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0073/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7c23c081ef263249ea720340e15fdccd94e6b2f2 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 4.792, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.25, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 5.99, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 7.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 197.483, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 2.967, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.209, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 3.587, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 17.19, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 164.231, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0073/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0073/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0082/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..324ac7898383fd4d0111e8cce03e642674d6b14a --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/environment/workdir/panels.csv @@ -0,0 +1,3 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,8.8,2.0,m,4,4,126,accepted +P01,4.6,2.3,m,10,10,224,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1bfd26e0454f4971a18f6802cb50965672aba8da --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d1-t0082/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..4d10ad04cfab0c41177a4f47bcdeacd4ccc26c48 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/tests/checks.json @@ -0,0 +1,72 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 9.167, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.083, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 19.097, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 7.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 136.719, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 5.111, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.556, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 13.062, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 19.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 276.543, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d1-t0082/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d1-t0082/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-e0004/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..532e64d0c2b79dc9cb53349438f962cfd016a21c --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P02,2.6,1.0,m,11,5,193,accepted +P00,7.9,1.0,m,12,8,220,accepted +VOID,9999,1.0,m,12,8,220,cancelled +P01,3.3,1.8,m,11,10,266,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..71f37df4bb512ad845a7208efb5a1f83ec39c158 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-e0004/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..cf3ea26229c2dcfcf5c474a145c471c6272ca486 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.977, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.087, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 9.758, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 19.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 271.739, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 3.708, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 7.416, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 19.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 332.085, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 2.921, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.053, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 3.075, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 15.45, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 228.267, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-e0004/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-e0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-e0013/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..787492c48aad89b743b9b644e15e7ff1acfa977f --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,6.0,1.2,m,11,2,259,accepted +P02,3.0,2.3,m,7,3,217,accepted +VOID,9999,1.2,m,11,2,259,cancelled +P01,9.0,1.0,m,10,5,186,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9e8a80b10a9f48daacee011fc6b77eb7f11a2e00 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-e0013/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9bf4fb1b7e31c7ef1480196645860ea1ee19830b --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 6.742, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.224, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 8.255, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 12.78, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 296.95, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 10.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.053, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 10.526, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 14.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 217.544, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 3.226, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.371, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 7.649, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 9.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 240.55, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-e0013/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-e0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-e0022/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..d783228a836112aa372f6c07dd6333d1b7a5caf8 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,2.3,2.1,m,9,7,231,accepted +VOID,9999,2.1,m,9,7,231,cancelled +P02,2.9,1.0,m,5,4,248,accepted +P01,6.9,2.4,m,3,8,259,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9b9763effeb6883a912b016ae3070f9953d9f7da --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-e0022/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6eb288ea69cf73d4f05f7d9a7a6a01052cf08909 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 2.527, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.258, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 5.707, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 15.37, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 272.953, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 7.113, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.609, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 18.557, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 10.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 290.229, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 3.053, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.042, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 3.18, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 8.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 271.93, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-e0022/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-e0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0004/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..9cfd4aec34048246585f237628c75928f7bebc14 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,6.8,1.3,m,7,3,168,accepted +P02,4.9,2.1,m,9,3,135,accepted +P01,3.5,1.2,m,10,3,216,accepted +VOID,9999,1.3,m,7,3,168,cancelled diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f05a6f27e2cef8cff1f0795cef6bc121d9f6ebda --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0004/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a378479c318719bf3b0725528d978d2c5e0f6061 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 7.312, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 9.799, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 9.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 186.232, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 3.889, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.237, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 4.811, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 12.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 247.423, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 5.385, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.165, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 11.657, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 11.73, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 152.94, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0004/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0004/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0013/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..82854f0232451b240662a53f11a87d8507197c7c --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P02,5.7,1.8,m,12,7,186,accepted +P01,4.0,1.4,m,3,3,292,accepted +VOID,9999,2.3,m,9,6,219,cancelled +P00,5.2,2.3,m,9,6,219,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2df875be9276e0f9150102dd96aabf9fe623a1f4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0013/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..9be4d056f414b2f5939a0f6419bba960c2ca4981 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 5.714, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.447, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 13.982, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 14.46, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 256.021, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 4.124, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.443, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 5.952, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 5.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 310.341, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 6.477, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.935, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 12.537, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 18.16, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 227.273, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0013/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0013/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0022/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..0a3850d1ba2a035610a4f370daa1a1817ca83863 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P01,3.6,1.3,m,7,3,136,accepted +P02,8.8,2.4,m,6,3,177,accepted +VOID,9999,2.3,m,10,3,273,cancelled +P00,2.7,2.3,m,10,3,273,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c8a469ea26bf0bdd13e369e07128edda54de501e --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0022/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..dd61fa1fc05d609048fea81a2ab97ccca876957a --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 3.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.371, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 7.113, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 12.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 312.715, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 3.871, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 5.188, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 9.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 150.759, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 9.362, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.474, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 23.163, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 8.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 194.122, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0022/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0022/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0031/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..d2b9630b73ef29994373f7e931e21488b03eea66 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P01,6.1,2.4,m,11,4,224,accepted +VOID,9999,1.0,m,11,6,208,cancelled +P02,8.0,1.8,m,2,8,166,accepted +P00,6.2,1.0,m,11,6,208,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cfe08b0b3bc60280518b20462e749af7abd37d95 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0031/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6e8b572cc7ee76974f0aaa1e88786521eb3fe330 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 6.966, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.064, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 7.411, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 16.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 248.625, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 6.854, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.5, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 17.135, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 14.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 262.172, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 8.163, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.957, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 15.972, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 9.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 184.117, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0031/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0031/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0040/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..7866109e75b627eac4890b11ccfdba5aea0b803a --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +VOID,9999,2.1,m,3,5,280,cancelled +P01,6.2,2.2,m,2,6,213,accepted +P02,8.3,1.7,m,9,5,231,accepted +P00,2.2,2.1,m,3,5,280,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9db7fd293ff7fd29b771c439103bd8bcec3045d9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0040/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6054ac4b76739d6c660d8302e6889073a7462726 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 2.268, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.211, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 5.014, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 7.85, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 303.852, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 6.327, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 14.807, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 7.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 231.22, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 9.121, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.789, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 16.322, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 13.55, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 267.206, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0040/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0040/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0049/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..986ed1ec5efca0d6120a06219d4f657a6c6c988d --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P02,3.0,1.4,m,7,6,284,accepted +P01,3.7,1.6,m,7,3,256,accepted +P00,7.7,2.2,m,7,7,273,accepted +VOID,9999,2.2,m,7,7,273,cancelled diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..946be6d0960f28d61e425297109d39ee9f9dd6dd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0049/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b9dec3c28a0355a4fc1b57909751d7e2d9859e69 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.366, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 19.586, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 13.51, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 315.643, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 3.978, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.649, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 6.562, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 9.79, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 283.782, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 3.226, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.489, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 4.804, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 12.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 324.868, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0049/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0049/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0058/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..1b08bbfe7e7566bf58c785c14f2408fc5a16017d --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +VOID,9999,2.2,m,9,7,198,cancelled +P00,6.4,2.2,m,9,7,198,accepted +P02,7.9,2.3,m,4,5,124,accepted +P01,4.0,1.2,m,2,10,288,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6f19259bdf3da7b38a95aa34a33da4eab355ac47 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0058/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..35edc11d342c6e4b0987be03cb02e07bba38b966 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 7.033, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.366, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 16.637, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 15.37, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 233.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 4.082, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.333, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 5.442, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 11.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 326.531, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 8.229, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.421, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 19.923, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 8.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 135.965, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0058/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0058/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0067/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..f12837cc965f087f68b9ef896d5447f6e8493e08 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +VOID,9999,2.2,m,5,6,298,cancelled +P02,4.7,1.7,m,11,7,243,accepted +P00,4.7,2.2,m,5,6,298,accepted +P01,6.6,2.3,m,2,2,294,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..58163f359f4a60fc6464b3342bdbedae1c09d88c --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0067/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..689b4a0bbb0723640c6e77f1c4b93d9aa3c7174e --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 4.947, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 11.579, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 10.7, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 333.707, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 6.735, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 15.806, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 3.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 306.122, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 5.281, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.828, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 9.653, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 17.23, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 293.585, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0067/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0067/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0076/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..04b2442c3aa9f92f7ff0a70cc1025efb899bbc42 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/environment/workdir/panels.csv @@ -0,0 +1,5 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,5.8,1.8,m,4,9,200,accepted +P02,7.9,1.7,m,3,2,158,accepted +P01,8.2,1.2,m,5,8,126,accepted +VOID,9999,1.8,m,4,9,200,cancelled diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0e052c478c1186e5e146ac23f5069aa6ae730d11 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..882599fe07729738c7e5e599b7fc270900334cdf --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d2-t0076/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f9aa5e19f93079b66b08a64e97ede1b49e0561ea --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/tests/checks.json @@ -0,0 +1,107 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 6.042, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.978, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 11.951, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 12.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 228.938, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 8.632, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.304, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 11.259, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 12.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 144.165, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 8.144, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.735, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 14.128, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 4.94, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 166.211, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d2-t0076/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d2-t0076/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-e0007/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..fb60a696d366f1a1bc5752aadc1f81dcf65b7740 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P01,760.0,180.0,cm,4,10,129,accepted +P03,280.0,250.0,cm,9,8,202,accepted +VOID,9999,200.0,cm,11,7,252,cancelled +P00,200.0,200.0,cm,11,7,252,accepted +P02,720.0,190.0,cm,12,10,265,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cfab2e575b463ba4ab090d5fb32bf0ce43a4f14a --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-e0007/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..84bbd51ae9140fc16cff8ed06f31f5be7a398f6e --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 2.247, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.151, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 4.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 17.23, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 304.458, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 7.917, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 15.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 13.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 149.306, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 8.182, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.111, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 17.273, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 20.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 334.596, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 3.077, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 2.717, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 8.361, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 16.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 241.28, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 46.3, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-e0007/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-e0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-e0016/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..508cb4178eb5173400ef07864e6bfed6b76e5ff7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P03,630.0,200.0,cm,4,9,140,accepted +VOID,9999,140.0,cm,7,6,298,cancelled +P00,590.0,140.0,cm,7,6,298,accepted +P01,220.00000000000003,170.0,cm,7,7,261,accepted +P02,229.99999999999997,140.0,cm,5,4,189,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c8bc98b8ff75c37a8b57a0a812c3e046e6f34ecb --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "eval"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-e0016/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..773ec11ffd3c5d874d7e75b95c6d313c80e19761 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 6.344, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.489, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 9.449, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 12.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 340.883, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 2.366, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.828, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 4.324, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 13.51, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 301.769, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 2.421, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.458, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 3.531, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 8.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 207.237, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 6.562, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 2.198, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 14.423, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 12.64, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 160.256, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 31.727, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-e0016/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-e0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0007/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..e7b2094d4f6b26e0b412e78f5fbdfef326540766 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +VOID,9999,170.0,cm,10,9,197,cancelled +P00,500.0,170.0,cm,10,9,197,accepted +P02,430.0,240.0,cm,3,6,261,accepted +P01,420.0,200.0,cm,6,8,189,accepted +P03,490.00000000000006,180.0,cm,4,8,225,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8eb47cb3c16813d39cc4e561f1f689abf035ca28 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0007/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..286f7814d951b742f9ebfc701a86c251f02c961d --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 5.556, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.868, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 10.379, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 18.1, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 240.537, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 4.468, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.174, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 9.713, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 13.52, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 218.548, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 4.433, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.553, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 11.318, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 8.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 286.247, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 5.104, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 1.957, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 9.986, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 11.68, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 254.755, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 41.396, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0007/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0007/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0016/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..348b2e361984a05d10777e6f2d3e1a5d1625b906 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,210.0,140.0,cm,4,2,240,accepted +VOID,9999,140.0,cm,4,2,240,cancelled +P01,830.0000000000001,229.99999999999997,cm,5,2,226,accepted +P03,830.0000000000001,150.0,cm,3,5,292,accepted +P02,860.0,150.0,cm,5,2,253,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e91897fdab974934fa0975358045d42859cdd1b9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0016/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..834dc6d824fb63f33d8455d286e8236a6f99fc6d --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 2.188, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 3.125, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 5.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 255.102, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 8.737, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 20.505, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 6.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 242.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 9.053, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.531, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 13.856, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 6.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 271.751, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 8.557, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 1.579, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 13.511, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 7.85, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 316.875, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 50.996, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0016/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0016/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0025/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..b81ab2bd3a9fd64f016f4e10096fa5ddc20647e3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,560.0,100.0,cm,2,5,201,accepted +P01,700.0,140.0,cm,3,4,191,accepted +P02,340.0,170.0,cm,10,10,177,accepted +VOID,9999,100.0,cm,2,5,201,cancelled +P03,560.0,110.00000000000001,cm,3,8,154,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1b94ab5b7ae37b7e15248634353c9543ec5f6990 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0025/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..eb89dd5a54e5344352a338ac92b339281fd1cac9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 5.714, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.053, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 6.015, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 6.9, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 215.897, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 7.216, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.458, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 10.524, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 6.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 205.112, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 3.778, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.889, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 7.136, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 19.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 218.519, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 5.773, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 1.196, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 6.903, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 10.76, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 172.568, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 30.578, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0025/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0025/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0034/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..493a3d798aa446e2abf3ef4becd1e5009f0c1090 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P00,520.0,190.0,cm,4,8,192,accepted +P02,440.00000000000006,180.0,cm,12,8,143,accepted +VOID,9999,190.0,cm,4,8,192,cancelled +P01,630.0,210.0,cm,11,2,125,accepted +P03,550.0,110.00000000000001,cm,3,9,220,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..eaebd6d3d23117640577f44ff8cadb5a69295297 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0034/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ecf701eed27ad3ea957e0f2cd27946f3027d8dbe --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 5.417, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.065, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 11.187, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 11.68, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 217.391, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 7.079, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 15.169, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 12.78, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 143.316, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 5.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.957, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 9.783, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 19.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 176.63, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 5.67, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 1.209, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 6.854, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 11.73, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 249.235, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 42.992, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0034/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0034/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0043/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..bd7d2e04af8a626e8ffdbb5cc6d38c60ffe05799 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +VOID,9999,140.0,cm,11,4,139,cancelled +P00,850.0,140.0,cm,11,4,139,accepted +P01,409.99999999999994,160.0,cm,4,3,143,accepted +P03,780.0,250.0,cm,5,8,231,accepted +P02,630.0,200.0,cm,2,10,145,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d4a527b4ceba99768d54c58ef9e7bf661173959c --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0043/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..43a838d9d7806d87775692fb116bf2b0deb88c5c --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 9.551, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.458, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 13.928, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 14.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 162.687, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 4.271, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.649, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 7.045, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 6.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 153.565, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 6.429, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.222, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 14.286, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 11.8, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 164.399, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 8.211, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 2.717, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 22.311, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 12.6, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 264.302, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 57.57, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0043/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0043/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0052/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..232e6086bb20ee4047e5ed811383204dc9319f49 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +VOID,9999,110.00000000000001,cm,3,6,256,cancelled +P02,370.0,110.00000000000001,cm,6,2,154,accepted +P00,710.0,110.00000000000001,cm,3,6,256,accepted +P03,450.0,140.0,cm,9,5,184,accepted +P01,580.0,190.0,cm,4,2,259,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dd9575e80f1d937dacb0ee4172e399137aee0461 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0052/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..17781189ddb76f31bb8d18ee3b7d987cdace7484 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 7.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.17, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 8.565, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 8.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 280.763, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 6.042, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.939, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 11.713, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 5.92, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 275.298, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 3.936, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.122, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 4.418, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 7.88, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 167.173, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 4.945, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 1.474, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 7.287, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 13.55, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 212.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 31.985, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0052/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0052/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0061/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..8af439654ef33d6dfac04d54f4de4f481b0d0201 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P02,280.0,229.99999999999997,cm,2,2,226,accepted +P01,350.0,110.00000000000001,cm,2,7,219,accepted +VOID,9999,220.00000000000003,cm,6,7,200,cancelled +P03,520.0,150.0,cm,5,5,171,accepted +P00,240.0,220.00000000000003,cm,6,7,200,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..62f2f018df0584cc5be819a13371ffc8a955a84b --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0061/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e5223657c6a64c3a77ea2c4be1a352c3115c4baa --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 2.553, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.366, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 6.04, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 12.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 228.781, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 3.571, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.183, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 4.224, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 8.86, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 240.29, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 2.857, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 6.706, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 3.96, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 235.319, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 5.474, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 1.579, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 8.643, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 9.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 189.474, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 25.612, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0061/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0061/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0070/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..6069ca6936f14f6b214a4b39c859673ba69e19cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +VOID,9999,250.0,cm,3,3,260,cancelled +P01,590.0,229.99999999999997,cm,7,6,233,accepted +P00,710.0,250.0,cm,3,3,260,accepted +P03,280.0,140.0,cm,7,5,151,accepted +P02,490.00000000000006,160.0,cm,11,4,275,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..64804a3f84b1ab72559b2333ad9987462e6d4206 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0070/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..512de4696042d84a05ced76ecb401e9cd69cec5b --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 7.32, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 2.577, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 18.865, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 5.91, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 276.331, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 6.344, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 2.447, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 15.523, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 12.58, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 266.529, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 5.506, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 1.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 9.176, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 14.56, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 321.863, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 3.011, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 1.474, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 4.437, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 11.65, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 170.911, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 48.001, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0070/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0070/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0079/environment/Dockerfile b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/environment/workdir/panels.csv b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/environment/workdir/panels.csv new file mode 100644 index 0000000000000000000000000000000000000000..c739b3e85427ee36f3951115ac8495fd04a9c704 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/environment/workdir/panels.csv @@ -0,0 +1,6 @@ +panel_id,finished_length,finished_width,dimension_unit,length_shrinkage_percent,width_shrinkage_percent,raw_gsm,status +P02,819.9999999999999,200.0,cm,2,3,121,accepted +P00,880.0000000000001,100.0,cm,2,3,214,accepted +P01,550.0,190.0,cm,6,3,237,accepted +VOID,9999,100.0,cm,2,3,214,cancelled +P03,670.0,250.0,cm,10,6,212,accepted diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/instruction.md b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fad0b20efa5bd6470ab16c35a410b5ea8e7b5820 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: shrinkage + +`panels.csv` supplies required finished dimensions and measured shrinkage percentages in the length and width directions. Shrinkage is measured relative to the original dimension. Assume mass is conserved in finishing. For each `panel_id` return `raw_length_m` = finished length/(1-length shrinkage/100), `raw_width_m` similarly, `raw_area_m2`, `area_shrinkage_percent` = 100*(1-(1-length shrinkage/100)*(1-width shrinkage/100)), and `finished_gsm` = raw_gsm*raw area/finished area. Do not add directional shrinkage percentages. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `raw_area_m2` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/solution/oracle.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/solution/solve.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/task.toml b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d9a12b197c490a5deef7e726a5d9fc7988a2b4f4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "shrinkage", "isced-0723", "train"] +isced_f = "0723" +family = "shrinkage" +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/textile-lab/textile-lab-shrinkage-d3-t0079/tests/checks.json b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..7e3e7ceb663dd4ec0b20ec4ae3dedbda7f373397 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/tests/checks.json @@ -0,0 +1,149 @@ +[ + { + "path": "results.P00.raw_length_m", + "type": "number", + "value": 8.98, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_width_m", + "type": "number", + "value": 1.031, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.raw_area_m2", + "type": "number", + "value": 9.257, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.area_shrinkage_percent", + "type": "number", + "value": 4.94, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P00.finished_gsm", + "type": "number", + "value": 225.121, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_length_m", + "type": "number", + "value": 5.851, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_width_m", + "type": "number", + "value": 1.959, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.raw_area_m2", + "type": "number", + "value": 11.461, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.area_shrinkage_percent", + "type": "number", + "value": 8.82, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P01.finished_gsm", + "type": "number", + "value": 259.925, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_length_m", + "type": "number", + "value": 8.367, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_width_m", + "type": "number", + "value": 2.062, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.raw_area_m2", + "type": "number", + "value": 17.252, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.area_shrinkage_percent", + "type": "number", + "value": 4.94, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P02.finished_gsm", + "type": "number", + "value": 127.288, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_length_m", + "type": "number", + "value": 7.444, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_width_m", + "type": "number", + "value": 2.66, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.raw_area_m2", + "type": "number", + "value": 19.799, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.area_shrinkage_percent", + "type": "number", + "value": 15.4, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.P03.finished_gsm", + "type": "number", + "value": 250.591, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 57.769, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/tests/test.sh b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-shrinkage-d3-t0079/tests/verify.py b/tasks/textile-lab/textile-lab-shrinkage-d3-t0079/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-shrinkage-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/textile-lab/textile-lab-yarn-length-d1-e0002/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..45f5266d21536fcd3e0d69b77cf3618b8e73dbf6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,70384,m,14,tex,0,accepted +Y01,83273,m,22,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b5313b9982a1b54374f85dea44cd36171e924343 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-e0002/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6312be8bcfc565608927bb972930a71c8dfe9e20 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.985, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.985, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.832, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.832, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-e0002/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-e0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-e0011/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..89f4a6478f68a44cd9c7416d09f9dea0d3f2c74c --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,65367,m,37,tex,0,accepted +Y01,16364,m,12,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d75148ed4649d149fcabf049db196596746f4655 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-e0011/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..84599b3480df51c5005c28238dfb1338570f7ac1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 2.419, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 2.419, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.196, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.196, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-e0011/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-e0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-e0020/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..77c4352f139e45ffe5cdc017061bcb30d3a42bfc --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,63348,m,26,tex,0,accepted +Y01,34181,m,54,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2c019d81ebd869bbd4842d9c8a592ac46e456b5e --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-e0020/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..68493221ba21b5a251c458905b4df0bb68bfbbbc --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.647, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.647, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.846, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.846, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-e0020/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-e0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0002/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..68cdbdcca42e9b11b3f24af95885cb1f5f8d659d --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,48332,m,31,tex,0,accepted +Y01,60581,m,43,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..22cd7136abe1a9af2b1742c5c8804a1da78017c8 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0002/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ea51fffeb1da4c76b733ad959bdcf0358a761b2a --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.498, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.498, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 2.605, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 2.605, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0002/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0002/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0011/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..a5a38388a94064b11a1b85ae89625ec1e2bb5c8a --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,55896,m,30,tex,0,accepted +Y01,92914,m,49,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c7c8622e76d62b563b69fec9c3d4e3786636656f --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0011/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..76a7412eff0eb30f46e94477a9fb5744a2e70205 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.677, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.677, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 4.553, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 4.553, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0011/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0011/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0020/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..3c2ed13e2730cff54609408f72d5e0abea9058b2 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,65843,m,63,tex,0,accepted +Y01,39985,m,49,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8911be46461d1911313fe3222d73f8bac910962c --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0020/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5ae7b02175a753c24b41ee46e308769481f31839 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 4.148, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 4.148, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.959, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.959, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0020/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0020/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0029/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..a38fda0fb413680fafff48ab189123cc7b5742c5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,41079,m,26,tex,0,accepted +Y01,75760,m,68,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9ae74926de317922598e8f8d7b88e6b3d30f7323 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0029/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..1f808e7a9066532029aaa30a66509b17cbe5d1d1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.068, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.068, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 5.152, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 5.152, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0029/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0029/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0038/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..b117e7267c4e3e8499ce876a4a7d7836ed00ea00 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,67853,m,32,tex,0,accepted +Y01,80318,m,20,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1d8773c686409f440d22b9790da9883ffe111157 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0038/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..415466e951d18605fdaa0c4b66f7b77b7511f0ba --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 2.171, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 2.171, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.606, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.606, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0038/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0038/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0047/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..3f342b062179db0344aae9e98806c8ceefe29906 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,28644,m,41,tex,0,accepted +Y01,90379,m,60,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..92079f9e79ba0d1e3101f0c34c1c9c69b0d10a28 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0047/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..99afc69e273b6049f557125f0f2185e4deb6fd67 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.174, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.174, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 5.423, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 5.423, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0047/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0047/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0056/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..1cb61b285c55fa8f1c9657621856d0d3b5527e76 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,88182,m,13,tex,0,accepted +Y01,39068,m,12,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c9e7b0a947ef4d7d85f3ddae39c7b9460810fcfc --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0056/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..63b7473a0302b7d9e280ec479d0426ca8aa8b1c1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.146, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.146, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.469, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.469, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0056/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0056/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0065/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..5172ba13174aba54546a80e39f226c472ac7a324 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,64968,m,72,tex,0,accepted +Y01,50384,m,23,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5ba89b9dfed86771db2e1cf2dcc2350a54f05a89 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0065/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..f79098bdba26e5af5d202c4ad8ce285d9a0ec539 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 4.678, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 4.678, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.159, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.159, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0065/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0065/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0074/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..3c6dfc7bff2ca32c9e67f07b77d43d3aa8e2e397 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,15235,m,51,tex,0,accepted +Y01,35078,m,30,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5b10f1938818d68a0a6bd9c9f88090b8859b437c --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0074/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..ba38b8a61b6a5e3417f0b7337ce422e1cf79e3a9 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.777, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.777, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.052, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.052, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0074/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0074/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0083/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..6400fdb3813b653eb0d7e96d75be4b960bd734f4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/environment/workdir/yarn.csv @@ -0,0 +1,3 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,33400,m,34,tex,0,accepted +Y01,26432,m,69,tex,0,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b507f0ca57ea08f2810a8672d2a5a65221992dc1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "easy" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d1-t0083/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..fe5526fbb0dfde038ff18a5a91b201e7fdb4645d --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/tests/checks.json @@ -0,0 +1,44 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.136, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.136, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.824, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.824, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.0, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d1-t0083/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d1-t0083/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-e0005/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..117d2bcf44de0d8e7b0e6ac86a455fd703004c3c --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,29486,m,18,tex,2,accepted +TRIAL,999999,m,18,tex,2,trial +Y01,27125,m,28,tex,2,accepted +Y02,23985,m,43,tex,8,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..61204418d6c18afa44963e56d17f0cbb865e1530 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-e0005/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..03ca682588fbbc4553c425178a33c207b0b30532 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.531, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.542, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.011, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.759, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.775, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.015, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 1.031, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 1.121, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.09, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-e0005/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-e0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-e0014/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..f0e93cb91773f42229b1ee9c4b87119ce5adb4b6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +TRIAL,999999,m,79,tex,8,trial +Y00,65627,m,79,tex,8,accepted +Y01,41031,m,67,tex,2,accepted +Y02,30051,m,61,tex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..06b7192b60776d159587b66d7d64c14483461ae8 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-e0014/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..e02bd1169e05ad46cf1eac2939e55c7ea62fcd18 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 5.185, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 5.635, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.451, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 2.749, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 2.805, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.056, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 1.833, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 1.871, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.037, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-e0014/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-e0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-e0023/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..2c532aa8653d015803a52a99413bea43ed4ed288 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +TRIAL,999999,m,23,tex,8,trial +Y01,92035,m,24,tex,6,accepted +Y02,21485,m,66,tex,6,accepted +Y00,95027,m,23,tex,8,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3d13b7868726e0e6df1fa88721a3aa5e280aea3c --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-e0023/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0097bd9481b2eb0f337894129cc3aa75a3fd04e6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 2.186, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 2.376, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.19, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 2.209, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 2.35, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.141, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 1.418, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 1.509, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.091, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-e0023/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-e0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0005/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..39551f02cb3d9c479b728f87f2de20ec5829dbf5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y01,41137,m,65,tex,8,accepted +Y02,84598,m,34,tex,8,accepted +TRIAL,999999,m,58,tex,2,trial +Y00,86782,m,58,tex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6838ca4d8ef02e9638285d174e0d3e4151de5d9e --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0005/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..dfeaeda180c9320ee371f6bffaf23378e706807a --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 5.033, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 5.136, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.103, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 2.674, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 2.906, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.233, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 2.876, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 3.126, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.25, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0005/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0005/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0014/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..86205e305c079728fb4e700d3f911bd5ae841831 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y02,34602,m,80,tex,6,accepted +Y00,21467,m,54,tex,4,accepted +TRIAL,999999,m,54,tex,4,trial +Y01,11085,m,28,tex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..43bfc4cc25591a50cd7665771c5660fb0c4624de --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0014/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0810e5b381f084fb4bafcf3716ff0db9982622d3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.159, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.208, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.048, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.31, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.317, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.006, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 2.768, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 2.945, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.177, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0014/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0014/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0023/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..275a57010a6266f0b5a3af64d917ee09c156b3e2 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y02,81182,m,76,tex,6,accepted +Y01,35655,m,25,tex,6,accepted +TRIAL,999999,m,78,tex,2,trial +Y00,52023,m,78,tex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0f81a5f1f89909ab583bb9f2f22ecfc301f42960 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0023/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..5461702765c0f6fddf5d8cb20668b69845677be5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 4.058, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 4.141, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.083, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.891, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.948, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.057, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 6.17, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 6.564, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.394, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0023/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0023/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0032/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..51e0b97d040138c3f0d914bc77dc7511a8836c7f --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +TRIAL,999999,m,27,tex,8,trial +Y02,80665,m,63,tex,6,accepted +Y00,46968,m,27,tex,8,accepted +Y01,29321,m,40,tex,6,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..82fd9397e1eac3c82be709b7bf9879340e580dde --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0032/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..a09ad1216a0513084c382c438adfbab1195b1383 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.268, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.378, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.11, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.173, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.248, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.075, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 5.082, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 5.406, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.324, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0032/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0032/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0041/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..baf6efd3d0fa7c460c5ec172a4b6bbdcd4377a57 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,26476,m,48,tex,6,accepted +Y02,27907,m,17,tex,8,accepted +Y01,84564,m,39,tex,8,accepted +TRIAL,999999,m,48,tex,6,trial diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f7a4877963012a459c2fe6c0440581b315c64ee4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0041/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c729b000189e5ff37476f0ade73410f05a21c6d6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.271, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.352, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.081, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 3.298, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 3.585, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.287, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 0.474, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 0.516, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.041, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0041/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0041/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0050/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..d91bd18f0397ae553db795cdf46feb7c68636cc4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y02,48705,m,60,tex,8,accepted +Y00,34311,m,51,tex,6,accepted +TRIAL,999999,m,51,tex,6,trial +Y01,97093,m,50,tex,6,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..678f651c6b8549e4bad36a68c305a9ca13d0963c --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0050/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..133f237a8daebe682ce7ef01999d6eaa757eeaf4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.75, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.862, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.112, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 4.855, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 5.165, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.31, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 2.922, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 3.176, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.254, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0050/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0050/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0059/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..9dcb6ee8afe44546796187dae8eb31d7f55197bc --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y02,56971,m,56,tex,4,accepted +TRIAL,999999,m,18,tex,2,trial +Y01,88209,m,61,tex,8,accepted +Y00,75441,m,18,tex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..75ac76e939071776cd6ad1e22ab9b31a5609f9ba --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0059/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..0c58980c2aaa624549d46db7773cf57d68aa75d0 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.358, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.386, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.028, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 5.381, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 5.849, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.468, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 3.19, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 3.323, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.133, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0059/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0059/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0068/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..dbe4a2dd436c89582f667fd8fd525b312ecd842a --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y02,70828,m,17,tex,4,accepted +Y00,13269,m,64,tex,4,accepted +Y01,40344,m,58,tex,8,accepted +TRIAL,999999,m,64,tex,4,trial diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1d7ff39835fed49deb295e294f2e4ea48b402f33 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0068/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..eb462abbaea905d03fc27ddd93e81088271a64d3 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.849, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.885, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.035, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 2.34, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 2.543, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.203, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 1.204, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 1.254, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.05, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0068/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0068/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0077/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..fddabea0136035b14a9ac177cb5ab4ee4c4bde44 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/environment/workdir/yarn.csv @@ -0,0 +1,5 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y01,23704,m,60,tex,8,accepted +TRIAL,999999,m,53,tex,8,trial +Y00,74577,m,53,tex,8,accepted +Y02,59962,m,75,tex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..45c251319e3292a2b18a977d10ba2e1530ef8ba1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4f6f625864673b589468b450144d05a20f81ded1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "medium" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d2-t0077/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..498b82653780e2a2788ab2448cd77b20bffb8e1e --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/tests/checks.json @@ -0,0 +1,65 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 3.953, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 4.296, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.344, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.422, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.546, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.124, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 4.497, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 4.589, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.092, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d2-t0077/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d2-t0077/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-e0008/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..c7250cbe6afd67c54b272dcbe8bbbc1890e6ce0c --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,49465,m,300,dtex,8,accepted +Y03,86.799,km,400,dtex,8,accepted +TRIAL,999999,m,300,dtex,8,trial +Y02,60515,m,330,dtex,8,accepted +Y01,24.78,km,200,dtex,8,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c95fb8ea1a7b9e65c8aa61f524c6316e279d9b34 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-e0008/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c3f7a9e84fa3452da9a567d2be937516bb9ba6fd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.484, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 1.613, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.129, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.496, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.539, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.043, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 1.997, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 2.171, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.174, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 3.472, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 3.774, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.302, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 8.096, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-e0008/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-e0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-e0017/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..57fa0786fe6f099e5f11a79209be977e2d5e1b91 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,75920,m,260,dtex,4,accepted +Y02,20587,m,610,dtex,2,accepted +Y01,81.079,km,460,dtex,8,accepted +TRIAL,999999,m,260,dtex,4,trial +Y03,38.547,km,760,dtex,4,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..55ebb74ff4c3c01e7f99e32a359d33de2290e74f --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "eval"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-e0017/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..88ee6136e62b16cafb84e1a07284e2be90f9e5eb --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.974, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 2.056, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.082, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 3.73, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 4.054, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.324, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 1.256, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 1.281, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.026, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 2.93, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 3.052, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.122, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 10.443, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-e0017/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-e0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0008/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..1f5c9e039eeec851d0b8f45f7c0f46e58c6a3f40 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y01,78.746,km,710,dtex,6,accepted +Y03,23.876,km,390,dtex,8,accepted +TRIAL,999999,m,210,dtex,6,trial +Y00,33851,m,210,dtex,6,accepted +Y02,93387,m,760,dtex,6,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..689611ea2d273bd1563a8e071c3e92a207a810bd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0008/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..46f66e84a0889ebdf580cd4a4334b846f8c89bef --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.711, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.756, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.045, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 5.591, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 5.948, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.357, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 7.097, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 7.55, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.453, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 0.931, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 1.012, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.081, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 15.267, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0008/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0008/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0017/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..ac339396373e1fd1d95bef09a98a76eb8c2031a4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +TRIAL,999999,m,340,dtex,8,trial +Y02,18541,m,320,dtex,4,accepted +Y00,11009,m,340,dtex,8,accepted +Y03,78.957,km,710,dtex,4,accepted +Y01,17.075,km,430,dtex,4,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2f0e7edcb750b796848555566bd759647364c673 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0017/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..28601e0b41c1628160d5c4af4e5e037d740c4a60 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.374, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.407, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.033, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.734, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.765, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.031, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 0.593, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 0.618, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.025, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 5.606, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 5.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.234, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 7.629, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0017/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0017/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0026/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..0ecde1206a53bf896a34c305d9d115f468ca96fb --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +TRIAL,999999,m,210,dtex,2,trial +Y02,20748,m,350,dtex,8,accepted +Y03,44.407,km,700,dtex,4,accepted +Y00,94995,m,210,dtex,2,accepted +Y01,19.122,km,550,dtex,8,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d4f38752e2545bab303fe05c83415702036aaade --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0026/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..6d20d5620b55293fcb911a28dc22576719f69804 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 1.995, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 2.036, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.041, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.052, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.143, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.091, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 0.726, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 0.789, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.063, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 3.108, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 3.238, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.13, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 7.206, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0026/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0026/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0035/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..ce3fa0daad7003f18270307b220421589173e3f7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y03,38.296,km,280,dtex,4,accepted +Y01,63.47,km,280,dtex,6,accepted +Y02,95412,m,770,dtex,2,accepted +Y00,11055,m,680,dtex,8,accepted +TRIAL,999999,m,680,dtex,8,trial diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..28100130a85e339b0b3709d2f6d3594a0ab2e8b4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0035/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..d9508c36463ac1c762ff4cd942a5728be2531dd1 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.752, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.817, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.065, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.777, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.891, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.113, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 7.347, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 7.497, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.15, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 1.072, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 1.117, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.045, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 11.321, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0035/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0035/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0044/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..b75e6f118241866ba3eae7d23328e43d46c2d000 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +TRIAL,999999,m,550,dtex,6,trial +Y01,37.677,km,470,dtex,2,accepted +Y00,72083,m,550,dtex,6,accepted +Y02,95066,m,270,dtex,2,accepted +Y03,85.039,km,440,dtex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..756817f47c992afc7f4d94f8e57b8ee7431ef405 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0044/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..b554a18cec3343072696952196a11ce0b03af8ff --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 3.965, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 4.218, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.253, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.771, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.807, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.036, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 2.567, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 2.619, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.052, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 3.742, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 3.818, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.076, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 12.462, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0044/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0044/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0053/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..ddef531f2f85a2b6dbf19ea9cc29e71c17555dd6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y01,20.709,km,770,dtex,8,accepted +Y00,47865,m,660,dtex,6,accepted +Y03,74.199,km,450,dtex,8,accepted +TRIAL,999999,m,660,dtex,6,trial +Y02,74071,m,360,dtex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..293413d6c1eb404a8432418a6b28c5fba34ce07b --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0053/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c7f929ec3a9cea12e3292688f5b34691a3b73946 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 3.159, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 3.361, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.202, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 1.595, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 1.733, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.139, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 2.667, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 2.721, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.054, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 3.339, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 3.629, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.29, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 11.444, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0053/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0053/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0062/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..10e2b37d539435ea7b27260c672b0c406fd7bf1d --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y00,13744,m,320,dtex,6,accepted +Y02,38311,m,140,dtex,2,accepted +Y03,86.701,km,780,dtex,6,accepted +TRIAL,999999,m,320,dtex,6,trial +Y01,45.184,km,120,dtex,4,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..89627f6fa744ac7f9b341a37a866e1a22a2704f5 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0062/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..32c416fe6350fec1f1c8edb520cfcd84e76f4aa6 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.44, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.468, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.028, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 0.542, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 0.565, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.023, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 0.536, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 0.547, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.011, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 6.763, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 7.194, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.432, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 8.774, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0062/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0062/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0071/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..324bb16d20b752c94e643ddb94e27119a4c78dca --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y02,72253,m,620,dtex,4,accepted +Y00,45204,m,460,dtex,2,accepted +TRIAL,999999,m,460,dtex,2,trial +Y03,40.707,km,170,dtex,2,accepted +Y01,74.469,km,390,dtex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..397a35c92f32fa5839062f6bbc663513b0c6ef66 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0071/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..dca3c7e36e945387321159e54071901e5ea3bf21 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 2.079, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 2.122, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.042, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 2.904, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 2.964, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.059, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 4.48, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 4.666, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.187, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 0.692, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 0.706, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.014, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 10.458, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0071/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0071/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0080/environment/Dockerfile b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d2579fdacf261c4800d0280c0927cbaace75c6cd --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/environment/Dockerfile @@ -0,0 +1,3 @@ +FROM python:3.12-slim +WORKDIR /app +COPY workdir/ /app/ diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/environment/workdir/yarn.csv b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/environment/workdir/yarn.csv new file mode 100644 index 0000000000000000000000000000000000000000..80239445cf34f6da5a8a90e51e84bb6a8319994b --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/environment/workdir/yarn.csv @@ -0,0 +1,6 @@ +order_id,net_length,length_unit,linear_density,density_unit,process_loss_percent,status +Y02,78875,m,630,dtex,8,accepted +Y01,40.448,km,550,dtex,8,accepted +Y00,13725,m,270,dtex,6,accepted +TRIAL,999999,m,270,dtex,6,trial +Y03,91.32,km,530,dtex,2,accepted diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/instruction.md b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62913016954d4cc53f09de35bfc98001d46ac986 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/instruction.md @@ -0,0 +1,5 @@ +# Textile Lab: yarn-length + +`yarn.csv` lists net yarn length needed in finished production. Tex is grams per 1000 m. For each `order_id` return `net_mass_kg` = length_m*tex/1,000,000, `purchase_mass_kg` = net mass/(1-process_loss_percent/100), and `loss_mass_kg` = purchase minus net. Loss is a fraction of purchased yarn, not a markup on net mass. + +Only rows with `status=accepted` are in scope. Unit conversions: 1 cm = 0.01 m, 1 km = 1000 m, 1 dtex = 0.1 tex. Write `answer.json` with `results`, keyed by record id. Also provide `total_primary`, the sum of `purchase_mass_kg` over result groups. All outputs have 3 decimal places and are accepted within 0.001. Do not round intermediate values. Data and processing assumptions are synthetic. diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/solution/oracle.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/solution/oracle.py new file mode 100644 index 0000000000000000000000000000000000000000..d68b5142e5902ef2b5994198c960d7707fd19fc7 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/solution/oracle.py @@ -0,0 +1,27 @@ +"""Solve textile records without using generator code.""" +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']=='accepted'] + +def solve(): + out={} + if Path('rolls.csv').exists(): + for r in read('rolls.csv'): + width=float(r['width'])/(100 if r['width_unit']=='cm' else 1);area=float(r['length_m'])*width;grammes=area*float(r['gsm']);usable=float(r['usable_percent'])/100 + out[r['roll_id']]=dict(gross_area_m2=area,gross_mass_kg=grammes/1000,usable_area_m2=area*usable,usable_mass_kg=grammes*usable/1000) + primary='usable_mass_kg' + elif Path('yarn.csv').exists(): + for r in read('yarn.csv'): + km=float(r['net_length'])/(1000 if r['length_unit']=='m' else 1);g_per_km=float(r['linear_density'])/(10 if r['density_unit']=='dtex' else 1);net=km*g_per_km/1000;purchase=net*100/(100-float(r['process_loss_percent'])) + out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net) + primary='purchase_mass_kg' + else: + for r in read('panels.csv'): + scale=.01 if r['dimension_unit']=='cm' else 1;l=float(r['finished_length'])*scale;w=float(r['finished_width'])*scale;rl=100-float(r['length_shrinkage_percent']);rw=100-float(r['width_shrinkage_percent']);raw_l=l*100/rl;raw_w=w*100/rw + out[r['panel_id']]=dict(raw_length_m=raw_l,raw_width_m=raw_w,raw_area_m2=raw_l*raw_w,area_shrinkage_percent=100-rl*rw/100,finished_gsm=float(r['raw_gsm'])*10000/(rl*rw)) + primary='raw_area_m2' + return dict(results=out,total_primary=sum(v[primary] for v in out.values())) + +if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve())) diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/solution/solve.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e181145ecdd916c6ebba65c9c854625c6e95d9ab --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/solution/solve.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd /app +python3 /solution/oracle.py diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/task.toml b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2f6dc3bc1e808b8fc7b442b94d5d40238ab86096 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/task.toml @@ -0,0 +1,25 @@ +version = "1.0" + +[metadata] +author_name = "Renaissance Labs" +author_email = "unknown" +difficulty = "hard" +category = "textile-lab" +tags = ["textile-lab", "yarn-length", "isced-0723", "train"] +isced_f = "0723" +family = "yarn-length" +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/textile-lab/textile-lab-yarn-length-d3-t0080/tests/checks.json b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/tests/checks.json new file mode 100644 index 0000000000000000000000000000000000000000..c0c5bb31a39f682d89aa4e5664c99068bd10eaf4 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/tests/checks.json @@ -0,0 +1,93 @@ +[ + { + "path": "results.Y00.net_mass_kg", + "type": "number", + "value": 0.371, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.purchase_mass_kg", + "type": "number", + "value": 0.394, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y00.loss_mass_kg", + "type": "number", + "value": 0.024, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.net_mass_kg", + "type": "number", + "value": 2.225, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.purchase_mass_kg", + "type": "number", + "value": 2.418, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y01.loss_mass_kg", + "type": "number", + "value": 0.193, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.net_mass_kg", + "type": "number", + "value": 4.969, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.purchase_mass_kg", + "type": "number", + "value": 5.401, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y02.loss_mass_kg", + "type": "number", + "value": 0.432, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.net_mass_kg", + "type": "number", + "value": 4.84, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.purchase_mass_kg", + "type": "number", + "value": 4.939, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "results.Y03.loss_mass_kg", + "type": "number", + "value": 0.099, + "abs_tol": 0.001, + "weight": 1.0 + }, + { + "path": "total_primary", + "type": "number", + "value": 13.152, + "abs_tol": 0.001, + "weight": 1.0 + } +] diff --git a/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/tests/test.sh b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f1149df2619f3f11ecc1e06c9ee5b6599e8ab71 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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/textile-lab/textile-lab-yarn-length-d3-t0080/tests/verify.py b/tasks/textile-lab/textile-lab-yarn-length-d3-t0080/tests/verify.py new file mode 100644 index 0000000000000000000000000000000000000000..e03124340b6015e692f6944976f4dedcadc0e722 --- /dev/null +++ b/tasks/textile-lab/textile-lab-yarn-length-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()