Skip to content

Commit eb70749

Browse files
add docs for some functions, remove unused imports
1 parent ee697e4 commit eb70749

4 files changed

Lines changed: 30 additions & 11 deletions

File tree

src/codeevolve/evolution.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def select_parents(
4444
evolve_config: Dict[str, Any],
4545
gen_init_pop: bool,
4646
exploration: bool,
47-
epoch: int,
4847
logger: logging.Logger,
4948
) -> Tuple[Program, Program, List[Program]]:
5049
"""
@@ -72,7 +71,6 @@ def select_parents(
7271
- migration_interval: Epochs between migrations (default: 20)
7372
gen_init_pop: Whether currently generating initial population
7473
exploration: Whether in exploration mode (vs exploitation)
75-
epoch: Current epoch number
7674
logger: Logger for recording selection decisions
7775
7876
Returns:
@@ -653,7 +651,6 @@ async def evolve_loop(
653651
evolve_config=evolve_config,
654652
gen_init_pop=gen_init_pop,
655653
exploration=exploration,
656-
epoch=epoch,
657654
logger=logger,
658655
)
659656

src/codeevolve/prompt/sampler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from typing import Dict, List, Tuple, Optional
1414
from collections import deque
15-
import logging
1615

1716
from codeevolve.lm import OpenAILM
1817
from codeevolve.database import Program, ProgramDatabase

src/codeevolve/scheduler.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# ===--------------------------------------------------------------------------------------===#
1212

13-
from typing import Any, Callable, Dict, List, Optional
13+
from typing import Dict, Optional
1414
from abc import ABC, abstractmethod
1515

1616
import numpy as np
@@ -264,18 +264,45 @@ def reset(self, exploration_rate: Optional[float] = None) -> None:
264264

265265

266266
class CosineScheduler(ExplorationRateScheduler):
267-
""" """
267+
"""Cosine annealing scheduler that oscillates exploration rate periodically.
268+
269+
This scheduler uses a cosine wave to smoothly vary the exploration rate
270+
between min_rate and max_rate over a fixed cycle length, allowing for
271+
periodic transitions between exploration and exploitation.
272+
273+
Attributes:
274+
cycle_length: Number of epochs for one complete cosine cycle.
275+
"""
268276

269277
def __init__(
270278
self, exploration_rate: float, max_rate: float, min_rate: float, cycle_length: int
271279
):
280+
"""Initialize the cosine annealing scheduler.
281+
282+
Args:
283+
exploration_rate: Initial exploration rate.
284+
max_rate: Maximum exploration rate bound.
285+
min_rate: Minimum exploration rate bound.
286+
cycle_length: Number of epochs per complete cosine cycle.
287+
288+
Raises:
289+
ValueError: If cycle_length is not positive.
290+
"""
272291
super().__init__(exploration_rate, max_rate, min_rate)
273292
if cycle_length <= 0:
274293
raise ValueError(f"cycle_length ({cycle_length}) must be positive")
275294
self.cycle_length = cycle_length
276295

277296
def __call__(self, epoch: int, **kwargs) -> float:
278-
""" """
297+
"""Compute exploration rate using cosine annealing.
298+
299+
Args:
300+
epoch: Current epoch number.
301+
**kwargs: Additional arguments (ignored).
302+
303+
Returns:
304+
Updated exploration rate following cosine wave.
305+
"""
279306
cycle_progress: float = (epoch % self.cycle_length) / self.cycle_length
280307
cosine_factor: float = 0.5 * (1 + np.cos(np.pi * cycle_progress))
281308
rate: float = self.min_rate + (self.max_rate - self.min_rate) * cosine_factor

src/codeevolve/utils/logging_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222

2323
from codeevolve.islands import GlobalData
2424

25-
from typing import Optional
26-
import logging
27-
28-
2925
class SizeLimitedFormatter(logging.Formatter):
3026
"""Custom logging formatter that enforces a maximum message size.
3127

0 commit comments

Comments
 (0)