diff --git a/rdagent/app/qlib_rd_loop/conf.py b/rdagent/app/qlib_rd_loop/conf.py index f09ea203..5e8b8b14 100644 --- a/rdagent/app/qlib_rd_loop/conf.py +++ b/rdagent/app/qlib_rd_loop/conf.py @@ -25,5 +25,6 @@ class PropSetting(BaseSettings): evolving_n: int = 10 py_bin: str = "/usr/bin/python" + local_qlib_folder: Path = Path("/home/rdagent/qlib") PROP_SETTING = PropSetting() diff --git a/rdagent/app/qlib_rd_loop/factor.py b/rdagent/app/qlib_rd_loop/factor.py index 0f5f5de8..32bbbb65 100644 --- a/rdagent/app/qlib_rd_loop/factor.py +++ b/rdagent/app/qlib_rd_loop/factor.py @@ -25,6 +25,7 @@ hypothesis_gen: HypothesisGen = import_class(PROP_SETTING.qlib_factor_hypothesis hypothesis2experiment: Hypothesis2Experiment = import_class(PROP_SETTING.qlib_factor_hypothesis2experiment)() qlib_factor_coder: TaskGenerator = import_class(PROP_SETTING.qlib_factor_coder)(scen) + qlib_factor_runner: TaskGenerator = import_class(PROP_SETTING.qlib_factor_runner)(scen) qlib_factor_summarizer: HypothesisExperiment2Feedback = import_class(PROP_SETTING.qlib_factor_summarizer)(scen) @@ -38,21 +39,4 @@ for _ in range(PROP_SETTING.evolving_n): exp = qlib_factor_runner.generate(exp) feedback = qlib_factor_summarizer.generateFeedback(exp, hypothesis, trace) - trace.hist.append((hypothesis, exp, feedback)) - - -""" -trace = Trace(scen=scen) -# for _ in range(PROP_SETTING.evolving_n): -for _ in range(1): - hypothesis = hypothesis_gen.gen(trace) - exp = hypothesis2experiment.convert(hypothesis, trace) - # exp = qlib_factor_coder.generate(exp) - import pickle - file_path = '/home/finco/v-yuanteli/RD-Agent/git_ignore_folder/factor_data_output/exp_new.pkl' - with open(file_path, 'rb') as file: - exp = pickle.load(file) - exp = qlib_factor_runner.generate(exp) - feedback = qlib_factor_summarizer.generateFeedback(exp, hypothesis, trace) - # trace.hist.append((hypothesis, exp, feedback)) -""" \ No newline at end of file + trace.hist.append((hypothesis, exp, feedback)) \ No newline at end of file diff --git a/rdagent/components/coder/factor_coder/CoSTEER/evolving_strategy.py b/rdagent/components/coder/factor_coder/CoSTEER/evolving_strategy.py index 94e1af9b..fcda9ad8 100644 --- a/rdagent/components/coder/factor_coder/CoSTEER/evolving_strategy.py +++ b/rdagent/components/coder/factor_coder/CoSTEER/evolving_strategy.py @@ -149,7 +149,7 @@ class FactorEvolvingStrategy(MultiProcessEvolvingStrategy): queried_former_failed_knowledge=queried_former_failed_knowledge_to_render, ) ) - session = APIBackend(use_chat_cache=True).build_chat_session( + session = APIBackend(use_chat_cache=False).build_chat_session( session_system_prompt=system_prompt, ) @@ -249,7 +249,7 @@ class FactorEvolvingStrategyWithGraph(MultiProcessEvolvingStrategy): ) ) - session = APIBackend(use_chat_cache=True).build_chat_session( + session = APIBackend(use_chat_cache=False).build_chat_session( session_system_prompt=system_prompt, ) @@ -276,7 +276,7 @@ class FactorEvolvingStrategyWithGraph(MultiProcessEvolvingStrategy): ) .strip("\n") ) - session_summary = APIBackend(use_chat_cache=True).build_chat_session( + session_summary = APIBackend(use_chat_cache=False).build_chat_session( session_system_prompt=error_summary_system_prompt, ) for _ in range(10): # max attempt to reduce the length of error_summary_user_prompt diff --git a/rdagent/scenarios/qlib/prompts.yaml b/rdagent/scenarios/qlib/prompts.yaml index 7481c734..af79c378 100644 --- a/rdagent/scenarios/qlib/prompts.yaml +++ b/rdagent/scenarios/qlib/prompts.yaml @@ -67,13 +67,13 @@ data_feedback_generation: } user: |- Target hypothesis: - {{hypothesis}} + {{ hypothesis_text }} Tasks and Factors: - {{task_details}} + {{ task_details }} Current Result: - {{current_result}} + {{ current_result }} SOTA Result: - {{sota_result}} + {{ sota_result }} Analyze the current result in the context of its ability to: 1. Support or refute the hypothesis. 2. Show improvement or deterioration compared to the last experiment. diff --git a/rdagent/scenarios/qlib/task_generator/data.py b/rdagent/scenarios/qlib/task_generator/data.py index ab72dc08..ec2b4ed0 100644 --- a/rdagent/scenarios/qlib/task_generator/data.py +++ b/rdagent/scenarios/qlib/task_generator/data.py @@ -24,6 +24,8 @@ logger = RDAgentLog() # de = DockerEnv() # de.run(local_path=self.ws_path, entry="qrun conf.yaml") +# TODO: supporting multiprocessing and keep previous results + class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]): """ Docker run @@ -32,8 +34,6 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]): - price-volume data dumper - `data.py` + Adaptor to Factor implementation - results in `mlflow` - - - TODO: implement a qlib handler """ def FetchAlpha158ResultFromDocker(self): @@ -86,8 +86,9 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]): Generate the experiment by processing and combining factor data, then passing the combined data to Docker for backtest results. """ - - SOTA_factor = self.process_factor_data(exp.based_experiments) + SOTA_factor = None + if exp.based_experiments.__len__() != 1: + SOTA_factor = self.process_factor_data(exp.based_experiments) if exp.based_experiments[-1].result is None: exp.based_experiments[-1].result = self.FetchAlpha158ResultFromDocker() @@ -133,6 +134,7 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]): result = pickle.load(f) """ + # TODO: Implement the Docker run in the following way # Local run # Clean up any previous run artifacts by deleting the mlruns directory mlruns_path = DIRNAME_local / 'mlruns' / '1' @@ -147,7 +149,7 @@ class QlibFactorRunner(TaskGenerator[QlibFactorExperiment]): qle = LocalEnv(conf=local_conf) qle.prepare() conf_path = str(DIRNAME / "env_factor" / "conf_combined.yaml") - qle.run(entry="qrun " + conf_path) + qle.run(entry="qrun " + conf_path, local_path=PROP_SETTING.local_qlib_folder) # Verify if the new folder is created mlrun_p = DIRNAME_local / 'mlruns' / '1' diff --git a/rdagent/scenarios/qlib/task_generator/feedback.py b/rdagent/scenarios/qlib/task_generator/feedback.py index fee41d26..431fc29b 100644 --- a/rdagent/scenarios/qlib/task_generator/feedback.py +++ b/rdagent/scenarios/qlib/task_generator/feedback.py @@ -39,20 +39,15 @@ class QlibFactorHypothesisExperiment2Feedback(HypothesisExperiment2Feedback): hypothesis_text = hypothesis.hypothesis current_result = exp.result tasks_factors = [task.get_factor_information() for task in exp.sub_tasks] - sota_result = exp.based_experiments[-1].result # Generate the system prompt sys_prompt = Environment(undefined=StrictUndefined).from_string(feedback_prompts["data_feedback_generation"]["system"]).render(scenario=self.scen.get_scenario_all_desc()) - - - # Prepare task details - task_details = "\n".join([f"Task: {factor_name}, Factor: {factor_description}" for factor_name, factor_description in tasks_factors]) # Generate the user prompt - usr_prompt = Environment(undefined=StrictUndefined).from_string(feedback_prompts["data_feedback_generation"]["user"]).format( + usr_prompt = Environment(undefined=StrictUndefined).from_string(feedback_prompts["data_feedback_generation"]["user"]).render( hypothesis_text=hypothesis_text, - task_details=task_details, + task_details=tasks_factors, current_result=current_result, sota_result=sota_result )