burtenshaw HF Staff
Publish procedural SQL investigation tasks and reproducible environment source
2ce79be verified Download source/scripts/prepare_dataset.py from burtenshaw/openenv-sql-investigation: direct link, hf CLI and curl.
- Browser
- Download file 4.56 kB
-
https://huggingface.co/datasets/burtenshaw/openenv-sql-investigation/resolve/main/source/scripts/prepare_dataset.py
- Command line
-
hf download hf://datasets/burtenshaw/openenv-sql-investigation/source/scripts/prepare_dataset.py
-
curl -L -o prepare_dataset.py https://huggingface.co/datasets/burtenshaw/openenv-sql-investigation/resolve/main/source/scripts/prepare_dataset.py
4.56 kB
| """Build a public, reproducible dataset from an explicit source-file allowlist.""" | |
| import json | |
| import shutil | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from sql_investigation.tasks import TASK_IDS, build_task | |
| def main(): | |
| target = ROOT / "dataset-stage" | |
| target.mkdir(exist_ok=True) | |
| rows = [] | |
| for task_id in TASK_IDS: | |
| task = build_task(task_id, 42) | |
| try: | |
| rows.append( | |
| { | |
| "task_id": task_id, | |
| "split": "train", | |
| "seed": 42, | |
| "instruction": task.instruction, | |
| "schema": task.schema, | |
| "expected_rows_json": json.dumps(task.expected_rows), | |
| "oracle_sql": task.oracle_sql, | |
| } | |
| ) | |
| data_dir = target / "data" | |
| data_dir.mkdir(exist_ok=True) | |
| (data_dir / f"{task_id}.sql").write_text("\n".join(task.connection.iterdump()) + "\n") | |
| finally: | |
| task.connection.close() | |
| (target / "tasks.jsonl").write_text("".join(json.dumps(row) + "\n" for row in rows)) | |
| for path in [ | |
| *ROOT.glob("sql_investigation/*.py"), | |
| *ROOT.glob("server/*.py"), | |
| *ROOT.glob("tests/*.py"), | |
| *ROOT.glob("scripts/*.py"), | |
| ROOT / "server/Dockerfile", | |
| ROOT / "openenv.yaml", | |
| ROOT / "requirements.lock", | |
| ROOT / "pyproject.toml", | |
| ROOT / "LICENSE", | |
| ROOT / "README.md", | |
| ]: | |
| destination = target / "source" / path.relative_to(ROOT) | |
| destination.parent.mkdir(parents=True, exist_ok=True) | |
| shutil.copyfile(path, destination) | |
| revision = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT, text=True).strip() | |
| (target / "README.md").write_text(f"""--- | |
| license: mit | |
| language: | |
| - en | |
| tags: | |
| - openenv | |
| - reinforcement-learning | |
| - sql | |
| - synthetic | |
| size_categories: | |
| - n<1K | |
| configs: | |
| - config_name: default | |
| data_files: | |
| - split: train | |
| path: tasks.jsonl | |
| --- | |
| # OpenEnv SQL Investigation | |
| Ten original procedural SQL investigation families teach joins, duplicate-safe aggregation, missing-data handling, weighted rates, temporal conditions, cohorts, anti-joins, ranking, and streak analysis. All data are synthetic and generated locally; there are no personal data or downloaded task assets. | |
| The container generates a fresh in-memory SQLite database on every unseeded reset. `tasks.jsonl` contains one reproducible seed-42 instance per family, with instructions, schema, reference SQL and independently calculated Python answers serialized in `expected_rows_json`. `data/*.sql` reconstruct those public example databases. `source/` contains the environment, generator, tests and container recipe from [source commit {revision}](https://github.com/burtenshaw/openenv-sql-investigation/tree/{revision}). Explicit reset seeds reproduce an instance; normal training samples fresh 63-bit seeds. | |
| The policy sees only its question, schema, and its own query results. It can use read-only SQLite queries and has 12 actions. `op=submit` executes final SQL and ends the episode. Reward is **1** only for the entire correct result table, otherwise **0**; row order is ignored, duplicate multiplicity and column position matter, and numeric absolute tolerance is 0.0001. Python computes the expected rows independently of the submitted SQL. `op=finish`, budget exhaustion, or an invalid final query earns 0. There is no partial credit. | |
| The public reference solutions are intended for audit and reproducibility. The runtime does not expose them through SQL tables or policy observations. SQL file access, writes, database attachment and extensions are denied; function, statement length, result length, execution-time and VM-operation limits bound each query. | |
| All ten families are training tasks for one Arena policy. This dataset does not contain Arena's private evaluation tasks, and no private evaluation improvement is claimed. The common admission example finishes with reward 0; separate oracle tests demonstrate reward 1 for correct solutions. | |
| Image: `ghcr.io/burtenshaw/openenv-sql-investigation:v1`. The Arena submission pins an immutable image digest. OpenEnv is pinned to `86a180ede21e044f7929b9a7783ad83aa67d83a3`; the image is self-contained and requires no secrets, files, volumes, GPU or external downloads at runtime. | |
| """) | |
| print(f"Prepared {len(rows)} tasks and source at {target}") | |
| if __name__ == "__main__": | |
| main() | |