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

Method from_dict

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

Create from dictionary representation

(cls, data: Dict[str, Any])

Source from the content-addressed store, hash-verified

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
102 # Filter the data to only include valid fields
103 filtered_data = {k: v for k, v in data.items() if k in valid_fields}
104
105 # Log if we're filtering out any fields
106 if len(filtered_data) != len(data):
107 filtered_out = set(data.keys()) - set(filtered_data.keys())
108 logger.debug(f"Filtered out unsupported fields when loading Program: {filtered_out}")
109
110 return cls(**filtered_data)
111
112
113class ProgramDatabase:

Callers 1

loadMethod · 0.45

Calls 1

getMethod · 0.80

Tested by

no test coverage detected