Skip to content

Commit 13d4519

Browse files
committed
feat: Add step-timeout param
1 parent a04190a commit 13d4519

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ For more advanced examples, including [Triton](/examples/triton/README.md), [CUD
134134
| `-M, --model` | Model identifier for the LLM to use (e.g., `o4-mini`, `claude-sonnet-4-0`). | `o4-mini` when `OPENAI_API_KEY` is set; `claude-sonnet-4-0` when `ANTHROPIC_API_KEY` is set; `gemini-2.5-pro` when `GEMINI_API_KEY` is set. | `-M o4-mini` |
135135
| `-i, --additional-instructions`| Natural language description of specific instructions **or** path to a file containing detailed instructions to guide the LLM. | `None` | `-i instructions.md` or `-i "Optimize the model for faster inference"`|
136136
| `-l, --log-dir` | Path to the directory to log intermediate steps and final optimization result. | `.runs/` | `-l ./logs/` |
137+
| `--step-timeout` | Timeout in seconds for each optimization step. | `3600` | `--step-timeout 60` |
137138

138139
---
139140

weco/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def configure_run_parser(run_parser: argparse.ArgumentParser) -> None:
6161
type=str,
6262
help="Description of additional instruction or path to a file containing additional instructions. Defaults to None.",
6363
)
64+
run_parser.add_argument(
65+
"--step-timeout", type=int, default=3600, help="Timeout in seconds for each optimization step. Defaults to 3600."
66+
)
6467

6568

6669
def execute_run_command(args: argparse.Namespace) -> None:
@@ -77,6 +80,7 @@ def execute_run_command(args: argparse.Namespace) -> None:
7780
log_dir=args.log_dir,
7881
additional_instructions=args.additional_instructions,
7982
console=console,
83+
step_timeout=args.step_timeout,
8084
)
8185
exit_code = 0 if success else 1
8286
sys.exit(exit_code)

weco/optimizer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def execute_optimization(
7878
log_dir: str = ".runs",
7979
additional_instructions: Optional[str] = None,
8080
console: Optional[Console] = None,
81+
step_timeout: int = 3600,
8182
) -> bool:
8283
"""
8384
Execute the core optimization logic.
@@ -248,7 +249,7 @@ def signal_handler(signum, frame):
248249
)
249250

250251
# Run evaluation on the initial solution
251-
term_out = run_evaluation(eval_command=eval_command)
252+
term_out = run_evaluation(eval_command=eval_command, timeout=step_timeout)
252253
# Update the evaluation output panel
253254
eval_output_panel.update(output=term_out)
254255
smooth_update(
@@ -347,7 +348,7 @@ def signal_handler(signum, frame):
347348
],
348349
transition_delay=0.08, # Slightly longer delay for more noticeable transitions
349350
)
350-
term_out = run_evaluation(eval_command=eval_command)
351+
term_out = run_evaluation(eval_command=eval_command, timeout=step_timeout)
351352
eval_output_panel.update(output=term_out)
352353
smooth_update(
353354
live=live,

weco/utils.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,21 @@ def smooth_update(
124124

125125

126126
# Other helper functions
127-
def run_evaluation(eval_command: str) -> str:
127+
def run_evaluation(eval_command: str, timeout: int | None = None) -> str:
128128
"""Run the evaluation command on the code and return the output."""
129129

130130
# Run the eval command as is
131-
result = subprocess.run(eval_command, shell=True, capture_output=True, text=True, check=False)
132-
133-
# Combine stdout and stderr for complete output
134-
output = result.stderr if result.stderr else ""
135-
if result.stdout:
136-
if len(output) > 0:
137-
output += "\n"
138-
output += result.stdout
139-
return output
131+
try:
132+
result = subprocess.run(eval_command, shell=True, capture_output=True, text=True, check=False, timeout=timeout)
133+
# Combine stdout and stderr for complete output
134+
output = result.stderr if result.stderr else ""
135+
if result.stdout:
136+
if len(output) > 0:
137+
output += "\n"
138+
output += result.stdout
139+
return output
140+
except subprocess.TimeoutExpired:
141+
return f"Evaluation timed out after {timeout} seconds."
140142

141143

142144
# Update Check Function

0 commit comments

Comments
 (0)