Skip to content

Commit 1737aff

Browse files
authored
fix: Runnable on first complete & Rename method to next_incomplete_component for clarity (microsoft#615)
1 parent 4642220 commit 1737aff

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

rdagent/app/data_science/loop.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,24 @@ def coding(self, prev_out: dict[str, Any]):
9393

9494
def running(self, prev_out: dict[str, Any]):
9595
exp: DSExperiment = prev_out["coding"]
96-
if self.trace.next_component_required() is None:
96+
if exp.is_ready_to_run():
9797
new_exp = self.runner.develop(exp)
9898
logger.log_object(new_exp)
9999
return new_exp
100-
else:
101-
return exp
100+
return exp
102101

103102
def feedback(self, prev_out: dict[str, Any]) -> ExperimentFeedback:
103+
"""
104+
Assumption:
105+
- If we come to feedback phase, the previous development steps are successful.
106+
"""
104107
exp: DSExperiment = prev_out["running"]
105-
if self.trace.next_component_required() is None:
108+
if self.trace.next_incomplete_component() is None:
109+
# we have alreadly completed components in previous trace. So current loop is focusing on a new proposed idea.
110+
# So we need feedback for the proposal.
106111
feedback = self.summarizer.generate_feedback(exp, self.trace)
107112
else:
113+
# Otherwise, it is on drafting stage, don't need complicated feedbacks.
108114
feedback = ExperimentFeedback(
109115
reason=f"{exp.hypothesis.component} is completed.",
110116
decision=True,

rdagent/scenarios/data_science/experiment/experiment.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ def __init__(self, pending_tasks_list: list, *args, **kwargs) -> None:
1919
self.experiment_workspace = FBWorkspace()
2020
self.pending_tasks_list = pending_tasks_list
2121
self.format_check_result = None
22+
23+
def is_ready_to_run(self) -> bool:
24+
"""
25+
ready to run does not indicate the experiment is runnable
26+
(so it is different from `trace.next_incomplete_component`.)
27+
"""
28+
return self.experiment_workspace is not None and "main.py" in self.experiment_workspace.file_dict

rdagent/scenarios/data_science/proposal/exp_gen.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ def __init__(self, scen: DataScienceScen, knowledge_base: KnowledgeBase | None =
9292

9393
COMPLETE_ORDER = ("DataLoadSpec", "FeatureEng", "Model", "Ensemble", "Workflow")
9494

95-
def next_component_required(self) -> COMPONENT | None:
95+
def next_incomplete_component(self) -> COMPONENT | None:
96+
"""
97+
NOTE:
98+
- A component will be complete until get True decision feedback !!!
99+
"""
96100
for c in self.COMPLETE_ORDER:
97101
if not self.has_compponent(c):
98102
return c
@@ -105,27 +109,17 @@ def has_compponent(self, component: COMPONENT) -> bool:
105109
return True
106110
return False
107111

108-
def sota_experiment(self, last_n: int = -1) -> DSExperiment | None:
112+
def sota_experiment(self) -> DSExperiment | None:
109113
"""
110-
Access the last experiment result.
111-
112-
Parameters
113-
----------
114-
last_n : int
115-
The index from the last experiment result to access.
116-
Use -1 for the most recent experiment, -2 for the second most recent, and so on.
117-
118114
Returns
119115
-------
120116
Experiment or None
121117
The experiment result if found, otherwise None.
122118
"""
123-
assert last_n < 0
124-
for exp, ef in self.hist[::-1]:
125-
# the sota exp should be accepted decision and all required components are completed.
126-
if ef.decision and self.next_component_required() is None:
127-
last_n += 1
128-
if last_n == 0:
119+
if self.next_incomplete_component() is None:
120+
for exp, ef in self.hist[::-1]:
121+
# the sota exp should be accepted decision and all required components are completed.
122+
if ef.decision:
129123
return exp
130124
return None
131125

@@ -252,7 +246,7 @@ def gen(self, trace: DSTrace) -> DSExperiment:
252246
scenario_desc = trace.scen.get_scenario_all_desc()
253247
last_successful_exp = trace.last_successful_exp()
254248

255-
next_missing_component = trace.next_component_required()
249+
next_missing_component = trace.next_incomplete_component()
256250

257251
init_component_config = {
258252
"DataLoadSpec": {"task_cls": DataLoaderTask, "spec_file": None, "component_prompt_key": "data_loader"},

0 commit comments

Comments
 (0)