From eba74d1825aa51410e5b0014eed907b79ca078a6 Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Thu, 5 Feb 2026 12:00:47 -0500 Subject: [PATCH 1/8] Update primary and secondary model configurations --- examples/attention_optimization/config.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/attention_optimization/config.yaml b/examples/attention_optimization/config.yaml index 57c413e0f6..d56a4a244c 100644 --- a/examples/attention_optimization/config.yaml +++ b/examples/attention_optimization/config.yaml @@ -6,13 +6,15 @@ log_level: "INFO" # LLM configuration llm: # primary_model: "gemini-2.0-flash-lite" + primary_model: "gemini-3-flash-preview" # primary_model: "gpt-4.1-nano" - primary_model: "o3" + # primary_model: "o3" primary_model_weight: 0.8 # secondary_model: "gemini-2.0-flash" - secondary_model: "gpt-4.1-mini" + secondary_model: "gemini-3-pro-preview" + # secondary_model: "gpt-4.1-mini" secondary_model_weight: 0.2 - # api_base: "https://generativelanguage.googleapis.com/v1beta/openai/" + api_base: "https://generativelanguage.googleapis.com/v1beta/openai/" # api_base: "https://api.cerebras.ai/v1" temperature: 0.7 top_p: 0.95 From ff5759d3ced4ecface18245cd6bd65301d492bf0 Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Thu, 5 Feb 2026 13:10:17 -0500 Subject: [PATCH 2/8] Update MLIR file path to be dynamic --- examples/attention_optimization/evaluator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/attention_optimization/evaluator.py b/examples/attention_optimization/evaluator.py index de6dd2d69a..8b593cfb6d 100644 --- a/examples/attention_optimization/evaluator.py +++ b/examples/attention_optimization/evaluator.py @@ -17,7 +17,11 @@ class MLIRAttentionEvaluator: def __init__(self): self.verify_tools() - self.mlir_file = Path("mlir/self_attn_with_consts_linalg_dialect.mlir") + # Get the absolute path of the current file + current_file_path = os.path.abspath(__file__) + # Get the directory containing the current file + current_dir = os.path.dirname(current_file_path) + self.mlir_file = Path(os.path.join(current_dir, "mlir/self_attn_with_consts_linalg_dialect.mlir")) # self.mlir_file = Path("mlir/export_mlir.mlir") self.baseline_mlir = None self.baseline_metrics = None @@ -140,7 +144,7 @@ def estimate_performance_from_ir(self, optimized_metrics, baseline_metrics, para 'method': 'ir_analysis', 'size_ratio': size_ratio, 'ops_ratio': ops_ratio, - 'optimization_score': base_speedup + 'combined_score': base_speedup } def apply_optimizations(self, mlir_content, params): From 79d7836cbf7cf8c97e507feac5624c2c55f0d5b4 Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Thu, 5 Feb 2026 16:32:41 -0500 Subject: [PATCH 3/8] Add variant configuration option to config.py --- openevolve/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openevolve/config.py b/openevolve/config.py index bef193da21..4eafb103f0 100644 --- a/openevolve/config.py +++ b/openevolve/config.py @@ -351,6 +351,7 @@ class DatabaseConfig: novelty_llm: Optional["LLMInterface"] = None embedding_model: Optional[str] = None similarity_threshold: float = 0.99 + variant: str = "threshold-elites" @dataclass From 08401859dcc6d7fb61b29fa711eeb508feb03655 Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Thu, 5 Feb 2026 16:34:56 -0500 Subject: [PATCH 4/8] Update primary and secondary model configurations --- examples/attention_optimization/config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/attention_optimization/config.yaml b/examples/attention_optimization/config.yaml index d56a4a244c..ca211c033e 100644 --- a/examples/attention_optimization/config.yaml +++ b/examples/attention_optimization/config.yaml @@ -6,12 +6,12 @@ log_level: "INFO" # LLM configuration llm: # primary_model: "gemini-2.0-flash-lite" - primary_model: "gemini-3-flash-preview" + primary_model: "gemini-2.5-flash" # primary_model: "gpt-4.1-nano" # primary_model: "o3" primary_model_weight: 0.8 # secondary_model: "gemini-2.0-flash" - secondary_model: "gemini-3-pro-preview" + secondary_model: "gemini-3-flash-preview" # secondary_model: "gpt-4.1-mini" secondary_model_weight: 0.2 api_base: "https://generativelanguage.googleapis.com/v1beta/openai/" From 4eaba235ace7a92d9d98cd6e9446da3675739e6b Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Fri, 6 Feb 2026 13:11:16 -0500 Subject: [PATCH 5/8] Assign programs to islands using threshold-elites --- openevolve/database.py | 126 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 1 deletion(-) diff --git a/openevolve/database.py b/openevolve/database.py index eca5eab0bb..04680e4735 100644 --- a/openevolve/database.py +++ b/openevolve/database.py @@ -209,7 +209,29 @@ def __init__(self, config: DatabaseConfig): self.similarity_threshold = config.similarity_threshold def add( - self, program: Program, iteration: int = None, target_island: Optional[int] = None + self, program: Program, iteration: int = None, target_island: Optional[int] = None, + ) -> str: + """ + Add a program to the database + + Args: + program: Program to add + iteration: Current iteration (defaults to last_iteration) + target_island: Specific island to add to (auto-detects parent's island if None) + + Returns: + Program ID + """ + variant = getattr(self.config, "variant", "map-elites") + if variant == "map-elites": + self.add_map_elites_program(program, iteration, target_island) + elif variant == "threshold-elites": + self.add_threshold_elites_program(program, iteration, target_island) + else: + raise NotImplementedError() + + def add_map_elites_program( + self, program: Program, iteration: int = None, target_island: Optional[int] = None, ) -> str: """ Add a program to the database @@ -367,6 +389,108 @@ def add( return program.id + def add_threshold_elites_program( + self, program: Program, iteration: int = None, target_island: Optional[int] = None, + ) -> str: + # Store the program + # If iteration is provided, update the program's iteration_found + if iteration is not None: + program.iteration_found = iteration + # Update last_iteration if needed + self.last_iteration = max(self.last_iteration, iteration) + + self.programs[program.id] = program + + # Calculate feature coordinates for Threshold-Elites + embd = self._calculate_feature_coords(program) + program.embedding = embd + + # Determine target island + # If target_island is not specified and program has a parent, inherit parent's island + if target_island is None and program.parent_id: + parent = self.programs.get(program.parent_id) + if parent and "island" in parent.metadata: + # Child inherits parent's island to maintain island isolation + island_idx = parent.metadata["island"] + logger.debug( + f"Program {program.id} inheriting island {island_idx} from parent {program.parent_id}" + ) + else: + # Parent not found or has no island, use current_island + island_idx = self.current_island + if parent: + logger.warning( + f"Parent {program.parent_id} has no island metadata, using current_island {island_idx}" + ) + else: + logger.warning( + f"Parent {program.parent_id} not found, using current_island {island_idx}" + ) + elif target_island is not None: + # Explicit target island specified (e.g., for migrants) + island_idx = target_island + else: + # No parent and no target specified, use current island + island_idx = self.current_island + + island_idx = island_idx % len(self.islands) # Ensure valid island + + # Novelty check before adding + if not self._is_novel(program.id, island_idx): + logger.debug( + f"Program {program.id} failed in novelty check and won't be added in the island {island_idx}" + ) + return program.id # Do not add non-novel program + + score = program.metrics["combined_score"] + + for pid in self.islands[island_idx]: + other = self.programs[pid] + + if other.embedding is None: + logger.warning( + f"Warning: Program {other.id} has no embedding, skipping similarity check" + ) + continue + + #similarity = self._cosine_similarity(embd, other.embedding) + distance = math.sqrt(sum((a - b) ** 2 for a, b in zip(embd, other.embedding))) + + if distance < 3: + # self._is_better(program, other) + if score > other.metrics["combined_score"]: + other.metrics["combined_score"] = float("-inf") + else: + program.metrics["combined_score"] = float("-inf") + + + # Add to island + self.islands[island_idx].add(program.id) + + # Track which island this program belongs to + program.metadata["island"] = island_idx + + # Update archive + self._update_archive(program) + + # Enforce population size limit BEFORE updating best program tracking + # This ensures newly added programs aren't immediately removed + self._enforce_population_limit(exclude_program_id=program.id) + + # Update the absolute best program tracking (after population enforcement) + self._update_best_program(program) + + # Update island-specific best program tracking + self._update_island_best_program(program, island_idx) + + # Save to disk if configured + if self.config.db_path: + self._save_program(program) + + logger.debug(f"Added program {program.id} to island {island_idx}") + + return program.id + def get(self, program_id: str) -> Optional[Program]: """ Get a program by ID From dd3a72fb41acce5791b60fc367cbafbfa3ac729c Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Fri, 6 Feb 2026 15:57:18 -0500 Subject: [PATCH 6/8] Assign programs to islands using threshold-elites --- openevolve/config.py | 2 +- openevolve/database.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/openevolve/config.py b/openevolve/config.py index 4eafb103f0..73b15fd8ff 100644 --- a/openevolve/config.py +++ b/openevolve/config.py @@ -352,7 +352,7 @@ class DatabaseConfig: embedding_model: Optional[str] = None similarity_threshold: float = 0.99 variant: str = "threshold-elites" - + elite_threshold: int = 3 @dataclass class EvaluatorConfig: diff --git a/openevolve/database.py b/openevolve/database.py index 04680e4735..79b01d5b11 100644 --- a/openevolve/database.py +++ b/openevolve/database.py @@ -403,7 +403,9 @@ def add_threshold_elites_program( # Calculate feature coordinates for Threshold-Elites embd = self._calculate_feature_coords(program) + score = get_fitness_score(program.metrics, self.config.feature_dimensions) program.embedding = embd + program.metrics["elite_score"] = score # Determine target island # If target_island is not specified and program has a parent, inherit parent's island @@ -442,8 +444,8 @@ def add_threshold_elites_program( ) return program.id # Do not add non-novel program - score = program.metrics["combined_score"] + elite_threshold = getattr(self.config, "elite_threshold", 3) for pid in self.islands[island_idx]: other = self.programs[pid] @@ -456,12 +458,12 @@ def add_threshold_elites_program( #similarity = self._cosine_similarity(embd, other.embedding) distance = math.sqrt(sum((a - b) ** 2 for a, b in zip(embd, other.embedding))) - if distance < 3: + if distance < elite_threshold: # self._is_better(program, other) - if score > other.metrics["combined_score"]: - other.metrics["combined_score"] = float("-inf") + if score > other.metrics["elite_score"]: + other.metrics["elite_score"] = float("-inf") else: - program.metrics["combined_score"] = float("-inf") + program.metrics["elite_score"] = float("-inf") # Add to island From 16458bffa44c9e258539fd930060b4c2398972f4 Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Fri, 6 Feb 2026 17:00:55 -0500 Subject: [PATCH 7/8] Bug fixes --- examples/attention_optimization/evaluator.py | 2 +- openevolve/database.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/attention_optimization/evaluator.py b/examples/attention_optimization/evaluator.py index 8b593cfb6d..330af6e4d4 100644 --- a/examples/attention_optimization/evaluator.py +++ b/examples/attention_optimization/evaluator.py @@ -271,7 +271,7 @@ def evaluate(self, optimize_attention_input): "compile_time": float(compile_time or 0), "method": result.get('method', 'ir_analysis'), "size_ratio": result.get('size_ratio', 1.0), - "optimization_score": result.get('optimization_score', 1.0) + "combined_score": result.get('combined_score', 1.0) } print(f"📊 Result: error={error:.3f}, speedup={speedup:.3f}x, runtime={runtime:.3f}") diff --git a/openevolve/database.py b/openevolve/database.py index 79b01d5b11..a438ff16c9 100644 --- a/openevolve/database.py +++ b/openevolve/database.py @@ -10,6 +10,7 @@ import shutil import time import uuid +import math from dataclasses import asdict, dataclass, field, fields # FileLock removed - no longer needed with threaded parallel processing From 96cbb888faf07013c0075e0805727dc48e8ad989 Mon Sep 17 00:00:00 2001 From: Yihao Fang Date: Mon, 9 Feb 2026 13:04:43 -0500 Subject: [PATCH 8/8] =?UTF-8?q?Copy=20program=E2=80=99s=20embedding=20vect?= =?UTF-8?q?or=20during=20exploration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openevolve/database.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openevolve/database.py b/openevolve/database.py index a438ff16c9..dabe66cee9 100644 --- a/openevolve/database.py +++ b/openevolve/database.py @@ -11,6 +11,7 @@ import time import uuid import math +import copy from dataclasses import asdict, dataclass, field, fields # FileLock removed - no longer needed with threaded parallel processing @@ -1440,6 +1441,7 @@ def _sample_exploration_parent(self) -> Program: metadata={"island": self.current_island}, artifacts_json=best_program.artifacts_json, artifact_dir=best_program.artifact_dir, + embedding=copy.deepcopy(best_program.embedding) ) self.programs[copy_program.id] = copy_program self.islands[self.current_island].add(copy_program.id) @@ -1486,6 +1488,7 @@ def _sample_exploration_parent(self) -> Program: metadata={"island": self.current_island}, artifacts_json=best_program.artifacts_json, artifact_dir=best_program.artifact_dir, + embedding=copy.deepcopy(best_program.embedding) ) self.programs[copy_program.id] = copy_program self.islands[self.current_island].add(copy_program.id)