MCPcopy Index your code
hub / github.com/algorithmicsuperintelligence/openevolve / Program

Class Program

openevolve/database.py:44–110  ·  view source on GitHub ↗

Represents a program in the database

Source from the content-addressed store, hash-verified

42
43@dataclass
44class Program:
45 """Represents a program in the database"""
46
47 # Program identification
48 id: str
49 code: str
50 changes_description: str = "" # compact program changes description (via LLM) stored per program
51 language: str = "python"
52
53 # Evolution information
54 parent_id: Optional[str] = None
55 generation: int = 0
56 timestamp: float = field(default_factory=time.time)
57 iteration_found: int = 0 # Track which iteration this program was found
58
59 # Performance metrics
60 metrics: Dict[str, float] = field(default_factory=dict)
61
62 # Derived features
63 complexity: float = 0.0
64 diversity: float = 0.0
65
66 # Metadata
67 metadata: Dict[str, Any] = field(default_factory=dict)
68
69 # Prompts
70 prompts: Optional[Dict[str, Any]] = None
71
72 # Artifact storage
73 artifacts_json: Optional[str] = None # JSON-serialized small artifacts
74 artifact_dir: Optional[str] = None # Path to large artifact files
75
76 # Embedding vector for novelty rejection sampling
77 embedding: Optional[List[float]] = None
78
79 def to_dict(self) -> Dict[str, Any]:
80 """Convert to dictionary representation"""
81 return asdict(self)
82
83 @classmethod
84 def from_dict(cls, data: Dict[str, Any]) -> "Program":
85 """Create from dictionary representation"""
86 # old DBs don't have changes_description (backward-compatibility)
87 if "changes_description" not in data:
88 metadata = data.get("metadata") or {}
89 if isinstance(metadata, dict):
90 data = {
91 **data,
92 "changes_description": metadata.get("changes_description")
93 or metadata.get("changes")
94 or "empty",
95 }
96 else:
97 data = {**data, "changes_description": "empty"}
98
99 # Get the valid field names for the Program dataclass
100 valid_fields = {f.name for f in fields(cls)}
101

Calls

no outgoing calls