Skip to content

Commit c5025bd

Browse files
committed
fix
1 parent a65ca2b commit c5025bd

File tree

3 files changed

+126
-4
lines changed

3 files changed

+126
-4
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Circle Packing Benchmark Configuration with Thompson Sampling
2+
# Based on config_benchmark.yaml but uses two models with Thompson sampling
3+
4+
max_iterations: 500
5+
checkpoint_interval: 10
6+
log_level: "INFO"
7+
random_seed: 42
8+
9+
# Full rewrite mode (best for constructor-based problems)
10+
diff_based_evolution: false
11+
max_code_length: 50000
12+
13+
# LLM Configuration - Two models
14+
llm:
15+
api_base: "https://openrouter.ai/api/v1"
16+
models:
17+
- name: "google/gemini-2.5-flash-lite"
18+
weight: 0.8
19+
- name: "google/gemini-2.5-flash"
20+
weight: 0.2
21+
22+
temperature: 0.4
23+
top_p: 0.95
24+
max_tokens: 16000
25+
timeout: 180
26+
retries: 3
27+
28+
# Prompt Configuration
29+
prompt:
30+
system_message: |
31+
You are an expert mathematician specializing in circle packing problems and computational geometry.
32+
Your task is to improve a constructor function that places 26 circles in a unit square to maximize the sum of their radii.
33+
34+
Target: AlphaEvolve achieved sum of radii = 2.635 for n=26.
35+
36+
Key insights:
37+
- This is a constrained optimization problem with many local minima
38+
- Local optimization methods may get stuck - consider approaches that explore the solution space more broadly
39+
- Multiple starting points or perturbation strategies can help find better solutions
40+
- Good initial placements matter: hexagonal patterns, corner utilization, edge circles
41+
- The problem has 78 degrees of freedom (26 centers + 26 radii)
42+
43+
Think about how to formulate this mathematically and what optimization strategies might help escape local minima.
44+
45+
num_top_programs: 3
46+
num_diverse_programs: 2
47+
48+
# Artifacts enabled for debugging/visualization data
49+
include_artifacts: true
50+
max_artifact_bytes: 20480 # 20KB
51+
52+
# Database Configuration
53+
database:
54+
population_size: 100
55+
archive_size: 50
56+
num_islands: 4 # Optimal island count
57+
58+
# Selection parameters
59+
elite_selection_ratio: 0.1
60+
exploration_ratio: 0.4 # Higher exploration to discover optimization approaches
61+
exploitation_ratio: 0.5 # Balance with exploitation
62+
63+
# Feature dimensions for MAP-Elites (diversity-focused metrics)
64+
# - radius_variance: separates uniform vs varied circle sizes (0-1 normalized)
65+
# - spatial_spread: separates clustered vs distributed centers (0-1 normalized)
66+
feature_dimensions: ["radius_variance", "spatial_spread"]
67+
feature_bins: 10
68+
69+
# Migration parameters - faster sharing of breakthroughs
70+
migration_interval: 10 # Share discoveries sooner
71+
migration_rate: 0.15 # Migrate more programs
72+
73+
# Evaluator Configuration
74+
evaluator:
75+
timeout: 600 # Allow complex optimization programs to complete
76+
max_retries: 3
77+
cascade_evaluation: true
78+
cascade_thresholds: [0.5, 0.8]
79+
parallel_evaluations: 4
80+
use_llm_feedback: false
81+
enable_artifacts: true
82+
83+
# Novelty Detection - prevent duplicate evaluations
84+
novelty:
85+
enabled: true
86+
embedding_backend: "local"
87+
embedding_model: "all-MiniLM-L6-v2"
88+
similarity_threshold: 0.95
89+
max_regeneration_attempts: 3
90+
temperature_increment: 0.15

examples/circle_packing_with_artifacts/evaluator.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ def evaluate(program_path):
237237
"validity": 0.0,
238238
"eval_time": float(eval_time),
239239
"combined_score": 0.0,
240+
"radius_variance": 0.0,
241+
"spatial_spread": 0.0,
240242
},
241243
artifacts={
242244
"stderr": shape_error,
@@ -250,6 +252,20 @@ def evaluate(program_path):
250252
# Calculate sum
251253
sum_radii = np.sum(radii) if valid else 0.0
252254

255+
# Calculate feature metrics for MAP-Elites diversity
256+
# radius_variance: normalized variance of radii (0-1)
257+
# Max theoretical variance for radii in [0, 0.5] is ~0.0625
258+
radius_variance = float(np.var(radii) / 0.0625) if valid else 0.0
259+
radius_variance = min(1.0, max(0.0, radius_variance)) # Clamp to [0, 1]
260+
261+
# spatial_spread: how spread out centers are (0-1)
262+
# Based on std of distances from centroid, normalized by max possible (0.5 * sqrt(2))
263+
centroid = np.mean(centers, axis=0)
264+
distances_from_centroid = np.sqrt(np.sum((centers - centroid) ** 2, axis=1))
265+
max_spread = 0.5 * np.sqrt(2) # Max distance from center to corner
266+
spatial_spread = float(np.std(distances_from_centroid) / max_spread) if valid else 0.0
267+
spatial_spread = min(1.0, max(0.0, spatial_spread)) # Clamp to [0, 1]
268+
253269
# Make sure reported_sum matches the calculated sum
254270
sum_mismatch = abs(sum_radii - reported_sum) > 1e-6
255271
if sum_mismatch:
@@ -306,6 +322,8 @@ def evaluate(program_path):
306322
"validity": float(validity),
307323
"eval_time": float(eval_time),
308324
"combined_score": float(combined_score),
325+
"radius_variance": radius_variance,
326+
"spatial_spread": spatial_spread,
309327
},
310328
artifacts=artifacts,
311329
)
@@ -320,6 +338,8 @@ def evaluate(program_path):
320338
"validity": 0.0,
321339
"eval_time": 600.0, # Timeout duration
322340
"combined_score": 0.0,
341+
"radius_variance": 0.0,
342+
"spatial_spread": 0.0,
323343
},
324344
artifacts={
325345
"stderr": error_msg,
@@ -339,6 +359,8 @@ def evaluate(program_path):
339359
"validity": 0.0,
340360
"eval_time": 0.0,
341361
"combined_score": 0.0,
362+
"radius_variance": 0.0,
363+
"spatial_spread": 0.0,
342364
},
343365
artifacts={
344366
"stderr": error_msg,
@@ -374,7 +396,7 @@ def evaluate_stage1(program_path):
374396
shape_error = f"Invalid shapes: centers={centers.shape}, radii={radii.shape}"
375397
print(shape_error)
376398
return EvaluationResult(
377-
metrics={"validity": 0.0, "combined_score": 0.0},
399+
metrics={"validity": 0.0, "combined_score": 0.0, "radius_variance": 0.0, "spatial_spread": 0.0},
378400
artifacts={
379401
"stderr": shape_error,
380402
"failure_stage": "stage1_shape_validation",
@@ -389,6 +411,14 @@ def evaluate_stage1(program_path):
389411
# Calculate sum
390412
actual_sum = np.sum(radii) if valid else 0.0
391413

414+
# Calculate feature metrics for MAP-Elites diversity
415+
radius_variance = float(np.var(radii) / 0.0625) if valid else 0.0
416+
radius_variance = min(1.0, max(0.0, radius_variance))
417+
centroid = np.mean(centers, axis=0)
418+
distances_from_centroid = np.sqrt(np.sum((centers - centroid) ** 2, axis=1))
419+
spatial_spread = float(np.std(distances_from_centroid) / (0.5 * np.sqrt(2))) if valid else 0.0
420+
spatial_spread = min(1.0, max(0.0, spatial_spread))
421+
392422
# Target from paper
393423
target = 2.635
394424

@@ -424,6 +454,8 @@ def evaluate_stage1(program_path):
424454
"sum_radii": float(actual_sum),
425455
"target_ratio": float(actual_sum / target if valid else 0.0),
426456
"combined_score": float(combined_score),
457+
"radius_variance": radius_variance,
458+
"spatial_spread": spatial_spread,
427459
},
428460
artifacts=artifacts,
429461
)
@@ -432,7 +464,7 @@ def evaluate_stage1(program_path):
432464
error_msg = f"Stage 1 evaluation timed out: {e}"
433465
print(error_msg)
434466
return EvaluationResult(
435-
metrics={"validity": 0.0, "combined_score": 0.0},
467+
metrics={"validity": 0.0, "combined_score": 0.0, "radius_variance": 0.0, "spatial_spread": 0.0},
436468
artifacts={
437469
"stderr": error_msg,
438470
"failure_stage": "stage1_timeout",
@@ -445,7 +477,7 @@ def evaluate_stage1(program_path):
445477
print(error_msg)
446478
print(traceback.format_exc())
447479
return EvaluationResult(
448-
metrics={"validity": 0.0, "combined_score": 0.0},
480+
metrics={"validity": 0.0, "combined_score": 0.0, "radius_variance": 0.0, "spatial_spread": 0.0},
449481
artifacts={
450482
"stderr": error_msg,
451483
"traceback": traceback.format_exc(),
@@ -459,7 +491,7 @@ def evaluate_stage1(program_path):
459491
print(error_msg)
460492
print(traceback.format_exc())
461493
return EvaluationResult(
462-
metrics={"validity": 0.0, "combined_score": 0.0},
494+
metrics={"validity": 0.0, "combined_score": 0.0, "radius_variance": 0.0, "spatial_spread": 0.0},
463495
artifacts={
464496
"stderr": error_msg,
465497
"traceback": traceback.format_exc(),
118 KB
Loading

0 commit comments

Comments
 (0)