Skip to content

Commit 89f9094

Browse files
authored
Merge pull request #89 from codelion/fix-prompts-checkpoint-loading
Filter unsupported fields in Program.from_dict
2 parents 21aded7 + 0fe8bf5 commit 89f9094

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

openevolve/database.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import random
1010
import time
11-
from dataclasses import asdict, dataclass, field
11+
from dataclasses import asdict, dataclass, field, fields
1212
from pathlib import Path
1313
from typing import Any, Dict, List, Optional, Set, Tuple, Union
1414

@@ -73,7 +73,18 @@ def to_dict(self) -> Dict[str, Any]:
7373
@classmethod
7474
def from_dict(cls, data: Dict[str, Any]) -> "Program":
7575
"""Create from dictionary representation"""
76-
return cls(**data)
76+
# Get the valid field names for the Program dataclass
77+
valid_fields = {f.name for f in fields(cls)}
78+
79+
# Filter the data to only include valid fields
80+
filtered_data = {k: v for k, v in data.items() if k in valid_fields}
81+
82+
# Log if we're filtering out any fields
83+
if len(filtered_data) != len(data):
84+
filtered_out = set(data.keys()) - set(filtered_data.keys())
85+
logger.debug(f"Filtered out unsupported fields when loading Program: {filtered_out}")
86+
87+
return cls(**filtered_data)
7788

7889

7990
class ProgramDatabase:

0 commit comments

Comments
 (0)