Add textile-lab subset: 84 train and 24 eval tasks
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/Dockerfile +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/workdir/rolls.csv +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/instruction.md +5 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/oracle.py +27 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/solve.sh +4 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/task.toml +25 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/checks.json +58 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/test.sh +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/verify.py +116 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/Dockerfile +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/workdir/rolls.csv +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/instruction.md +5 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/oracle.py +27 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/solve.sh +4 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/task.toml +25 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/checks.json +58 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/test.sh +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/verify.py +116 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/Dockerfile +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/workdir/rolls.csv +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/instruction.md +5 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/oracle.py +27 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/solve.sh +4 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/task.toml +25 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/checks.json +58 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/test.sh +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/verify.py +116 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/Dockerfile +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/workdir/rolls.csv +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/instruction.md +5 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/oracle.py +27 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/solve.sh +4 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/task.toml +25 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/checks.json +58 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/test.sh +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/verify.py +116 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/Dockerfile +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/workdir/rolls.csv +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/instruction.md +5 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/oracle.py +27 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/solve.sh +4 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/task.toml +25 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/checks.json +58 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/test.sh +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/verify.py +116 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/Dockerfile +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/workdir/rolls.csv +3 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/instruction.md +5 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/oracle.py +27 -0
- tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/solve.sh +4 -0
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/environment/workdir/rolls.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour
|
| 2 |
+
F00,61,1.27,m,140,100,accepted,grey
|
| 3 |
+
F01,58,1.48,m,301,100,accepted,grey
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Textile Lab: fabric-mass
|
| 2 |
+
|
| 3 |
+
`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.
|
| 4 |
+
|
| 5 |
+
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.
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Solve textile records without using generator code."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='accepted']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('rolls.csv').exists():
|
| 11 |
+
for r in read('rolls.csv'):
|
| 12 |
+
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
|
| 13 |
+
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)
|
| 14 |
+
primary='usable_mass_kg'
|
| 15 |
+
elif Path('yarn.csv').exists():
|
| 16 |
+
for r in read('yarn.csv'):
|
| 17 |
+
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']))
|
| 18 |
+
out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net)
|
| 19 |
+
primary='purchase_mass_kg'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('panels.csv'):
|
| 22 |
+
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
|
| 23 |
+
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))
|
| 24 |
+
primary='raw_area_m2'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "textile-lab"
|
| 8 |
+
tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"]
|
| 9 |
+
isced_f = "0723"
|
| 10 |
+
family = "fabric-mass"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10000
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.F00.gross_area_m2",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 77.47,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.F00.gross_mass_kg",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 10.846,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.F00.usable_area_m2",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 77.47,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.F00.usable_mass_kg",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 10.846,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.F01.gross_area_m2",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 85.84,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.F01.gross_mass_kg",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 25.838,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.F01.usable_area_m2",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 85.84,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.F01.usable_mass_kg",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 25.838,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0000/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/environment/workdir/rolls.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour
|
| 2 |
+
F00,329,1.58,m,241,100,accepted,navy
|
| 3 |
+
F01,80,1.35,m,186,100,accepted,grey
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Textile Lab: fabric-mass
|
| 2 |
+
|
| 3 |
+
`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.
|
| 4 |
+
|
| 5 |
+
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.
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Solve textile records without using generator code."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='accepted']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('rolls.csv').exists():
|
| 11 |
+
for r in read('rolls.csv'):
|
| 12 |
+
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
|
| 13 |
+
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)
|
| 14 |
+
primary='usable_mass_kg'
|
| 15 |
+
elif Path('yarn.csv').exists():
|
| 16 |
+
for r in read('yarn.csv'):
|
| 17 |
+
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']))
|
| 18 |
+
out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net)
|
| 19 |
+
primary='purchase_mass_kg'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('panels.csv'):
|
| 22 |
+
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
|
| 23 |
+
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))
|
| 24 |
+
primary='raw_area_m2'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "textile-lab"
|
| 8 |
+
tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"]
|
| 9 |
+
isced_f = "0723"
|
| 10 |
+
family = "fabric-mass"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10009
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.F00.gross_area_m2",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 519.82,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.F00.gross_mass_kg",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 125.277,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.F00.usable_area_m2",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 519.82,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.F00.usable_mass_kg",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 125.277,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.F01.gross_area_m2",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 108.0,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.F01.gross_mass_kg",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 20.088,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.F01.usable_area_m2",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 108.0,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.F01.usable_mass_kg",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 20.088,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0009/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/environment/workdir/rolls.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour
|
| 2 |
+
F00,343,2.05,m,332,100,accepted,cream
|
| 3 |
+
F01,306,2.12,m,106,100,accepted,cream
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Textile Lab: fabric-mass
|
| 2 |
+
|
| 3 |
+
`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.
|
| 4 |
+
|
| 5 |
+
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.
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Solve textile records without using generator code."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='accepted']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('rolls.csv').exists():
|
| 11 |
+
for r in read('rolls.csv'):
|
| 12 |
+
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
|
| 13 |
+
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)
|
| 14 |
+
primary='usable_mass_kg'
|
| 15 |
+
elif Path('yarn.csv').exists():
|
| 16 |
+
for r in read('yarn.csv'):
|
| 17 |
+
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']))
|
| 18 |
+
out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net)
|
| 19 |
+
primary='purchase_mass_kg'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('panels.csv'):
|
| 22 |
+
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
|
| 23 |
+
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))
|
| 24 |
+
primary='raw_area_m2'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "textile-lab"
|
| 8 |
+
tags = ["textile-lab", "fabric-mass", "isced-0723", "eval"]
|
| 9 |
+
isced_f = "0723"
|
| 10 |
+
family = "fabric-mass"
|
| 11 |
+
split = "eval"
|
| 12 |
+
seed = 10018
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.F00.gross_area_m2",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 703.15,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.F00.gross_mass_kg",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 233.446,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.F00.usable_area_m2",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 703.15,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.F00.usable_mass_kg",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 233.446,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.F01.gross_area_m2",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 648.72,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.F01.gross_mass_kg",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 68.764,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.F01.usable_area_m2",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 648.72,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.F01.usable_mass_kg",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 68.764,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/textile-lab/textile-lab-fabric-mass-d1-e0018/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/environment/workdir/rolls.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour
|
| 2 |
+
F00,329,1.38,m,343,100,accepted,grey
|
| 3 |
+
F01,143,1.9,m,248,100,accepted,navy
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Textile Lab: fabric-mass
|
| 2 |
+
|
| 3 |
+
`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.
|
| 4 |
+
|
| 5 |
+
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.
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Solve textile records without using generator code."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='accepted']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('rolls.csv').exists():
|
| 11 |
+
for r in read('rolls.csv'):
|
| 12 |
+
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
|
| 13 |
+
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)
|
| 14 |
+
primary='usable_mass_kg'
|
| 15 |
+
elif Path('yarn.csv').exists():
|
| 16 |
+
for r in read('yarn.csv'):
|
| 17 |
+
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']))
|
| 18 |
+
out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net)
|
| 19 |
+
primary='purchase_mass_kg'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('panels.csv'):
|
| 22 |
+
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
|
| 23 |
+
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))
|
| 24 |
+
primary='raw_area_m2'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "textile-lab"
|
| 8 |
+
tags = ["textile-lab", "fabric-mass", "isced-0723", "train"]
|
| 9 |
+
isced_f = "0723"
|
| 10 |
+
family = "fabric-mass"
|
| 11 |
+
split = "train"
|
| 12 |
+
seed = 0
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.F00.gross_area_m2",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 454.02,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.F00.gross_mass_kg",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 155.729,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.F00.usable_area_m2",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 454.02,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.F00.usable_mass_kg",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 155.729,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.F01.gross_area_m2",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 271.7,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.F01.gross_mass_kg",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 67.382,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.F01.usable_area_m2",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 271.7,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.F01.usable_mass_kg",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 67.382,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0000/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/environment/workdir/rolls.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour
|
| 2 |
+
F00,57,1.53,m,290,100,accepted,grey
|
| 3 |
+
F01,104,1.78,m,280,100,accepted,navy
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Textile Lab: fabric-mass
|
| 2 |
+
|
| 3 |
+
`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.
|
| 4 |
+
|
| 5 |
+
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.
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Solve textile records without using generator code."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='accepted']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('rolls.csv').exists():
|
| 11 |
+
for r in read('rolls.csv'):
|
| 12 |
+
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
|
| 13 |
+
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)
|
| 14 |
+
primary='usable_mass_kg'
|
| 15 |
+
elif Path('yarn.csv').exists():
|
| 16 |
+
for r in read('yarn.csv'):
|
| 17 |
+
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']))
|
| 18 |
+
out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net)
|
| 19 |
+
primary='purchase_mass_kg'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('panels.csv'):
|
| 22 |
+
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
|
| 23 |
+
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))
|
| 24 |
+
primary='raw_area_m2'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/task.toml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[metadata]
|
| 4 |
+
author_name = "Renaissance Labs"
|
| 5 |
+
author_email = "unknown"
|
| 6 |
+
difficulty = "easy"
|
| 7 |
+
category = "textile-lab"
|
| 8 |
+
tags = ["textile-lab", "fabric-mass", "isced-0723", "train"]
|
| 9 |
+
isced_f = "0723"
|
| 10 |
+
family = "fabric-mass"
|
| 11 |
+
split = "train"
|
| 12 |
+
seed = 9
|
| 13 |
+
|
| 14 |
+
[verifier]
|
| 15 |
+
timeout_sec = 120.0
|
| 16 |
+
|
| 17 |
+
[agent]
|
| 18 |
+
timeout_sec = 900.0
|
| 19 |
+
|
| 20 |
+
[environment]
|
| 21 |
+
build_timeout_sec = 600.0
|
| 22 |
+
cpus = 1
|
| 23 |
+
memory_mb = 1024
|
| 24 |
+
storage_mb = 2048
|
| 25 |
+
allow_internet = false
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/checks.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"path": "results.F00.gross_area_m2",
|
| 4 |
+
"type": "number",
|
| 5 |
+
"value": 87.21,
|
| 6 |
+
"abs_tol": 0.001,
|
| 7 |
+
"weight": 1.0
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"path": "results.F00.gross_mass_kg",
|
| 11 |
+
"type": "number",
|
| 12 |
+
"value": 25.291,
|
| 13 |
+
"abs_tol": 0.001,
|
| 14 |
+
"weight": 1.0
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"path": "results.F00.usable_area_m2",
|
| 18 |
+
"type": "number",
|
| 19 |
+
"value": 87.21,
|
| 20 |
+
"abs_tol": 0.001,
|
| 21 |
+
"weight": 1.0
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"path": "results.F00.usable_mass_kg",
|
| 25 |
+
"type": "number",
|
| 26 |
+
"value": 25.291,
|
| 27 |
+
"abs_tol": 0.001,
|
| 28 |
+
"weight": 1.0
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "results.F01.gross_area_m2",
|
| 32 |
+
"type": "number",
|
| 33 |
+
"value": 185.12,
|
| 34 |
+
"abs_tol": 0.001,
|
| 35 |
+
"weight": 1.0
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"path": "results.F01.gross_mass_kg",
|
| 39 |
+
"type": "number",
|
| 40 |
+
"value": 51.834,
|
| 41 |
+
"abs_tol": 0.001,
|
| 42 |
+
"weight": 1.0
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"path": "results.F01.usable_area_m2",
|
| 46 |
+
"type": "number",
|
| 47 |
+
"value": 185.12,
|
| 48 |
+
"abs_tol": 0.001,
|
| 49 |
+
"weight": 1.0
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"path": "results.F01.usable_mass_kg",
|
| 53 |
+
"type": "number",
|
| 54 |
+
"value": 51.834,
|
| 55 |
+
"abs_tol": 0.001,
|
| 56 |
+
"weight": 1.0
|
| 57 |
+
}
|
| 58 |
+
]
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/test.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
python3 /tests/verify.py --answer /app/answer.json --checks /tests/checks.json --out /logs/verifier || echo 0 > /logs/verifier/reward.txt
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0009/tests/verify.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Verifier for Renaissance Labs practice environments. Standard library only.
|
| 3 |
+
|
| 4 |
+
Reads the agent's answer (a JSON object) and a list of checks, and writes a reward in [0, 1].
|
| 5 |
+
The reward is the weighted share of checks that pass. A missing, unreadable or non-object
|
| 6 |
+
answer scores 0. Each check addresses one value in the answer by a dotted path.
|
| 7 |
+
|
| 8 |
+
Check types
|
| 9 |
+
int exact integer (a float with integral value is accepted; booleans are not)
|
| 10 |
+
number within abs_tol of value (default 1e-9); booleans and strings are rejected
|
| 11 |
+
str equal after trimming and case-folding
|
| 12 |
+
bool exact boolean
|
| 13 |
+
list ordered list; items compared as int/number/str according to "item" (default str)
|
| 14 |
+
set unordered collection of distinct strings (or ints)
|
| 15 |
+
custom a function in validators.py: name(answer, args) -> bool or float in [0, 1]
|
| 16 |
+
"""
|
| 17 |
+
import argparse, json, math, os, sys
|
| 18 |
+
|
| 19 |
+
MISSING = object()
|
| 20 |
+
|
| 21 |
+
def lookup(obj, path):
|
| 22 |
+
cur = obj
|
| 23 |
+
for part in path.split("."):
|
| 24 |
+
if isinstance(cur, dict):
|
| 25 |
+
if part not in cur: return MISSING
|
| 26 |
+
cur = cur[part]
|
| 27 |
+
elif isinstance(cur, list):
|
| 28 |
+
try: cur = cur[int(part)]
|
| 29 |
+
except (ValueError, IndexError): return MISSING
|
| 30 |
+
else:
|
| 31 |
+
return MISSING
|
| 32 |
+
return cur
|
| 33 |
+
|
| 34 |
+
def is_num(x):
|
| 35 |
+
return isinstance(x, (int, float)) and not isinstance(x, bool) and not (isinstance(x, float) and (math.isnan(x) or math.isinf(x)))
|
| 36 |
+
|
| 37 |
+
def eq_int(got, want):
|
| 38 |
+
return is_num(got) and float(got) == float(int(got)) and int(got) == want
|
| 39 |
+
|
| 40 |
+
def eq_num(got, want, tol):
|
| 41 |
+
return is_num(got) and abs(float(got) - float(want)) <= tol + 1e-12
|
| 42 |
+
|
| 43 |
+
def eq_str(got, want):
|
| 44 |
+
return isinstance(got, str) and got.strip().casefold() == str(want).strip().casefold()
|
| 45 |
+
|
| 46 |
+
def eq_item(got, want, kind, tol):
|
| 47 |
+
if kind == "int": return eq_int(got, want)
|
| 48 |
+
if kind == "number": return eq_num(got, want, tol)
|
| 49 |
+
return eq_str(got, want)
|
| 50 |
+
|
| 51 |
+
def run_check(answer, chk, validators):
|
| 52 |
+
t = chk["type"]
|
| 53 |
+
if t == "custom":
|
| 54 |
+
fn = getattr(validators, chk["name"], None) if validators else None
|
| 55 |
+
if fn is None: return 0.0
|
| 56 |
+
try: r = fn(answer, chk.get("args", {}))
|
| 57 |
+
except Exception: return 0.0
|
| 58 |
+
if r is True: return 1.0
|
| 59 |
+
if r is False or r is None: return 0.0
|
| 60 |
+
return max(0.0, min(1.0, float(r))) if is_num(r) else 0.0
|
| 61 |
+
got = lookup(answer, chk["path"])
|
| 62 |
+
if got is MISSING: return 0.0
|
| 63 |
+
want, tol = chk["value"], chk.get("abs_tol", 1e-9)
|
| 64 |
+
if t == "int": ok = eq_int(got, want)
|
| 65 |
+
elif t == "number": ok = eq_num(got, want, tol)
|
| 66 |
+
elif t == "str": ok = eq_str(got, want)
|
| 67 |
+
elif t == "bool": ok = isinstance(got, bool) and got is want
|
| 68 |
+
elif t == "list":
|
| 69 |
+
ok = isinstance(got, list) and len(got) == len(want) and all(eq_item(g, w, chk.get("item", "str"), tol) for g, w in zip(got, want))
|
| 70 |
+
elif t == "set":
|
| 71 |
+
kind = chk.get("item", "str")
|
| 72 |
+
if not isinstance(got, list): ok = False
|
| 73 |
+
else:
|
| 74 |
+
norm = (lambda x: x.strip().casefold() if isinstance(x, str) else None) if kind == "str" else (lambda x: int(x) if eq_int(x, int(x) if is_num(x) else 0) else None)
|
| 75 |
+
g = [norm(x) for x in got]; w = [norm(x) for x in want]
|
| 76 |
+
ok = None not in g and len(g) == len(set(g)) and set(g) == set(w)
|
| 77 |
+
else: ok = False
|
| 78 |
+
return 1.0 if ok else 0.0
|
| 79 |
+
|
| 80 |
+
def grade(answer, checks, validators=None):
|
| 81 |
+
"""Return (reward, details). answer is the parsed JSON, or None if it could not be read."""
|
| 82 |
+
if not isinstance(answer, dict):
|
| 83 |
+
return 0.0, [{"check": c.get("path", c.get("name")), "score": 0.0} for c in checks]
|
| 84 |
+
total = sum(c.get("weight", 1.0) for c in checks)
|
| 85 |
+
got, details = 0.0, []
|
| 86 |
+
for c in checks:
|
| 87 |
+
s = run_check(answer, c, validators)
|
| 88 |
+
got += s * c.get("weight", 1.0)
|
| 89 |
+
details.append({"check": c.get("path", c.get("name")), "score": s})
|
| 90 |
+
return (round(got / total, 6) if total else 0.0), details
|
| 91 |
+
|
| 92 |
+
def main():
|
| 93 |
+
ap = argparse.ArgumentParser()
|
| 94 |
+
ap.add_argument("--answer", default="/app/answer.json")
|
| 95 |
+
ap.add_argument("--checks", default=os.path.join(os.path.dirname(os.path.abspath(__file__)), "checks.json"))
|
| 96 |
+
ap.add_argument("--out", default="/logs/verifier")
|
| 97 |
+
a = ap.parse_args()
|
| 98 |
+
checks = json.load(open(a.checks))
|
| 99 |
+
try:
|
| 100 |
+
with open(a.answer) as f: answer = json.load(f)
|
| 101 |
+
except Exception:
|
| 102 |
+
answer = None
|
| 103 |
+
validators = None
|
| 104 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 105 |
+
if os.path.exists(os.path.join(here, "validators.py")):
|
| 106 |
+
sys.path.insert(0, here)
|
| 107 |
+
import validators # noqa
|
| 108 |
+
reward, details = grade(answer, checks, validators)
|
| 109 |
+
os.makedirs(a.out, exist_ok=True)
|
| 110 |
+
with open(os.path.join(a.out, "reward.txt"), "w") as f: f.write(str(reward))
|
| 111 |
+
with open(os.path.join(a.out, "reward.json"), "w") as f:
|
| 112 |
+
json.dump({"reward": reward, "solved": reward == 1.0, "passed": sum(1 for d in details if d["score"] == 1.0), "checks": len(details)}, f)
|
| 113 |
+
print("reward", reward)
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY workdir/ /app/
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/environment/workdir/rolls.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
roll_id,length_m,width,width_unit,gsm,usable_percent,status,colour
|
| 2 |
+
F00,248,1.87,m,198,100,accepted,cream
|
| 3 |
+
F01,126,2.15,m,172,100,accepted,cream
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/instruction.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Textile Lab: fabric-mass
|
| 2 |
+
|
| 3 |
+
`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.
|
| 4 |
+
|
| 5 |
+
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.
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/oracle.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Solve textile records without using generator code."""
|
| 2 |
+
import csv,json
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def read(name):
|
| 6 |
+
with open(name) as f:return [r for r in csv.DictReader(f) if r['status']=='accepted']
|
| 7 |
+
|
| 8 |
+
def solve():
|
| 9 |
+
out={}
|
| 10 |
+
if Path('rolls.csv').exists():
|
| 11 |
+
for r in read('rolls.csv'):
|
| 12 |
+
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
|
| 13 |
+
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)
|
| 14 |
+
primary='usable_mass_kg'
|
| 15 |
+
elif Path('yarn.csv').exists():
|
| 16 |
+
for r in read('yarn.csv'):
|
| 17 |
+
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']))
|
| 18 |
+
out[r['order_id']]=dict(net_mass_kg=net,purchase_mass_kg=purchase,loss_mass_kg=purchase-net)
|
| 19 |
+
primary='purchase_mass_kg'
|
| 20 |
+
else:
|
| 21 |
+
for r in read('panels.csv'):
|
| 22 |
+
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
|
| 23 |
+
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))
|
| 24 |
+
primary='raw_area_m2'
|
| 25 |
+
return dict(results=out,total_primary=sum(v[primary] for v in out.values()))
|
| 26 |
+
|
| 27 |
+
if __name__=='__main__':Path('answer.json').write_text(json.dumps(solve()))
|
tasks/textile-lab/textile-lab-fabric-mass-d1-t0018/solution/solve.sh
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
cd /app
|
| 4 |
+
python3 /solution/oracle.py
|