From 747a764664ccb19ba2d7a748c2188ac59be76d3d Mon Sep 17 00:00:00 2001 From: Linlang <30293408+SunsetWolf@users.noreply.github.com> Date: Fri, 13 Feb 2026 10:50:46 +0800 Subject: [PATCH] fix: preserve null end_time when rendering dataset segments template (#1326) * fix: preserve null end_time when rendering dataset segments template * deps(qlib): bump qlib revision to 2fb9380 * fix: lint error --- rdagent/log/ui/app.py | 12 ++++------ rdagent/log/ui/ds_trace.py | 12 ++++------ rdagent/log/ui/web.py | 24 +++++++------------ .../data_science/proposal/exp_gen/proposal.py | 6 ++--- rdagent/scenarios/qlib/docker/Dockerfile | 2 +- .../factor_template/conf_baseline.yaml | 6 ++--- .../conf_combined_factors.yaml | 6 ++--- .../conf_combined_factors_sota_model.yaml | 6 ++--- .../conf_baseline_factors_model.yaml | 6 ++--- .../conf_sota_factors_model.yaml | 6 ++--- rdagent/scenarios/qlib/experiment/utils.py | 6 ++--- .../factor_experiment_loader/pdf_loader.py | 4 +--- rdagent/utils/env.py | 2 +- test/oai/test_embedding_and_similarity.py | 7 ++---- 14 files changed, 40 insertions(+), 65 deletions(-) diff --git a/rdagent/log/ui/app.py b/rdagent/log/ui/app.py index 605e97d2..881b32fb 100644 --- a/rdagent/log/ui/app.py +++ b/rdagent/log/ui/app.py @@ -561,11 +561,9 @@ def research_window(): if hg := state.msgs[round]["hypothesis generation"]: st.markdown("**Hypothesis💡**") # 🧠 h: Hypothesis = hg[0].content - st.markdown( - f""" + st.markdown(f""" - **Hypothesis**: {h.hypothesis} -- **Reason**: {h.reason}""" - ) +- **Reason**: {h.reason}""") if eg := state.msgs[round]["experiment generation"]: tasks_window(eg[0].content) @@ -644,14 +642,12 @@ def feedback_window(): st.plotly_chart(fig) st.markdown("**Hypothesis Feedback🔍**") h: HypothesisFeedback = fb[0].content - st.markdown( - f""" + st.markdown(f""" - **Observations**: {h.observations} - **Hypothesis Evaluation**: {h.hypothesis_evaluation} - **New Hypothesis**: {h.new_hypothesis} - **Decision**: {h.decision} -- **Reason**: {h.reason}""" - ) +- **Reason**: {h.reason}""") if isinstance(state.scenario, KGScenario): if fbe := state.msgs[round]["runner result"]: diff --git a/rdagent/log/ui/ds_trace.py b/rdagent/log/ui/ds_trace.py index a489df3a..ec70f13f 100644 --- a/rdagent/log/ui/ds_trace.py +++ b/rdagent/log/ui/ds_trace.py @@ -189,13 +189,11 @@ def task_win(task): st.markdown(f"**:blue[Package Info:]**") st.code(task.package_info) if hasattr(task, "architecture"): # model task - st.markdown( - f""" + st.markdown(f""" | Model_type | Architecture | hyperparameters | |------------|--------------|-----------------| | {task.model_type} | {task.architecture} | {task.hyperparameters} | - """ - ) + """) def workspace_win(workspace, cmp_workspace=None, cmp_name="last code."): @@ -1168,8 +1166,7 @@ with st.sidebar: st.toggle("**Show LLM Log**", key="show_llm_log") st.toggle("*Show stdout*", key="show_stdout") st.toggle("*Show save workspace*", key="show_save_input") - st.markdown( - f""" + st.markdown(f""" - [Summary](#summary) - [Exp Gen](#exp-gen) - [Coding](#coding) @@ -1177,8 +1174,7 @@ with st.sidebar: - [Feedback](#feedback) - [Record](#record) - [SOTA Experiment](#sota-exp) -""" - ) +""") def get_state_data_range(state_data): diff --git a/rdagent/log/ui/web.py b/rdagent/log/ui/web.py index 452bfab0..bdfe0d8f 100644 --- a/rdagent/log/ui/web.py +++ b/rdagent/log/ui/web.py @@ -171,11 +171,9 @@ class HypothesisWindow(StWindow): h: Hypothesis = msg.content if isinstance(msg, Message) else msg self.container.markdown("#### **Hypothesis💡**") - self.container.markdown( - f""" + self.container.markdown(f""" - **Hypothesis**: {h.hypothesis} -- **Reason**: {h.reason}""" - ) +- **Reason**: {h.reason}""") class HypothesisFeedbackWindow(StWindow): @@ -183,14 +181,12 @@ class HypothesisFeedbackWindow(StWindow): h: HypothesisFeedback = msg.content if isinstance(msg, Message) else msg self.container.markdown("#### **Hypothesis Feedback🔍**") - self.container.markdown( - f""" + self.container.markdown(f""" - **Observations**: {h.observations} - **Hypothesis Evaluation**: {h.hypothesis_evaluation} - **New Hypothesis**: {h.new_hypothesis} - **Decision**: {h.decision} -- **Reason**: {h.reason}""" - ) +- **Reason**: {h.reason}""") class FactorTaskWindow(StWindow): @@ -225,8 +221,7 @@ class FactorFeedbackWindow(StWindow): def consume_msg(self, msg: Message | FactorSingleFeedback): fb: FactorSingleFeedback = msg.content if isinstance(msg, Message) else msg - self.container.markdown( - f"""### :blue[Factor Execution Feedback] + self.container.markdown(f"""### :blue[Factor Execution Feedback] {fb.execution_feedback} ### :blue[Factor Code Feedback] {fb.code_feedback} @@ -236,16 +231,14 @@ class FactorFeedbackWindow(StWindow): {fb.final_feedback} ### :blue[Factor Final Decision] This implementation is {'SUCCESS' if fb.final_decision else 'FAIL'}. -""" - ) +""") class ModelFeedbackWindow(StWindow): def consume_msg(self, msg: Message | ModelSingleFeedback): mb: ModelSingleFeedback = msg.content if isinstance(msg, Message) else msg - self.container.markdown( - f"""### :blue[Model Execution Feedback] + self.container.markdown(f"""### :blue[Model Execution Feedback] {mb.execution_feedback} ### :blue[Model Shape Feedback] {mb.shape_feedback} @@ -257,8 +250,7 @@ class ModelFeedbackWindow(StWindow): {mb.final_feedback} ### :blue[Model Final Decision] This implementation is {'SUCCESS' if mb.final_decision else 'FAIL'}. -""" - ) +""") class WorkspaceWindow(StWindow): diff --git a/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py b/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py index 8a0343f2..1696387e 100644 --- a/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py +++ b/rdagent/scenarios/data_science/proposal/exp_gen/proposal.py @@ -649,10 +649,8 @@ class DSProposalV2ExpGen(ExpGen): # knowledge retrieval if DS_RD_SETTING.enable_research_rag: - rag_agent = RAGAgent( - system_prompt="""You are a helpful assistant. -You help users retrieve relevant knowledge from community discussions and public code.""" - ) + rag_agent = RAGAgent(system_prompt="""You are a helpful assistant. +You help users retrieve relevant knowledge from community discussions and public code.""") knowledge = rag_agent.query(problem_formatted_str) else: knowledge = None diff --git a/rdagent/scenarios/qlib/docker/Dockerfile b/rdagent/scenarios/qlib/docker/Dockerfile index e7c87260..3b5b206b 100644 --- a/rdagent/scenarios/qlib/docker/Dockerfile +++ b/rdagent/scenarios/qlib/docker/Dockerfile @@ -14,7 +14,7 @@ RUN git clone https://github.com/microsoft/qlib.git WORKDIR /workspace/qlib -RUN git fetch && git reset 3e72593b8c985f01979bebcf646658002ac43b00 --hard +RUN git fetch && git reset 2fb9380b342556ddb50a4b24e4fe8655d548b2b8 --hard RUN python -m pip install --upgrade cython RUN python -m pip install -e . diff --git a/rdagent/scenarios/qlib/experiment/factor_template/conf_baseline.yaml b/rdagent/scenarios/qlib/experiment/factor_template/conf_baseline.yaml index 189333a4..9ba27ff8 100644 --- a/rdagent/scenarios/qlib/experiment/factor_template/conf_baseline.yaml +++ b/rdagent/scenarios/qlib/experiment/factor_template/conf_baseline.yaml @@ -7,7 +7,7 @@ benchmark: &benchmark SH000300 data_handler_config: &data_handler_config start_time: {{ train_start | default("2008-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} fit_start_time: {{ train_start | default("2008-01-01", true) }} fit_end_time: {{ train_end | default("2014-12-31", true) }} instruments: *market @@ -43,7 +43,7 @@ port_analysis_config: &port_analysis_config n_drop: 5 backtest: start_time: {{ test_start | default("2017-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} account: 100000000 benchmark: *benchmark exchange_kwargs: @@ -77,7 +77,7 @@ task: segments: train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}] valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}] - test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}] + test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("null", true) }}] record: - class: SignalRecord module_path: qlib.workflow.record_temp diff --git a/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors.yaml b/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors.yaml index 47ae345c..5849a793 100644 --- a/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors.yaml +++ b/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors.yaml @@ -7,7 +7,7 @@ benchmark: &benchmark SH000300 data_handler_config: &data_handler_config start_time: {{ train_start | default("2008-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} instruments: *market data_loader: class: NestedDataLoader @@ -51,7 +51,7 @@ port_analysis_config: &port_analysis_config n_drop: 5 backtest: start_time: {{ test_start | default("2017-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} account: 100000000 benchmark: *benchmark exchange_kwargs: @@ -86,7 +86,7 @@ task: segments: train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}] valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}] - test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}] + test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("null", true) }}] record: - class: SignalRecord module_path: qlib.workflow.record_temp diff --git a/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors_sota_model.yaml b/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors_sota_model.yaml index 9f786891..e2b7da69 100644 --- a/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors_sota_model.yaml +++ b/rdagent/scenarios/qlib/experiment/factor_template/conf_combined_factors_sota_model.yaml @@ -7,7 +7,7 @@ benchmark: &benchmark SH000300 data_handler_config: &data_handler_config start_time: {{ train_start | default("2008-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} instruments: *market data_loader: class: NestedDataLoader @@ -61,7 +61,7 @@ port_analysis_config: &port_analysis_config n_drop: 5 backtest: start_time: {{ test_start | default("2017-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} account: 100000000 benchmark: *benchmark exchange_kwargs: @@ -100,7 +100,7 @@ task: segments: train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}] valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}] - test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}] + test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("null", true) }}] {% if step_len %}step_len: {{ step_len }}{% endif %} record: - class: SignalRecord diff --git a/rdagent/scenarios/qlib/experiment/model_template/conf_baseline_factors_model.yaml b/rdagent/scenarios/qlib/experiment/model_template/conf_baseline_factors_model.yaml index 6673fec9..1012d590 100644 --- a/rdagent/scenarios/qlib/experiment/model_template/conf_baseline_factors_model.yaml +++ b/rdagent/scenarios/qlib/experiment/model_template/conf_baseline_factors_model.yaml @@ -5,7 +5,7 @@ market: &market csi300 benchmark: &benchmark SH000300 data_handler_config: &data_handler_config start_time: {{ train_start | default("2008-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} fit_start_time: {{ train_start | default("2008-01-01", true) }} fit_end_time: {{ train_end | default("2014-12-31", true) }} instruments: *market @@ -41,7 +41,7 @@ port_analysis_config: &port_analysis_config n_drop: 5 backtest: start_time: {{ test_start | default("2017-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} account: 100000000 benchmark: *benchmark exchange_kwargs: @@ -80,7 +80,7 @@ task: segments: train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}] valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}] - test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}] + test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("null", true) }}] {% if step_len %}step_len: {{ step_len }}{% endif %} record: - class: SignalRecord diff --git a/rdagent/scenarios/qlib/experiment/model_template/conf_sota_factors_model.yaml b/rdagent/scenarios/qlib/experiment/model_template/conf_sota_factors_model.yaml index 9f786891..e2b7da69 100644 --- a/rdagent/scenarios/qlib/experiment/model_template/conf_sota_factors_model.yaml +++ b/rdagent/scenarios/qlib/experiment/model_template/conf_sota_factors_model.yaml @@ -7,7 +7,7 @@ benchmark: &benchmark SH000300 data_handler_config: &data_handler_config start_time: {{ train_start | default("2008-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} instruments: *market data_loader: class: NestedDataLoader @@ -61,7 +61,7 @@ port_analysis_config: &port_analysis_config n_drop: 5 backtest: start_time: {{ test_start | default("2017-01-01", true) }} - end_time: {{ test_end | default(null, true) }} + end_time: {{ test_end | default("null", true) }} account: 100000000 benchmark: *benchmark exchange_kwargs: @@ -100,7 +100,7 @@ task: segments: train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}] valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}] - test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}] + test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("null", true) }}] {% if step_len %}step_len: {{ step_len }}{% endif %} record: - class: SignalRecord diff --git a/rdagent/scenarios/qlib/experiment/utils.py b/rdagent/scenarios/qlib/experiment/utils.py index d58a6af1..f07eed85 100644 --- a/rdagent/scenarios/qlib/experiment/utils.py +++ b/rdagent/scenarios/qlib/experiment/utils.py @@ -67,8 +67,7 @@ def get_file_desc(p: Path, variable_list=[]) -> str: """ p = Path(p) - JJ_TPL = Environment(undefined=StrictUndefined).from_string( - """ + JJ_TPL = Environment(undefined=StrictUndefined).from_string(""" # {{file_name}} ## File Type @@ -76,8 +75,7 @@ def get_file_desc(p: Path, variable_list=[]) -> str: ## Content Overview {{content}} -""" - ) +""") if p.name.endswith(".h5"): df = pd.read_hdf(p) diff --git a/rdagent/scenarios/qlib/factor_experiment_loader/pdf_loader.py b/rdagent/scenarios/qlib/factor_experiment_loader/pdf_loader.py index d571197e..1f25f228 100644 --- a/rdagent/scenarios/qlib/factor_experiment_loader/pdf_loader.py +++ b/rdagent/scenarios/qlib/factor_experiment_loader/pdf_loader.py @@ -463,9 +463,7 @@ def __deduplicate_factor_dict(factor_dict: dict[str, dict[str, str]]) -> list[li description = factor_dict[factor_name]["description"] formulation = factor_dict[factor_name]["formulation"] variables = factor_dict[factor_name]["variables"] - factor_name_to_full_str[ - factor_name - ] = f"""Factor name: {factor_name} + factor_name_to_full_str[factor_name] = f"""Factor name: {factor_name} Factor description: {description} Factor formulation: {formulation} Factor variables: {variables} diff --git a/rdagent/utils/env.py b/rdagent/utils/env.py index 5ae073e9..74024a8f 100644 --- a/rdagent/utils/env.py +++ b/rdagent/utils/env.py @@ -683,7 +683,7 @@ class QlibCondaEnv(LocalEnv[QlibCondaConf]): shell=True, ) subprocess.check_call( - f"conda run -n {self.conf.conda_env_name} pip install git+https://github.com/microsoft/qlib.git@3e72593b8c985f01979bebcf646658002ac43b00", + f"conda run -n {self.conf.conda_env_name} pip install git+https://github.com/microsoft/qlib.git@2fb9380b342556ddb50a4b24e4fe8655d548b2b8", shell=True, ) subprocess.check_call( diff --git a/test/oai/test_embedding_and_similarity.py b/test/oai/test_embedding_and_similarity.py index 4235c466..6a0042c7 100644 --- a/test/oai/test_embedding_and_similarity.py +++ b/test/oai/test_embedding_and_similarity.py @@ -30,13 +30,10 @@ class TestEmbedding(unittest.TestCase): """Test embedding with very long text that exceeds token limits""" # Create a very long text that will definitely exceed embedding token limits # Using a repetitive pattern to simulate a real long document - long_content = ( - """ + long_content = """ This is a very long document that contains a lot of repetitive content to test the embedding truncation functionality. We need to make this text long enough to exceed the typical embedding model token limits of around 8192 tokens. - """ - * 1000 - ) # This should create a text with approximately 50,000+ tokens + """ * 1000 # This should create a text with approximately 50,000+ tokens # This should trigger the gradual truncation mechanism emb = APIBackend().create_embedding(long_content)