mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-04 18:57:44 +00:00
CI checks that can be automatically repaired (#119)
* fix isort & black & toml-sort & sphinx error * fix ci error * fix ci error * add comments * Update Makefile * change sphinx build command * add auto-lint * add black args * format with black * Auto Linting document * fix ci error --------- Co-authored-by: you-n-g <you-n-g@users.noreply.github.com> Co-authored-by: Young <afe.young@gmail.com>
This commit is contained in:
@@ -19,18 +19,17 @@ from rdagent.components.coder.factor_coder.CoSTEER.evaluators import (
|
||||
from rdagent.components.coder.factor_coder.factor import FactorFBWorkspace
|
||||
from rdagent.core.conf import RD_AGENT_SETTINGS
|
||||
from rdagent.core.developer import Developer
|
||||
|
||||
from rdagent.core.exception import CoderException, RunnerException
|
||||
from rdagent.core.experiment import Task, Workspace
|
||||
from rdagent.core.scenario import Scenario
|
||||
from rdagent.core.utils import multiprocessing_wrapper
|
||||
|
||||
|
||||
EVAL_RES = Dict[
|
||||
str,
|
||||
List[Tuple[FactorEvaluator, Union[object, RunnerException]]],
|
||||
]
|
||||
|
||||
|
||||
class TestCase:
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -356,7 +356,9 @@ class FactorValueEvaluator(FactorEvaluator):
|
||||
|
||||
# Check if both dataframe have the same rows count
|
||||
if gt_implementation is not None:
|
||||
feedback_str, single_column_result = FactorRowCountEvaluator(self.scen).evaluate(implementation, gt_implementation)
|
||||
feedback_str, single_column_result = FactorRowCountEvaluator(self.scen).evaluate(
|
||||
implementation, gt_implementation
|
||||
)
|
||||
conclusions.append(feedback_str)
|
||||
|
||||
feedback_str, same_index_result = FactorIndexEvaluator(self.scen).evaluate(
|
||||
@@ -364,7 +366,9 @@ class FactorValueEvaluator(FactorEvaluator):
|
||||
)
|
||||
conclusions.append(feedback_str)
|
||||
|
||||
feedback_str, output_format_result = FactorMissingValuesEvaluator(self.scen).evaluate(implementation, gt_implementation)
|
||||
feedback_str, output_format_result = FactorMissingValuesEvaluator(self.scen).evaluate(
|
||||
implementation, gt_implementation
|
||||
)
|
||||
conclusions.append(feedback_str)
|
||||
|
||||
feedback_str, equal_value_ratio_result = FactorEqualValueCountEvaluator(self.scen).evaluate(
|
||||
@@ -464,8 +468,10 @@ class FactorFinalDecisionEvaluator(Evaluator):
|
||||
except KeyError as e:
|
||||
attempts += 1
|
||||
if attempts >= max_attempts:
|
||||
raise KeyError("Response from API is missing 'final_decision' or 'final_feedback' key after multiple attempts.") from e
|
||||
|
||||
raise KeyError(
|
||||
"Response from API is missing 'final_decision' or 'final_feedback' key after multiple attempts."
|
||||
) from e
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
|
||||
@@ -68,8 +68,12 @@ class MultiProcessEvolvingStrategy(EvolvingStrategy):
|
||||
# if the number of factors to be implemented is larger than the limit, we need to select some of them
|
||||
if FACTOR_IMPLEMENT_SETTINGS.select_ratio < 1:
|
||||
# if the number of loops is equal to the select_loop, we need to select some of them
|
||||
implementation_factors_per_round = round(FACTOR_IMPLEMENT_SETTINGS.select_ratio * len(to_be_finished_task_index) + 0.5) # ceilling
|
||||
implementation_factors_per_round = min(implementation_factors_per_round, len(to_be_finished_task_index)) # but not exceed the total number of tasks
|
||||
implementation_factors_per_round = round(
|
||||
FACTOR_IMPLEMENT_SETTINGS.select_ratio * len(to_be_finished_task_index) + 0.5
|
||||
) # ceilling
|
||||
implementation_factors_per_round = min(
|
||||
implementation_factors_per_round, len(to_be_finished_task_index)
|
||||
) # but not exceed the total number of tasks
|
||||
|
||||
if FACTOR_IMPLEMENT_SETTINGS.select_method == "random":
|
||||
to_be_finished_task_index = RandomSelect(
|
||||
|
||||
@@ -10,11 +10,7 @@ import pandas as pd
|
||||
from filelock import FileLock
|
||||
|
||||
from rdagent.components.coder.factor_coder.config import FACTOR_IMPLEMENT_SETTINGS
|
||||
from rdagent.core.exception import (
|
||||
CodeFormatError,
|
||||
NoOutputError,
|
||||
CustomRuntimeError,
|
||||
)
|
||||
from rdagent.core.exception import CodeFormatError, CustomRuntimeError, NoOutputError
|
||||
from rdagent.core.experiment import Experiment, FBWorkspace, Task
|
||||
from rdagent.log import rdagent_logger as logger
|
||||
from rdagent.oai.llm_utils import md5_hash
|
||||
|
||||
@@ -16,7 +16,14 @@ from rdagent.utils import get_module_by_module_path
|
||||
|
||||
class ModelTask(Task):
|
||||
def __init__(
|
||||
self, name: str, description: str, formulation: str, architecture: str, variables: Dict[str, str], hyperparameters: Dict[str, str], model_type: Optional[str] = None
|
||||
self,
|
||||
name: str,
|
||||
description: str,
|
||||
formulation: str,
|
||||
architecture: str,
|
||||
variables: Dict[str, str],
|
||||
hyperparameters: Dict[str, str],
|
||||
model_type: Optional[str] = None,
|
||||
) -> None:
|
||||
self.name: str = name
|
||||
self.description: str = description
|
||||
@@ -24,7 +31,9 @@ class ModelTask(Task):
|
||||
self.architecture: str = architecture
|
||||
self.variables: str = variables
|
||||
self.hyperparameters: str = hyperparameters
|
||||
self.model_type: str = model_type # Tabular for tabular model, TimesSeries for time series model, Graph for graph model
|
||||
self.model_type: str = (
|
||||
model_type # Tabular for tabular model, TimesSeries for time series model, Graph for graph model
|
||||
)
|
||||
|
||||
def get_task_information(self):
|
||||
return f"""name: {self.name}
|
||||
@@ -107,21 +116,21 @@ class ModelFBWorkspace(FBWorkspace):
|
||||
# Initialize all parameters of `m` to `param_init_value`
|
||||
for _, param in m.named_parameters():
|
||||
param.data.fill_(param_init_value)
|
||||
|
||||
|
||||
# Execute the model
|
||||
if self.target_task.model_type == "Graph":
|
||||
out = m(*data)
|
||||
else:
|
||||
out = m(data)
|
||||
|
||||
|
||||
execution_model_output = out.cpu().detach()
|
||||
execution_feedback_str = f"Execution successful, output tensor shape: {execution_model_output.shape}"
|
||||
|
||||
|
||||
if MODEL_IMPL_SETTINGS.enable_execution_cache:
|
||||
pickle.dump((execution_feedback_str, execution_model_output), open(cache_file_path, "wb"))
|
||||
|
||||
|
||||
return execution_feedback_str, execution_model_output
|
||||
|
||||
|
||||
except Exception as e:
|
||||
return f"Execution error: {e}", None
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import fitz
|
||||
from PIL import Image
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import fitz
|
||||
from azure.ai.formrecognizer import DocumentAnalysisClient
|
||||
from azure.core.credentials import AzureKeyCredential
|
||||
from langchain.document_loaders import PyPDFDirectoryLoader, PyPDFLoader
|
||||
from PIL import Image
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langchain_core.documents import Document
|
||||
|
||||
from rdagent.core.conf import RD_AGENT_SETTINGS
|
||||
|
||||
|
||||
@@ -99,10 +100,11 @@ def load_and_process_pdfs_by_azure_document_intelligence(path: Path) -> dict[str
|
||||
)
|
||||
return content_dict
|
||||
|
||||
|
||||
def extract_first_page_screenshot_from_pdf(pdf_path: Path) -> Image:
|
||||
doc = fitz.open(pdf_path)
|
||||
page = doc.load_page(0)
|
||||
pix = page.get_pixmap()
|
||||
image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
||||
|
||||
return image
|
||||
|
||||
return image
|
||||
|
||||
@@ -15,11 +15,11 @@ from rdagent.core.proposal import (
|
||||
)
|
||||
from rdagent.oai.llm_utils import APIBackend
|
||||
|
||||
|
||||
ModelHypothesis = Hypothesis
|
||||
|
||||
prompt_dict = Prompts(file_path=Path(__file__).parent / "prompts.yaml")
|
||||
|
||||
|
||||
class ModelHypothesisGen(HypothesisGen):
|
||||
prompts: Prompts = prompt_dict
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class BasePropSetting(BaseSettings):
|
||||
"""
|
||||
The common part of the config for RD Loop to propose and developement
|
||||
@@ -11,6 +12,7 @@ class BasePropSetting(BaseSettings):
|
||||
env_prefix = "DM_MODEL_" # Use MODEL_CODER_ as prefix for environment variables
|
||||
protected_namespaces = () # Add 'model_' to the protected namespaces
|
||||
"""
|
||||
|
||||
scen: str = ""
|
||||
hypothesis_gen: str = ""
|
||||
hypothesis2experiment: str = ""
|
||||
|
||||
@@ -4,6 +4,7 @@ It is from `rdagent/app/qlib_rd_loop/model.py` and try to replace `rdagent/app/q
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from rdagent.components.workflow.conf import BasePropSetting
|
||||
from rdagent.core.developer import Developer
|
||||
from rdagent.core.proposal import (
|
||||
@@ -15,11 +16,10 @@ from rdagent.core.proposal import (
|
||||
from rdagent.core.scenario import Scenario
|
||||
from rdagent.core.utils import import_class
|
||||
from rdagent.log import rdagent_logger as logger
|
||||
from rdagent.utils.workflow import LoopBase, LoopMeta
|
||||
|
||||
from rdagent.utils.workflow import LoopMeta, LoopBase
|
||||
|
||||
class RDLoop(LoopBase, metaclass=LoopMeta):
|
||||
|
||||
def __init__(self, PROP_SETTING: BasePropSetting):
|
||||
scen: Scenario = import_class(PROP_SETTING.scen)()
|
||||
|
||||
@@ -62,4 +62,4 @@ class RDLoop(LoopBase, metaclass=LoopMeta):
|
||||
feedback = self.summarizer.generate_feedback(prev_out["running"], prev_out["propose"], self.trace)
|
||||
with logger.tag("ef"): # evaluate and feedback
|
||||
logger.log_object(feedback, tag="feedback")
|
||||
self.trace.hist.append((prev_out["propose"],prev_out["running"] , feedback))
|
||||
self.trace.hist.append((prev_out["propose"], prev_out["running"], feedback))
|
||||
|
||||
Reference in New Issue
Block a user