@@ -248,7 +248,9 @@ def add(
248248 if existing_program_id in self .programs :
249249 existing_program = self .programs [existing_program_id ]
250250 new_fitness = get_fitness_score (program .metrics , self .config .feature_dimensions )
251- existing_fitness = get_fitness_score (existing_program .metrics , self .config .feature_dimensions )
251+ existing_fitness = get_fitness_score (
252+ existing_program .metrics , self .config .feature_dimensions
253+ )
252254 logger .info (
253255 "MAP-Elites cell improved: %s (fitness: %.3f -> %.3f)" ,
254256 coords_dict ,
@@ -290,7 +292,7 @@ def add(
290292 else :
291293 # No parent and no target specified, use current island
292294 island_idx = self .current_island
293-
295+
294296 island_idx = island_idx % len (self .islands ) # Ensure valid island
295297 self .islands [island_idx ].add (program .id )
296298
@@ -547,7 +549,7 @@ def load(self, path: str) -> None:
547549 self .current_island = metadata .get ("current_island" , 0 )
548550 self .island_generations = metadata .get ("island_generations" , [0 ] * len (saved_islands ))
549551 self .last_migration_generation = metadata .get ("last_migration_generation" , 0 )
550-
552+
551553 # Load feature_stats for MAP-Elites grid stability
552554 self .feature_stats = self ._deserialize_feature_stats (metadata .get ("feature_stats" , {}))
553555
@@ -839,7 +841,7 @@ def _feature_coords_to_key(self, coords: List[int]) -> str:
839841 def _is_better (self , program1 : Program , program2 : Program ) -> bool :
840842 """
841843 Determine if program1 has better FITNESS than program2
842-
844+
843845 Uses fitness calculation that excludes MAP-Elites feature dimensions
844846 to prevent pollution of fitness comparisons.
845847
@@ -901,7 +903,8 @@ def _update_archive(self, program: Program) -> None:
901903 # Find worst program among valid programs
902904 if valid_archive_programs :
903905 worst_program = min (
904- valid_archive_programs , key = lambda p : get_fitness_score (p .metrics , self .config .feature_dimensions )
906+ valid_archive_programs ,
907+ key = lambda p : get_fitness_score (p .metrics , self .config .feature_dimensions ),
905908 )
906909
907910 # Replace if new program is better
@@ -1848,7 +1851,7 @@ def _scale_feature_value_minmax(self, feature_name: str, value: float) -> float:
18481851 def _serialize_feature_stats (self ) -> Dict [str , Any ]:
18491852 """
18501853 Serialize feature_stats for JSON storage
1851-
1854+
18521855 Returns:
18531856 Dictionary that can be JSON-serialized
18541857 """
@@ -1866,26 +1869,28 @@ def _serialize_feature_stats(self) -> Dict[str, Any]:
18661869 serialized_stats [key ] = value
18671870 else :
18681871 # Convert numpy types to Python native types
1869- if hasattr (value , ' item' ): # numpy scalar
1872+ if hasattr (value , " item" ): # numpy scalar
18701873 serialized_stats [key ] = value .item ()
18711874 else :
18721875 serialized_stats [key ] = value
18731876 serialized [feature_name ] = serialized_stats
18741877 return serialized
1875-
1876- def _deserialize_feature_stats (self , stats_dict : Dict [str , Any ]) -> Dict [str , Dict [str , Union [float , List [float ]]]]:
1878+
1879+ def _deserialize_feature_stats (
1880+ self , stats_dict : Dict [str , Any ]
1881+ ) -> Dict [str , Dict [str , Union [float , List [float ]]]]:
18771882 """
18781883 Deserialize feature_stats from loaded JSON
1879-
1884+
18801885 Args:
18811886 stats_dict: Dictionary loaded from JSON
1882-
1887+
18831888 Returns:
18841889 Properly formatted feature_stats dictionary
18851890 """
18861891 if not stats_dict :
18871892 return {}
1888-
1893+
18891894 deserialized = {}
18901895 for feature_name , stats in stats_dict .items ():
18911896 if isinstance (stats , dict ):
@@ -1897,8 +1902,10 @@ def _deserialize_feature_stats(self, stats_dict: Dict[str, Any]) -> Dict[str, Di
18971902 }
18981903 deserialized [feature_name ] = deserialized_stats
18991904 else :
1900- logger .warning (f"Skipping malformed feature_stats entry for '{ feature_name } ': { stats } " )
1901-
1905+ logger .warning (
1906+ f"Skipping malformed feature_stats entry for '{ feature_name } ': { stats } "
1907+ )
1908+
19021909 return deserialized
19031910
19041911 def log_island_status (self ) -> None :
0 commit comments