import re
from typing import Literal

import pandas as pd

from rdagent.components.coder.finetune.conf import FT_YAML_FILE_NAME
from rdagent.core.experiment import Experiment, Task
from rdagent.scenarios.finetune.experiment.workspace import FTWorkspace

COMPONENT = Literal["Training"]


class FTExperiment(Experiment[Task, FTWorkspace, FTWorkspace]):
    def __init__(self, sub_tasks: list[Task], *args, **kwargs) -> None:
        super().__init__(sub_tasks=sub_tasks, *args, **kwargs)
        # Status
        # - Initial: blank;
        # - Injecting from SOTA code;
        # - New version no matter successful or not
        # the initial workspace or the successful new version after coding
        self.experiment_workspace = FTWorkspace()

        self.format_check_result = None
        # this field is optional. It is not none only when we have a format checker. Currently, only following cases are supported.
        # - mle-bench

    def is_ready_to_run(self) -> bool:
        """
        ready to run does not indicate the experiment is runnable
        (so it is different from `trace.next_incomplete_component`.)
        """
        return self.experiment_workspace is not None and FT_YAML_FILE_NAME in self.experiment_workspace.file_dict
