-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: "solve" updates #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
from filelock import FileLock | ||
|
||
datasets_dir = Path(__file__).parent / "datasets" | ||
output_file = None | ||
|
||
|
||
def load_data(dataset_name, split) -> tuple[DatasetDict, str]: | ||
|
@@ -29,33 +28,41 @@ def load_data(dataset_name, split) -> tuple[DatasetDict, str]: | |
|
||
|
||
def solve_instance(data): | ||
# Check that this is defined | ||
output_file = data["output_file"] | ||
|
||
for instance in data["task_instances"]: | ||
# Create a temporary directory to store the problem statement and the working files | ||
issue_dir = Path(data["testbed"]) / instance["instance_id"] | ||
issue_dir.mkdir(parents=True, exist_ok=True) | ||
issue_file = issue_dir / "issue.txt" | ||
with open(issue_file, "w") as f: | ||
f.write(instance["problem_statement"]) | ||
|
||
try: | ||
with NamedTemporaryFile(mode="w", dir=data["testbed"], prefix="issue_", suffix=".txt") as f: | ||
f.write(instance["problem_statement"]) | ||
f.flush() | ||
run( | ||
[ | ||
"python", | ||
abspath(args.solver_path), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
data["testbed"], | ||
f.name, | ||
"--appmap-command", | ||
args.appmap_command, | ||
], | ||
check=True, | ||
cwd=data["testbed"], | ||
) | ||
output = run(["git", "--no-pager", "diff"], check=True, cwd=data["testbed"], capture_output=True, text=True) | ||
if output.stdout: | ||
instance["model_patch"] = output.stdout | ||
instance["model_name_or_path"] = "navie" | ||
with FileLock(f"{output_file}.lock"): | ||
with open(output_file, "a+") as f: | ||
f.write(json.dumps(instance) + "\n") | ||
run( | ||
[ | ||
"python", | ||
abspath(data["solver_path"]), | ||
data["testbed"], | ||
str(issue_file), | ||
"--appmap-command", | ||
data["appmap_command"] | ||
], | ||
check=True, | ||
cwd=data["testbed"], | ||
) | ||
output = run(["git", "--no-pager", "diff"], check=True, cwd=data["testbed"], capture_output=True, text=True) | ||
if output.stdout: | ||
instance["model_patch"] = output.stdout | ||
instance["model_name_or_path"] = "navie" | ||
with FileLock(f"{output_file}.lock"): | ||
with open(output_file, "a+") as f: | ||
f.write(json.dumps(instance) + "\n") | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
|
||
import traceback | ||
print(f"Error processing {instance['instance_id']}") | ||
traceback.print_exc() | ||
|
||
def solve_instances(instances, args): | ||
if args.filter is not None: | ||
|
@@ -68,6 +75,7 @@ def solve_instances(instances, args): | |
{ | ||
"task_instances": g, | ||
"func": solve_instance, | ||
"output_file": args.output, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alias |
||
**vars(args), | ||
} | ||
for g in instance_groups | ||
|
@@ -83,14 +91,13 @@ def solve_instances(instances, args): | |
pool.join() | ||
|
||
def main(args): | ||
dataset = load_data(args.instances, args.split) | ||
global output_file | ||
output_file = args.output | ||
dataset = load_data(args.instances_path, args.split) | ||
solve_instances(dataset, args) | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--instances_path", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"--instances", | ||
type=str, | ||
help="path or huggingface name of task instances dataset", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary reason for putting this information in a directory is that the logs will remain available - and there can be a lot of logs per issue that are very useful to pick through if something doesn't go right.