Skip to content

Commit b50a4d5

Browse files
authored
Merge pull request #35 from commit-0/docs2
Update docs / include --cfg in cli
2 parents b65f265 + 9e68977 commit b50a4d5

File tree

8 files changed

+318
-24
lines changed

8 files changed

+318
-24
lines changed

commit0/__main__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from hydra.core.config_store import ConfigStore
1212
from commit0.configs.config_class import Commit0Config
1313
from commit0.harness.constants import COMMANDS, SPLIT
14+
from omegaconf import OmegaConf
1415

1516

1617
def main() -> None:
@@ -24,9 +25,17 @@ def main() -> None:
2425
cs.store(name="user", group="Commit0Config", node=Commit0Config)
2526
# have hydra to ignore all command-line arguments
2627
sys_argv = copy.deepcopy(sys.argv)
27-
sys.argv = [sys.argv[0]]
28+
cfg_arg = next((arg for arg in sys_argv if arg.startswith("--cfg=")), None)
29+
2830
hydra.initialize(version_base=None, config_path="configs")
2931
config = hydra.compose(config_name="user")
32+
33+
if cfg_arg:
34+
sys_argv.remove(cfg_arg)
35+
config_name = cfg_arg.split("=")[1]
36+
user_config = OmegaConf.load(config_name)
37+
config = OmegaConf.merge(config, user_config)
38+
3039
# after hydra gets all configs, put command-line arguments back
3140
sys.argv = sys_argv
3241
# repo_split: split from command line has a higher priority than split in hydra

commit0/harness/docker_build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from concurrent.futures import ThreadPoolExecutor, as_completed
88
from pathlib import Path
99
from typing import Any
10+
import sys
1011

1112
from commit0.harness.constants import (
1213
BASE_IMAGE_BUILD_DIR,
@@ -39,6 +40,8 @@ def setup_logger(repo: str, log_file: Path, mode: str = "w") -> logging.Logger:
3940
log_file.parent.mkdir(parents=True, exist_ok=True)
4041
logger = logging.getLogger(f"{repo}.{log_file.name}")
4142
handler = logging.FileHandler(log_file, mode=mode)
43+
stdout_handler = logging.StreamHandler(sys.stdout)
44+
logger.addHandler(stdout_handler)
4245
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
4346
handler.setFormatter(formatter)
4447
logger.addHandler(handler)

commit0/harness/run_pytest_ids.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ def main(
100100
eval_file.write_text(eval_script)
101101

102102
if ExecutionBackend(backend) == ExecutionBackend.MODAL:
103+
logger.info("Runnning on Modal")
103104
execution_context = Modal
104105
elif ExecutionBackend(backend) == ExecutionBackend.LOCAL:
106+
logger.info("Runnning locally")
105107
execution_context = Docker
106108
else:
107109
raise ValueError(

docs/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Spec2Repo is made by ...
1+
Commit0 is ..

docs/distributed.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Distributed
2+
3+
One of the main advantages of `commit0` is that it can run
4+
a range of unit tests in distributed environments.
5+
6+
By default, the library is configured to work with [modal](https://modal.com/).
7+
8+
```bash
9+
pip install modal
10+
modal token new
11+
```
12+
13+
## Modal Setup
14+
15+
To enable distributed run, first
16+
create a file called `distributed.yaml`
17+
18+
```yaml
19+
backend: modal
20+
base_dir: repos.dist/
21+
```
22+
23+
You can pass this configuration file as an argumnet to clone.
24+
25+
```bash
26+
commit0 clone lite --cfg=distributed
27+
```
28+
29+
Next to run tests you can run the standard test command.
30+
31+
```bash
32+
commit0 test simpy master tests/test_event.py::test_succeed --cfg=distributed
33+
```

docs/index.md

Lines changed: 73 additions & 5 deletions
Large diffs are not rendered by default.

docs/make_md.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import datasets
2+
import subprocess
3+
4+
import requests
5+
from bs4 import BeautifulSoup
6+
7+
def get_github_avatar(repo):
8+
"""
9+
Given a GitHub repo in the format 'owner/repo', get the avatar URL of the organization or user.
10+
"""
11+
try:
12+
org = repo.split("/")[0]
13+
# Construct the URL for the repo
14+
url = f"https://github.com/{org}"
15+
16+
# Make a request to the page
17+
response = requests.get(url)
18+
19+
# Check if the request was successful
20+
if response.status_code != 200:
21+
print(f"Failed to fetch page for {repo}. Status code: {response.status_code}")
22+
return None
23+
24+
# Parse the HTML content using BeautifulSoup
25+
soup = BeautifulSoup(response.content, 'html.parser')
26+
27+
# Find the meta tag with property "og:image" which contains the avatar URL
28+
meta_tag = soup.find('meta', property='og:image')
29+
30+
if meta_tag and 'content' in meta_tag.attrs:
31+
avatar_url = meta_tag['content']
32+
return avatar_url
33+
else:
34+
print(f"Avatar URL not found for {repo}")
35+
return None
36+
37+
except Exception as e:
38+
print(f"An error occurred: {e}")
39+
return None
40+
41+
d = datasets.load_dataset("wentingzhao/commit0_docstring", split="test")
42+
43+
print(d)
44+
45+
46+
47+
print("| | Name | Repo | Commit0 | Tests | | ")
48+
print("|--|--------|-------|----|----|------| ")
49+
overload = {
50+
"simpy" : "https://simpy.readthedocs.io/en/4.1.1/_images/simpy-logo-small.png",
51+
"tinydb" : "https://raw.githubusercontent.com/msiemens/tinydb/master/artwork/logo.png",
52+
"bitstring": "https://bitstring.readthedocs.io/en/stable/_images/bitstring_logo.png",
53+
"seaborn": "https://raw.githubusercontent.com/mwaskom/seaborn/master/doc/_static/logo-wide-lightbg.svg",
54+
"statsmodels": "https://raw.githubusercontent.com/statsmodels/statsmodels/main/docs/source/images/statsmodels-logo-v2-horizontal.svg",
55+
"pyboy" : "https://github.com/Baekalfen/PyBoy/raw/master/extras/README/pyboy.svg",
56+
}
57+
skip = {
58+
"pyjwt",
59+
"wcwidth",
60+
"chardet",
61+
"dnspython",
62+
"imapclient",
63+
"pexpect",
64+
"dulwich",
65+
"voluptuous",
66+
"requests",
67+
"tlslite-ng",
68+
"more-itertools",
69+
"deprecated",
70+
"cachetools",
71+
"paramiko",
72+
"jedi",
73+
"sqlparse",
74+
}
75+
for i, ex in enumerate(d):
76+
img = get_github_avatar(ex["original_repo"])
77+
78+
name = ex["repo"].split("/")[1]
79+
result = subprocess.check_output(f"commit0 get-tests {name} | wc", shell=True, text=True)
80+
81+
tests = int(result.split()[0])
82+
if name.lower() not in skip and name.lower() not in overload:
83+
img = f"<img src='{img}' width='100px'/>"
84+
elif name.lower() in overload:
85+
img = f"<img src='{overload[name.lower()]}' width='100px'/>"
86+
else:
87+
img = f"<b>{name}</b>"
88+
print(f"| {img} | [{name}]({ex['setup']['specification']}) | [[orig](http://github.com/{ex['original_repo']})] | [[commit0](http://github.com/{ex['repo']})] | {tests} | <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAABkCAQAAADtJZLrAAAAD0lEQVR42mNkYGAcRcQhADxaAGWhD8eHAAAAAElFTkSuQmCC'/> |")

docs/setup.md

Lines changed: 108 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Quickstart
2+
3+
## Install
4+
15
First be sure that you have docker tools installed.
26

37
```bash
@@ -7,42 +11,129 @@ apt install docker
711
To install the benchmark run,
812

913
```bash
10-
pip install spec2repo
14+
pip install commit0
1115
```
1216

13-
Then run
17+
## Commands
18+
19+
The system is a command-line tool that allows you to run unit-tests on a
20+
variety of libraries in isolated environments. To get started with the full
21+
setup run the `clone` command which will install a clone the code of a subset
22+
of libraries to your `repos/` directory.
1423

1524
```bash
16-
spec2repo new local
25+
commit0 clone lit
1726
```
1827

19-
This will generate a file `spec2repo.yml` in your project.
20-
To launch the benchmark suite run
28+
Next run the `build` command which will configure Docker containers for
29+
each of the libraries with isolated virtual environments. The command uses the
30+
[uv](https://github.com/astral-sh/uv) library for efficient builds.
2131

2232
```bash
23-
spec2repo launch
33+
commit0 build lit
2434
```
2535

26-
This will launch a set of docker instances for each of the repos as well as a
27-
local master.
36+
The main operation you can do with these enviroments is to run tests.
37+
Here we run [a test](https://github.com/commit-0/simpy/blob/master/tests/test_event.py#L11) in the `simpy` library.
38+
39+
```bash
40+
commit0 test simpy tests/test_event.py::test_succeed
41+
```
2842

29-
Now let's apply a patch to one of our repos:
43+
This test should run and pass, but others will fail.
44+
45+
```bash
46+
commit0 test minitorch tests/test_operators.py::test_relu
47+
```
48+
49+
Let's now manually go in and change that repo.
50+
This is all just standard shell commands.
3051

3152
```bash
3253
cd repos/minitorch/
33-
git checkout -b first_change
34-
patch ../../minitorch.example.patch .
35-
spec2repo test minitorch first_change test_add
54+
git checkout -b mychange
3655
```
3756

38-
This will run the `test_add` in the MiniTorch Repository and show the results.
57+
And apply and commit this patch.
3958

40-
To get your current score on a repository you can run
59+
```
60+
--- a/minitorch/operators.py
61+
+++ b/minitorch/operators.py
62+
@@ -81,7 +81,7 @@ def relu(x: float) -> float:
63+
(See https://en.wikipedia.org/wiki/Rectifier_(neural_networks) .)
64+
"""
65+
# TODO: Implement for Task 0.1.
66+
- raise NotImplementedError('Need to implement for Task 0.1')
67+
+ return 1. if x > 0. else 0.
68+
```
69+
70+
Once this is done we can run `test` with
71+
a branch and the environment will sync and run.
72+
73+
```bash
74+
commit0 test minitorch branch=mychange tests/test_operators.py::test_relu
75+
```
76+
77+
## Running an Agent
78+
79+
Next we will see how this can be run with an AI agent system.
80+
We will use [Aider](https://aider.chat/) which is a nice
81+
command-line oriented agent system.
82+
83+
To setup Aider first set your api key.
84+
We recommend using Claude Sonnet.
4185

4286
```bash
43-
spec2repo score minitorch
87+
# Work with Claude 3.5 Sonnet on your repo
88+
export ANTHROPIC_API_KEY=your-key-goes-here
4489
```
4590

46-
## Running Aider
91+
Once this is setup you can run Aider with the following command.
92+
This will edit the files locally in your branch, but
93+
run the tests inside the environment.
4794

48-
...
95+
```bash
96+
aider --model sonnet --file repos/minitorch/operators.py --message "fill in" \
97+
--auto-test --test \
98+
--test-cmd 'commit0 test minitorch branch=mychange tests/test_operators.py::test_relu' \
99+
--yes
100+
```
101+
102+
This will run an LLM agent that will try to fill in the
103+
functions in one file of the minitorch library.
104+
105+
For a full example baseline system that tries to solve
106+
all the tests in the library see the [baseline](baseline) documentation.
107+
108+
109+
## Distributed Tests
110+
111+
One of the main advantages of `commit0` is that it can run
112+
a range of unit tests in distributed environments.
113+
114+
By default, the library is configured to work with [modal](https://modal.com/).
115+
116+
```bash
117+
pip install modal
118+
modal token new
119+
```
120+
121+
To enable distributed run, first
122+
create a file called `distributed.yaml`
123+
124+
```yaml
125+
backend: modal
126+
base_dir: repos.dist/
127+
```
128+
129+
You can pass this configuration file as an argumnet to clone.
130+
131+
```bash
132+
commit0 clone lite --cfg=distributed.yaml
133+
```
134+
135+
Next to run tests you can run the standard test command.
136+
137+
```bash
138+
commit0 test simpy master tests/test_event.py::test_succeed --cfg=distributed.yaml
139+
```

0 commit comments

Comments
 (0)