Skip to content

Commit 02bb931

Browse files
RolandMinruiWinstonLiyt
authored andcommitted
feat: add do_truncate control for the load function (#656)
feat: add do_truncate control for the load function (#656)
1 parent f7d9437 commit 02bb931

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

rdagent/app/data_science/loop.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ def record(self, prev_out: dict[str, Any]):
142142
logger.log_object(self.trace.sota_experiment(), tag="SOTA experiment")
143143

144144

145-
def main(path=None, output_path=None, step_n=None, loop_n=None, competition="bms-molecular-translation"):
145+
def main(
146+
path=None, output_path=None, step_n=None, loop_n=None, competition="bms-molecular-translation", do_truncate=True
147+
):
146148
"""
147149
148150
Parameters
149151
----------
150152
path :
151-
path like `$LOG_PATH/__session__/1/0_propose`. It indicates that we restore the state that after finish the step 0 in loop1
153+
path like `$LOG_PATH/__session__/1/0_propose`. It indicates that we restore the state that after finish the step 0 in loop 1
152154
output_path :
153155
path like `$LOG_PATH`. It indicates that where we want to save our session and log information.
154156
step_n :
@@ -158,6 +160,8 @@ def main(path=None, output_path=None, step_n=None, loop_n=None, competition="bms
158160
- if current loop is incomplete, it will be counted as the first loop for completion.
159161
- if both step_n and loop_n are provided, the process will stop as soon as either condition is met.
160162
competition :
163+
do_truncate :
164+
If set to True, the logger will truncate the future log messages by calling `logger.storage.truncate`.
161165
162166
163167
Auto R&D Evolving loop for models in a Kaggle scenario.
@@ -181,7 +185,7 @@ def main(path=None, output_path=None, step_n=None, loop_n=None, competition="bms
181185
if path is None:
182186
kaggle_loop = DataScienceRDLoop(DS_RD_SETTING)
183187
else:
184-
kaggle_loop = DataScienceRDLoop.load(path, output_path)
188+
kaggle_loop = DataScienceRDLoop.load(path, output_path, do_truncate)
185189
kaggle_loop.run(step_n=step_n, loop_n=loop_n)
186190

187191

rdagent/utils/workflow.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ def dump(self, path: str | Path) -> None:
161161
pickle.dump(self, f)
162162

163163
@classmethod
164-
def load(cls, path: Union[str, Path], output_path: Optional[Union[str, Path]] = None) -> "LoopBase":
164+
def load(
165+
cls, path: Union[str, Path], output_path: Optional[Union[str, Path]] = None, do_truncate: bool = True
166+
) -> "LoopBase":
165167
path = Path(path)
166168
with path.open("rb") as f:
167169
session = cast(LoopBase, pickle.load(f))
@@ -175,8 +177,10 @@ def load(cls, path: Union[str, Path], output_path: Optional[Union[str, Path]] =
175177
# set trace path
176178
logger.set_trace_path(session.session_folder.parent)
177179

178-
max_loop = max(session.loop_trace.keys())
179-
logger.storage.truncate(time=session.loop_trace[max_loop][-1].end)
180+
# truncate future message
181+
if do_truncate:
182+
max_loop = max(session.loop_trace.keys())
183+
logger.storage.truncate(time=session.loop_trace[max_loop][-1].end)
180184
return session
181185

182186

0 commit comments

Comments
 (0)