Skip to content

Commit dbdd0e1

Browse files
committed
OmegaConf integration
1 parent 3ed0d9a commit dbdd0e1

File tree

4 files changed

+75
-89
lines changed

4 files changed

+75
-89
lines changed

commit0/harness/run_pytest_ids.py

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
from datasets import load_dataset
23
import docker
34
from enum import StrEnum, auto
45
import modal
@@ -7,6 +8,9 @@
78
import yaml
89
from pathlib import Path
910

11+
from omegaconf import DictConfig, OmegaConf
12+
import hydra
13+
1014
from commit0.harness.constants import RUN_PYTEST_LOG_DIR
1115
from commit0.harness.docker_build import (
1216
close_logger,
@@ -32,7 +36,7 @@
3236

3337

3438
class ExecutionBackend(StrEnum):
35-
DOCKER = auto()
39+
LOCAL = auto()
3640
MODAL = auto()
3741

3842

@@ -188,62 +192,38 @@ def run_modal(spec, logger, eval_file, timeout, log_dir):
188192
)
189193

190194

191-
def main(
192-
repo: str,
193-
test_ids: list[str],
194-
timeout: int,
195-
branch_name: str,
196-
backend: ExecutionBackend,
197-
) -> None:
198-
with open("config.yml", "r") as file:
199-
data = yaml.safe_load(file)
200-
spec = make_spec(data["repos"][repo])
201-
test_ids = " ".join(test_ids)
202-
hashed_test_ids = get_hash_string(test_ids)
195+
@hydra.main(version_base=None, config_path="configs", config_name="base")
196+
def main(config: DictConfig) -> None:
197+
OmegaConf.to_yaml(config)
198+
dataset = load_dataset(config.dataset_name, split="test")
199+
for example in dataset:
200+
if example["repo"].endswith(config.repo):
201+
spec = make_spec(example)
202+
break
203203

204+
hashed_test_ids = get_hash_string(config.test_ids)
204205
# set up logging
205-
log_dir = RUN_PYTEST_LOG_DIR / repo / hashed_test_ids
206+
log_dir = RUN_PYTEST_LOG_DIR / config.repo / hashed_test_ids
206207
log_dir.mkdir(parents=True, exist_ok=True)
207208
log_file = log_dir / "run_pytest.log"
208-
logger = setup_logger(repo, log_file)
209+
logger = setup_logger(config.repo, log_file)
209210

210211
# make eval file
211212
eval_script = spec.eval_script.format(
212-
local_repo=f"{data['base_repo_dir']}/{repo}",
213-
branch_name=branch_name,
214-
test_ids=test_ids,
215-
ip=get_ip(data["backend"]),
213+
local_repo=f"{config.base_dir}/{config.repo}",
214+
branch_name=config.branch,
215+
test_ids=config.test_ids,
216+
ip=get_ip(config.backend),
216217
user=get_user(),
217218
)
218219
eval_file = Path(log_dir / "eval.sh")
219220
eval_file.write_text(eval_script)
220221

221-
if ExecutionBackend(backend) == ExecutionBackend.DOCKER:
222-
run_docker(spec, logger, eval_file, timeout, log_dir)
223-
elif ExecutionBackend(backend) == ExecutionBackend.MODAL:
224-
run_modal(spec, logger, eval_file, timeout, log_dir)
222+
if ExecutionBackend(config.backend) == ExecutionBackend.LOCAL:
223+
run_docker(spec, logger, eval_file, config.timeout, log_dir)
224+
elif ExecutionBackend(config.backend) == ExecutionBackend.MODAL:
225+
run_modal(spec, logger, eval_file, config.timeout, log_dir)
225226

226227

227228
if __name__ == "__main__":
228-
parser = argparse.ArgumentParser()
229-
parser.add_argument("--repo", type=str, help="which repo to run unit tests")
230-
parser.add_argument(
231-
"--test_ids", type=str, nargs="+", help="which test ids / files / directories"
232-
)
233-
parser.add_argument(
234-
"--branch_name", type=str, help="which git branch to run unit tests"
235-
)
236-
parser.add_argument(
237-
"--timeout",
238-
type=int,
239-
default=1_800,
240-
help="Timeout (in seconds) for running tests for each instance",
241-
)
242-
parser.add_argument(
243-
"--backend",
244-
choices=[backend.value for backend in ExecutionBackend],
245-
default=ExecutionBackend.DOCKER.value,
246-
help="Execution backend [docker, modal]",
247-
)
248-
args = parser.parse_args()
249-
main(**vars(args))
229+
main()

commit0/harness/setup.py

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,50 @@
1-
import argparse
21
import logging
32
import os
43

54
import docker
65
import yaml
76
from datasets import load_dataset
87

8+
from omegaconf import DictConfig, OmegaConf
9+
import hydra
10+
911
from commit0.harness.utils import clone_repo, create_branch
1012
from commit0.harness.constants import REPO_IMAGE_BUILD_DIR
1113
from commit0.harness.docker_build import build_repo_images
1214
from commit0.harness.spec import make_spec
1315

16+
1417
logging.basicConfig(
1518
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
1619
)
1720
logger = logging.getLogger(__name__)
1821

1922

20-
def main(hf_name: str, base_dir: str, config_file: str, backend: str, repo: str) -> None:
21-
dataset = load_dataset(hf_name, split="test")
23+
@hydra.main(version_base=None, config_path="configs", config_name="base")
24+
def main(config: DictConfig) -> None:
25+
OmegaConf.to_yaml(config)
26+
dataset = load_dataset(config.dataset_name, split="test")
2227
out = dict()
23-
out["backend"] = backend
24-
out["base_repo_dir"] = base_dir
25-
out["repos"] = dict()
28+
out["backend"] = config.backend
29+
out["base_repo_dir"] = config.base_dir
2630
specs = []
2731
for example in dataset:
2832
repo_name = example["repo"].split("/")[-1]
29-
if repo != "all" and repo_name != repo:
33+
if config.build != "all" and repo_name != repo:
3034
logger.info(f"Skipping {repo_name}")
3135
continue
3236
spec = make_spec(example)
3337
specs.append(spec)
34-
out["repos"][repo_name] = example
3538
clone_url = f"https://github.com/{example['repo']}.git"
3639
clone_dir = os.path.join(out["base_repo_dir"], repo_name)
3740
repo = clone_repo(clone_url, clone_dir, example["base_commit"], logger)
38-
create_branch(repo, "aider", logger)
41+
create_branch(repo, config.branch, logger)
3942

40-
config_file = os.path.abspath(config_file)
41-
with open(config_file, "w") as f:
42-
yaml.dump(out, f, default_flow_style=False)
43-
logger.info(f"Config file has been written to {config_file}")
4443
logger.info("Start building docker images")
4544
logger.info(f"Please check {REPO_IMAGE_BUILD_DIR} for build details")
4645
client = docker.from_env()
4746
build_repo_images(client, specs)
4847
logger.info("Done building docker images")
4948

50-
51-
if __name__ == "__main__":
52-
parser = argparse.ArgumentParser()
53-
parser.add_argument("--hf_name", type=str, help="HF dataset name")
54-
parser.add_argument(
55-
"--base_dir",
56-
type=str,
57-
default="repos/",
58-
help="base directory to write repos to",
59-
)
60-
parser.add_argument(
61-
"--config_file",
62-
type=str,
63-
default="config.yml",
64-
help="where to write config file to",
65-
)
66-
parser.add_argument(
67-
"--backend",
68-
type=str,
69-
choices=["local", "modal"],
70-
default="modal",
71-
help="specify evaluation backend to be local or modal (remote)",
72-
)
73-
parser.add_argument(
74-
"--repo",
75-
type=str,
76-
default="all",
77-
help="which repos to setup. all or one from dataset",
78-
)
79-
args = parser.parse_args()
80-
main(**vars(args))
49+
if __name__ == '__main__':
50+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies = [
2323
"wget",
2424
"ruff>=0.6.4",
2525
"pre-commit>=3.8.0",
26+
"hydra-core>=1.3.2",
2627
]
2728

2829
[tool.pyright]

uv.lock

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)