Skip to content

Commit

Permalink
New Structure Demo (#120)
Browse files Browse the repository at this point in the history
better demo
---------

Co-authored-by: Young <[email protected]>
Co-authored-by: Taozhi Wang <[email protected]>
Co-authored-by: you-n-g <[email protected]>
Co-authored-by: cyncyw <[email protected]>
  • Loading branch information
5 people authored Jul 30, 2024
1 parent 756552c commit 311deea
Show file tree
Hide file tree
Showing 11 changed files with 985 additions and 74 deletions.
13 changes: 6 additions & 7 deletions rdagent/app/model_extraction_and_code/GeneralModel.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from pathlib import Path

from rdagent.components.coder.model_coder.model import (
ModelExperiment,
)
from rdagent.components.coder.model_coder.model import ModelExperiment
from rdagent.core.prompts import Prompts
from rdagent.core.scenario import Scenario

prompt_dict = Prompts(file_path=Path(__file__).parent / "prompts.yaml")


class GeneralModelScenario(Scenario):
@property
def background(self) -> str:
Expand All @@ -28,10 +27,10 @@ def interface(self) -> str:
@property
def simulator(self) -> str:
return prompt_dict["general_model_simulator"]

@property
def rich_style_description(self)->str:
return '''
def rich_style_description(self) -> str:
return """
# General Model Scenario
## Overview
Expand Down Expand Up @@ -61,7 +60,7 @@ def rich_style_description(self)->str:
- **Time-Series Data:** Sequential data points indexed in time order, useful for forecasting and temporal pattern recognition.
- **Graph Data:** Data structured as nodes and edges, suitable for network analysis and relational tasks.
'''
"""

def get_scenario_all_desc(self) -> str:
return f"""Background of the scenario:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

load_dotenv(override=True)

import fire

from rdagent.app.model_extraction_and_code.GeneralModel import GeneralModelScenario
from rdagent.components.coder.model_coder.task_loader import (
ModelExperimentLoaderFromPDFfiles,
)
from rdagent.scenarios.qlib.developer.model_coder import QlibModelCoSTEER
from rdagent.app.model_extraction_and_code.GeneralModel import GeneralModelScenario
from rdagent.components.document_reader.document_reader import extract_first_page_screenshot_from_pdf
from rdagent.components.document_reader.document_reader import (
extract_first_page_screenshot_from_pdf,
)
from rdagent.log import rdagent_logger as logger
import fire
from rdagent.scenarios.qlib.developer.model_coder import QlibModelCoSTEER

def extract_models_and_implement(report_file_path: str = "/home/v-xisenwang/RD-Agent/rdagent/app/model_extraction_and_code/test_doc1.pdf") -> None:

def extract_models_and_implement(
report_file_path: str = "/home/v-xisenwang/RD-Agent/rdagent/app/model_extraction_and_code/test_doc1.pdf",
) -> None:
with logger.tag("r"):
# Save Relevant Images
# Save Relevant Images
img = extract_first_page_screenshot_from_pdf(report_file_path)
logger.log_object(img, tag="pdf_image")
scenario = GeneralModelScenario()
Expand All @@ -26,5 +32,6 @@ def extract_models_and_implement(report_file_path: str = "/home/v-xisenwang/RD-A
logger.log_object(exp, tag="developed_experiment")
return exp


if __name__ == "__main__":
fire.Fire(extract_models_and_implement)
2 changes: 2 additions & 0 deletions rdagent/app/quant_factor_benchmark/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def process_results(self, results):
processed_data = self.analyze_data(summarized_data)
final_res[experiment] = processed_data.iloc[-1, :]
return final_res

def reformat_succ_rate(self, display_df):
new_idx = []
display_df = display_df[display_df.index.isin(self.index_map.keys())]
Expand Down Expand Up @@ -166,6 +167,7 @@ def plot_data(data, file_name):
plt.title("Comparison of Different Methods")
plt.savefig(file_name)


if __name__ == "__main__":
settings = BenchmarkSettings()
benchmark = BenchmarkAnalyzer(settings)
Expand Down
6 changes: 0 additions & 6 deletions rdagent/app/quant_factor_benchmark/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
FactorTestCaseLoaderFromJsonFile,
)

from rdagent.core.utils import import_class
from rdagent.core.scenario import Scenario
from rdagent.scenarios.qlib.experiment.factor_experiment import QlibFactorScenario

from pprint import pprint

# 1.read the settings
bs = BenchmarkSettings()

Expand Down
1 change: 1 addition & 0 deletions rdagent/components/benchmark/eval_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
List[Tuple[FactorEvaluator, Union[object, RunnerException]]],
]


class TestCase:
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion rdagent/core/proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def gen(self, trace: Trace) -> Hypothesis:

class Hypothesis2Experiment(ABC, Generic[ASpecificExp]):
"""
[Abstract description => concrete description] => Code implementation Card
[Abstract description => concrete description] => Code implementation Card
"""

@abstractmethod
Expand Down
26 changes: 16 additions & 10 deletions rdagent/log/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,28 @@ def iter_msg(self, watch: bool = False) -> Generator[Message, None, None]:
message_end = next_match.start() if next_match else len(content)
message_content = content[message_start:message_end].strip()

if "Logging object in" in message_content:
continue

m = Message(
tag=tag, level=level, timestamp=timestamp, caller=caller, pid_trace=pid, content=message_content
)

if isinstance(m.content, str) and "Logging object in" in m.content:
absolute_p = m.content.split("Logging object in ")[1]
relative_p = "." + absolute_p.split(self.path.name)[1]
pkl_path = self.path / relative_p
try:
with pkl_path.open("rb") as f:
m.content = pickle.load(f)
except:
continue

msg_l.append(m)

for file in self.path.glob("**/*.pkl"):
tag = ".".join(str(file.relative_to(self.path)).replace("/", ".").split(".")[:-3])
pid = file.parent.name

with file.open("rb") as f:
content = pickle.load(f)

timestamp = datetime.strptime(file.stem, "%Y-%m-%d_%H-%M-%S-%f").replace(tzinfo=timezone.utc)

m = Message(tag=tag, level="INFO", timestamp=timestamp, caller="", pid_trace=pid, content=content)

msg_l.append(m)

msg_l.sort(key=lambda x: x.timestamp)
for m in msg_l:
yield m
Expand Down
Loading

0 comments on commit 311deea

Please sign in to comment.