Skip to content

Commit 456c07a

Browse files
committed
linter
1 parent 5622df8 commit 456c07a

File tree

3 files changed

+37
-40
lines changed

3 files changed

+37
-40
lines changed

openevolve/cli.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,19 @@ def parse_args() -> argparse.Namespace:
4444
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
4545
default="INFO",
4646
)
47-
47+
4848
parser.add_argument(
4949
"--checkpoint",
5050
help="Path to checkpoint directory to resume from (e.g., openevolve_output/checkpoints/checkpoint_50)",
51-
default=None
52-
)
53-
54-
parser.add_argument(
55-
"--api-base",
56-
help="Base URL for the LLM API",
57-
default=None
58-
)
59-
60-
parser.add_argument(
61-
"--primary-model",
62-
help="Primary LLM model name",
63-
default=None
51+
default=None,
6452
)
65-
66-
parser.add_argument(
67-
"--secondary-model",
68-
help="Secondary LLM model name",
69-
default=None
70-
)
71-
53+
54+
parser.add_argument("--api-base", help="Base URL for the LLM API", default=None)
55+
56+
parser.add_argument("--primary-model", help="Primary LLM model name", default=None)
57+
58+
parser.add_argument("--secondary-model", help="Secondary LLM model name", default=None)
59+
7260
return parser.parse_args()
7361

7462

@@ -118,16 +106,18 @@ async def main_async() -> int:
118106
config_path=args.config if config is None else None,
119107
output_dir=args.output,
120108
)
121-
109+
122110
# Load from checkpoint if specified
123111
if args.checkpoint:
124112
if not os.path.exists(args.checkpoint):
125113
print(f"Error: Checkpoint directory '{args.checkpoint}' not found")
126114
return 1
127115
print(f"Loading checkpoint from {args.checkpoint}")
128116
openevolve.database.load(args.checkpoint)
129-
print(f"Checkpoint loaded successfully (iteration {openevolve.database.last_iteration})")
130-
117+
print(
118+
f"Checkpoint loaded successfully (iteration {openevolve.database.last_iteration})"
119+
)
120+
131121
# Override log level if specified
132122
if args.log_level:
133123
logging.getLogger().setLevel(getattr(logging, args.log_level))
@@ -137,25 +127,30 @@ async def main_async() -> int:
137127
iterations=args.iterations,
138128
target_score=args.target_score,
139129
)
140-
130+
141131
# Get the checkpoint path
142132
checkpoint_dir = os.path.join(openevolve.output_dir, "checkpoints")
143133
latest_checkpoint = None
144134
if os.path.exists(checkpoint_dir):
145-
checkpoints = [os.path.join(checkpoint_dir, d) for d in os.listdir(checkpoint_dir)
146-
if os.path.isdir(os.path.join(checkpoint_dir, d))]
135+
checkpoints = [
136+
os.path.join(checkpoint_dir, d)
137+
for d in os.listdir(checkpoint_dir)
138+
if os.path.isdir(os.path.join(checkpoint_dir, d))
139+
]
147140
if checkpoints:
148-
latest_checkpoint = sorted(checkpoints, key=lambda x: int(x.split("_")[-1]) if "_" in x else 0)[-1]
149-
141+
latest_checkpoint = sorted(
142+
checkpoints, key=lambda x: int(x.split("_")[-1]) if "_" in x else 0
143+
)[-1]
144+
150145
print(f"\nEvolution complete!")
151146
print(f"Best program metrics:")
152147
for name, value in best_program.metrics.items():
153148
print(f" {name}: {value:.4f}")
154-
149+
155150
if latest_checkpoint:
156151
print(f"\nLatest checkpoint saved at: {latest_checkpoint}")
157152
print(f"To resume, use: --checkpoint {latest_checkpoint}")
158-
153+
159154
return 0
160155

161156
except Exception as e:

openevolve/controller.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ async def run(
156156
# Main evolution loop
157157
start_iteration = self.database.last_iteration
158158
total_iterations = start_iteration + max_iterations
159-
160-
logger.info(f"Starting evolution from iteration {start_iteration} for {max_iterations} iterations (total: {total_iterations})")
161-
159+
160+
logger.info(
161+
f"Starting evolution from iteration {start_iteration} for {max_iterations} iterations (total: {total_iterations})"
162+
)
163+
162164
for i in range(start_iteration, total_iterations):
163165
iteration_start = time.time()
164166

@@ -354,7 +356,7 @@ def _save_checkpoint(self, iteration: int) -> None:
354356
# Save the database
355357
checkpoint_path = os.path.join(checkpoint_dir, f"checkpoint_{iteration}")
356358
self.database.save(checkpoint_path, iteration)
357-
359+
358360
logger.info(f"Saved checkpoint at iteration {iteration} to {checkpoint_path}")
359361

360362
def _save_best_program(self, program: Optional[Program] = None) -> None:

openevolve/database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ def __init__(self, config: DatabaseConfig):
8080

8181
# Track the absolute best program separately
8282
self.best_program_id: Optional[str] = None
83-
83+
8484
# Track the last iteration number (for resuming)
8585
self.last_iteration: int = 0
86-
86+
8787
# Load database from disk if path is provided
8888
if config.db_path and os.path.exists(config.db_path):
8989
self.load(config.db_path)
@@ -255,7 +255,7 @@ def get_top_programs(self, n: int = 10, metric: Optional[str] = None) -> List[Pr
255255
)
256256

257257
return sorted_programs[:n]
258-
258+
259259
def save(self, path: Optional[str] = None, iteration: int = 0) -> None:
260260
"""
261261
Save the database to disk
@@ -312,9 +312,9 @@ def load(self, path: str) -> None:
312312
self.archive = set(metadata.get("archive", []))
313313
self.best_program_id = metadata.get("best_program_id")
314314
self.last_iteration = metadata.get("last_iteration", 0)
315-
315+
316316
logger.info(f"Loaded database metadata with last_iteration={self.last_iteration}")
317-
317+
318318
# Load programs
319319
programs_dir = os.path.join(path, "programs")
320320
if os.path.exists(programs_dir):

0 commit comments

Comments
 (0)