From 32ecf92afcf647f257b430c748cbe6bb5fa0fac4 Mon Sep 17 00:00:00 2001 From: Linlang <30293408+SunsetWolf@users.noreply.github.com> Date: Mon, 3 Nov 2025 21:52:41 +0800 Subject: [PATCH] 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 --- .../components/coder/factor_coder/evolving_strategy.py | 7 ++++++- rdagent/log/ui/ds_trace.py | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/rdagent/components/coder/factor_coder/evolving_strategy.py b/rdagent/components/coder/factor_coder/evolving_strategy.py index 157f4148..338ed941 100644 --- a/rdagent/components/coder/factor_coder/evolving_strategy.py +++ b/rdagent/components/coder/factor_coder/evolving_strategy.py @@ -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 diff --git a/rdagent/log/ui/ds_trace.py b/rdagent/log/ui/ds_trace.py index f2648a5f..a489df3a 100644 --- a/rdagent/log/ui/ds_trace.py +++ b/rdagent/log/ui/ds_trace.py @@ -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()