From 4c541c2e533a5b5803752b64ff55b02e2ab58001 Mon Sep 17 00:00:00 2001 From: Cyzus Chi Date: Mon, 28 Oct 2024 17:47:27 +0800 Subject: [PATCH] reorder import --- metagpt/ext/sela/experimenter/experimenter.py | 2 +- metagpt/ext/sela/experimenter/mcts.py | 2 +- metagpt/ext/sela/research_assistant.py | 2 +- metagpt/ext/sela/run_experiment.py | 2 +- metagpt/ext/sela/search/search_algorithm.py | 1 + metagpt/ext/sela/search/tree_search.py | 21 ++++++++++++------- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/metagpt/ext/sela/experimenter/experimenter.py b/metagpt/ext/sela/experimenter/experimenter.py index fd9122d29..3df46b74b 100644 --- a/metagpt/ext/sela/experimenter/experimenter.py +++ b/metagpt/ext/sela/experimenter/experimenter.py @@ -6,8 +6,8 @@ import numpy as np import pandas as pd from metagpt.ext.sela.evaluation.evaluation import evaluate_score -from metagpt.ext.sela.search.tree_search import create_initial_state from metagpt.ext.sela.research_assistant import ResearchAssistant +from metagpt.ext.sela.search.tree_search import create_initial_state from metagpt.ext.sela.utils import DATA_CONFIG, save_notebook diff --git a/metagpt/ext/sela/experimenter/mcts.py b/metagpt/ext/sela/experimenter/mcts.py index f8f9f9fd1..9fd66121d 100644 --- a/metagpt/ext/sela/experimenter/mcts.py +++ b/metagpt/ext/sela/experimenter/mcts.py @@ -6,7 +6,7 @@ from metagpt.ext.sela.evaluation.evaluation import ( ) from metagpt.ext.sela.evaluation.visualize_mcts import get_tree_text from metagpt.ext.sela.experimenter.experimenter import Experimenter -from metagpt.ext.sela.search.search_algorithm import Greedy, Random, MCTS +from metagpt.ext.sela.search.search_algorithm import MCTS, Greedy, Random class MCTSExperimenter(Experimenter): diff --git a/metagpt/ext/sela/research_assistant.py b/metagpt/ext/sela/research_assistant.py index 21cc46447..2c698c1d2 100644 --- a/metagpt/ext/sela/research_assistant.py +++ b/metagpt/ext/sela/research_assistant.py @@ -6,9 +6,9 @@ import os from pydantic import model_validator -from metagpt.ext.sela.utils import mcts_logger, save_notebook from metagpt.actions.di.write_analysis_code import WriteAnalysisCode from metagpt.const import SERDESER_PATH +from metagpt.ext.sela.utils import mcts_logger, save_notebook from metagpt.roles.di.data_interpreter import DataInterpreter from metagpt.schema import Message, Task, TaskResult from metagpt.utils.common import CodeParser, write_json_file diff --git a/metagpt/ext/sela/run_experiment.py b/metagpt/ext/sela/run_experiment.py index 7d2a317c6..4cced19c3 100644 --- a/metagpt/ext/sela/run_experiment.py +++ b/metagpt/ext/sela/run_experiment.py @@ -2,12 +2,12 @@ import argparse import asyncio from metagpt.ext.sela.data.custom_task import get_mle_is_lower_better, get_mle_task_id -from metagpt.ext.sela.experimenter.random_search import RandomSearchExperimenter from metagpt.ext.sela.experimenter.autogluon import GluonExperimenter from metagpt.ext.sela.experimenter.autosklearn import AutoSklearnExperimenter from metagpt.ext.sela.experimenter.custom import CustomExperimenter from metagpt.ext.sela.experimenter.experimenter import Experimenter from metagpt.ext.sela.experimenter.mcts import MCTSExperimenter +from metagpt.ext.sela.experimenter.random_search import RandomSearchExperimenter def get_args(cmd=True): diff --git a/metagpt/ext/sela/search/search_algorithm.py b/metagpt/ext/sela/search/search_algorithm.py index 675cc7c5f..ca47d8cf6 100644 --- a/metagpt/ext/sela/search/search_algorithm.py +++ b/metagpt/ext/sela/search/search_algorithm.py @@ -1,4 +1,5 @@ import numpy as np + from metagpt.ext.sela.search.tree_search import BaseTreeSearch, Node diff --git a/metagpt/ext/sela/search/tree_search.py b/metagpt/ext/sela/search/tree_search.py index 08f4abb5d..cde8dc82a 100644 --- a/metagpt/ext/sela/search/tree_search.py +++ b/metagpt/ext/sela/search/tree_search.py @@ -6,8 +6,14 @@ import shutil import numpy as np import pandas as pd -from metagpt.ext.sela.data.custom_task import get_mle_bench_requirements, get_mle_task_id -from metagpt.ext.sela.data.dataset import generate_task_requirement, get_split_dataset_path +from metagpt.ext.sela.data.custom_task import ( + get_mle_bench_requirements, + get_mle_task_id, +) +from metagpt.ext.sela.data.dataset import ( + generate_task_requirement, + get_split_dataset_path, +) from metagpt.ext.sela.evaluation.evaluation import evaluate_score from metagpt.ext.sela.insights.instruction_generator import InstructionGenerator from metagpt.ext.sela.research_assistant import ResearchAssistant, TimeoutException @@ -57,9 +63,9 @@ def create_initial_state(task: str, start_task_id: int, data_config: dict, args) Args: task (str): The task to be performed. start_task_id (int): The ID of the starting task. - data_config (dict): The configuration of the data. + data_config (dict): The configuration of the data. Expected keys: 'datasets', 'work_dir', 'role_dir'. - args (Namespace): The arguments passed to the program. + args (Namespace): The arguments passed to the program. Expected attributes: 'external_eval', 'custom_dataset_dir', 'special_instruction', 'name', 'low_is_better', 'role_timeout'. Returns: @@ -104,6 +110,7 @@ def create_initial_state(task: str, start_task_id: int, data_config: dict, args) os.makedirs(initial_state["node_dir"], exist_ok=True) return initial_state + class Node: state: dict = {} action: str = None @@ -113,7 +120,9 @@ class Node: normalized_reward: dict = {"train_score": 0, "dev_score": 0, "test_score": 0} parent = None - def __init__(self, parent=None, state: dict = None, action: str = None, value: float = 0, max_depth: int = 4, **kwargs): + def __init__( + self, parent=None, state: dict = None, action: str = None, value: float = 0, max_depth: int = 4, **kwargs + ): self.state = state self.action = action self.value = value @@ -306,8 +315,6 @@ class Node: return score_dict, result_dict - - class BaseTreeSearch: # data_path root_node: Node = None