2024-07-16 10:33:53 +08:00
|
|
|
import pickle
|
2024-11-06 13:14:35 +08:00
|
|
|
import shutil
|
2024-07-16 10:33:53 +08:00
|
|
|
from pathlib import Path
|
2024-10-14 17:34:09 +08:00
|
|
|
from typing import Any, Tuple
|
2024-07-16 10:33:53 +08:00
|
|
|
|
2024-07-17 15:00:13 +08:00
|
|
|
from rdagent.core.developer import Developer
|
2024-07-16 10:33:53 +08:00
|
|
|
from rdagent.core.experiment import ASpecificExp, Experiment
|
|
|
|
|
from rdagent.oai.llm_utils import md5_hash
|
|
|
|
|
|
|
|
|
|
|
2024-07-17 15:00:13 +08:00
|
|
|
class CachedRunner(Developer[ASpecificExp]):
|
2024-07-16 10:33:53 +08:00
|
|
|
def get_cache_key(self, exp: Experiment) -> str:
|
|
|
|
|
all_tasks = []
|
|
|
|
|
for based_exp in exp.based_experiments:
|
|
|
|
|
all_tasks.extend(based_exp.sub_tasks)
|
|
|
|
|
all_tasks.extend(exp.sub_tasks)
|
|
|
|
|
task_info_list = [task.get_task_information() for task in all_tasks]
|
|
|
|
|
task_info_str = "\n".join(task_info_list)
|
|
|
|
|
return md5_hash(task_info_str)
|
|
|
|
|
|
2024-10-14 17:34:09 +08:00
|
|
|
def assign_cached_result(self, exp: Experiment, cached_res: Experiment) -> Experiment:
|
|
|
|
|
if exp.based_experiments and exp.based_experiments[-1].result is None:
|
|
|
|
|
exp.based_experiments[-1].result = cached_res.based_experiments[-1].result
|
2024-11-06 13:14:35 +08:00
|
|
|
if cached_res.experiment_workspace.workspace_path.exists():
|
|
|
|
|
for csv_file in cached_res.experiment_workspace.workspace_path.glob("*.csv"):
|
|
|
|
|
shutil.copy(csv_file, exp.experiment_workspace.workspace_path)
|
|
|
|
|
for py_file in (cached_res.experiment_workspace.workspace_path / "feature").glob("*.py"):
|
|
|
|
|
shutil.copy(py_file, exp.experiment_workspace.workspace_path / "feature")
|
|
|
|
|
for py_file in (cached_res.experiment_workspace.workspace_path / "model").glob("*.py"):
|
|
|
|
|
shutil.copy(py_file, exp.experiment_workspace.workspace_path / "model")
|
2024-10-14 17:34:09 +08:00
|
|
|
exp.result = cached_res.result
|
|
|
|
|
return exp
|