MCPcopy Create free account
hub / github.com/FareedKhan-dev/ai-long-task / _update_island_best_program

Method _update_island_best_program

data/database.py:1224–1274  ·  view source on GitHub ↗

Update the best program tracking for a specific island Args: program: Program to consider as the new best for the island island_idx: Island index

(self, program: Program, island_idx: int)

Source from the content-addressed store, hash-verified

1222 logger.info(f"New best program {program.id} replaces {old_id}")
1223
1224 def _update_island_best_program(self, program: Program, island_idx: int) -> None:
1225 """
1226 Update the best program tracking for a specific island
1227
1228 Args:
1229 program: Program to consider as the new best for the island
1230 island_idx: Island index
1231 """
1232 # Ensure island_idx is valid
1233 if island_idx >= len(self.island_best_programs):
1234 logger.warning(f"Invalid island index {island_idx}, skipping island best update")
1235 return
1236
1237 # If island doesn't have a best program yet, this becomes the best
1238 current_island_best_id = self.island_best_programs[island_idx]
1239 if current_island_best_id is None:
1240 self.island_best_programs[island_idx] = program.id
1241 logger.debug(f"Set initial best program for island {island_idx} to {program.id}")
1242 return
1243
1244 # Check if current best still exists
1245 if current_island_best_id not in self.programs:
1246 logger.warning(
1247 f"Island {island_idx} best program {current_island_best_id} no longer exists, updating to {program.id}"
1248 )
1249 self.island_best_programs[island_idx] = program.id
1250 return
1251
1252 current_island_best = self.programs[current_island_best_id]
1253
1254 # Update if the new program is better
1255 if self._is_better(program, current_island_best):
1256 old_id = current_island_best_id
1257 self.island_best_programs[island_idx] = program.id
1258
1259 # Log the change
1260 if (
1261 "combined_score" in program.metrics
1262 and "combined_score" in current_island_best.metrics
1263 ):
1264 old_score = current_island_best.metrics["combined_score"]
1265 new_score = program.metrics["combined_score"]
1266 score_diff = new_score - old_score
1267 logger.debug(
1268 f"Island {island_idx}: New best program {program.id} replaces {old_id} "
1269 f"(combined_score: {old_score:.4f} → {new_score:.4f}, +{score_diff:.4f})"
1270 )
1271 else:
1272 logger.debug(
1273 f"Island {island_idx}: New best program {program.id} replaces {old_id}"
1274 )
1275
1276 def _sample_parent(self) -> Program:
1277 """

Callers 1

addMethod · 0.95

Calls 1

_is_betterMethod · 0.95

Tested by

no test coverage detected