fix: handle mixed str and dict types in code_list (#1279)

* fix: handle mixed str and dict types in code_list

* fix: handle missing token_costs entry for loop 0 in summarize_win
This commit is contained in:
Linlang
2025-11-03 21:52:41 +08:00
committed by GitHub
parent 35a7ae5e1f
commit 32ecf92afc
2 changed files with 12 additions and 3 deletions
@@ -169,5 +169,10 @@ class FactorMultiProcessEvolvingStrategy(MultiProcessEvolvingStrategy):
continue
if evo.sub_workspace_list[index] is None:
evo.sub_workspace_list[index] = FactorFBWorkspace(target_task=evo.sub_tasks[index])
evo.sub_workspace_list[index].inject_files(**{"factor.py": code_list[index]})
# Since the `implement_one_task` method is not standardized and the `code_list` has both `str` and `dict` data types,
# we ended up getting an `TypeError` here, so we chose to fix the problem temporarily with this dirty method.
if isinstance(code_list[index], dict):
evo.sub_workspace_list[index].inject_files(**code_list[index])
else:
evo.sub_workspace_list[index].inject_files(**{"factor.py": code_list[index]})
return evo
+6 -2
View File
@@ -93,7 +93,7 @@ def load_data(log_path: Path):
continue
li, fn = extract_loopid_func_name(msg.tag)
ei = extract_evoid(msg.tag)
if li:
if li is not None:
li = int(li)
if ei is not None:
ei = int(ei)
@@ -784,7 +784,11 @@ def summarize_win():
for k, v in loop_data["direct_exp_gen"]["no_tag"].hypothesis.__dict__.items()
if k not in ["component", "hypothesis", "reason"] and v is not None
}
df.loc[loop, "COST($)"] = sum(tc.content["cost"] for tc in state.token_costs[loop])
# In the test before 0.8.0 release, we found that when running `ui` of `data_science` (custom dataset),
# when `loop=0`, it doesn't exist in `state.token_costs.keys`, and we will get `KeyError` when running it,
# so we have fixed the problem with this dirty method for the time being.
if loop in state.token_costs:
df.loc[loop, "COST($)"] = sum(tc.content["cost"] for tc in state.token_costs[loop])
# Time Stats
exp_gen_time = timedelta()