Files
NexQuant/rdagent/scenarios/qlib/factor_experiment_loader/json_loader.py
T
Linlang 32a29a7479 fix: main bug (#938)
* feat: parameterize cache paths with USER to avoid conflicts

* guide for missing training_hyperparameters

* guidance for  KeyError: 'concise_reason'

* fixed three bugs in the test

* fix general_model task bug

* fixed some bugs in the med_model scenario

* delete comments

* format with black

* fix mypy error

* fix ruff error

* fix isort error

* sync code

* revert cache_path code

* revert cache_path code

* delete data mining scenario

* fix factor report loop

* fix LiteLLMAPIBackend log_llm_chat_content setting

* refine fin factor report scenario

* remove unused LogColors

* fix UI

* remove medical scenario docs

* change **kaggle** to **data_science**

* remove default dataset_path in create_debug_data

* remove KAGGLE_SETTINGS in kaggle_crawler

* limit litellm versions

* reformat with black

* change README

* fix_data_science_docs

* make hypothesis observations string

* Hiding old versions of kaggle docs

* hidding kaggle agent docs

---------

Co-authored-by: Young <afe.young@gmail.com>
Co-authored-by: Bowen Xian <xianbowen@outlook.com>
Co-authored-by: yuanteli <1957922024@qq.com>
2025-06-18 14:35:45 +08:00

64 lines
2.5 KiB
Python

import json
from pathlib import Path
from rdagent.components.benchmark.eval_method import TestCase, TestCases
from rdagent.components.coder.factor_coder.factor import (
FactorExperiment,
FactorFBWorkspace,
FactorTask,
)
from rdagent.components.loader.experiment_loader import FactorExperimentLoader
from rdagent.core.experiment import Experiment, Loader
from rdagent.scenarios.qlib.experiment.factor_experiment import QlibFactorExperiment
class FactorExperimentLoaderFromDict(FactorExperimentLoader):
def load(self, factor_dict: dict) -> QlibFactorExperiment:
"""Load data from a dict."""
task_l = []
for factor_name, factor_data in factor_dict.items():
task = FactorTask(
factor_name=factor_name,
factor_description=factor_data["description"],
factor_formulation=factor_data["formulation"],
variables=factor_data["variables"],
)
task_l.append(task)
exp = QlibFactorExperiment(sub_tasks=task_l)
return exp
class FactorExperimentLoaderFromJsonFile(FactorExperimentLoader):
def load(self, json_file_path: Path) -> list:
with open(json_file_path, "r") as file:
factor_dict = json.load(file)
return FactorExperimentLoaderFromDict().load(factor_dict)
class FactorExperimentLoaderFromJsonString(FactorExperimentLoader):
def load(self, json_string: str) -> list:
factor_dict = json.loads(json_string)
return FactorExperimentLoaderFromDict().load(factor_dict)
# TODO loader only supports generic of task or experiment, testcase might cause CI error here
# class FactorTestCaseLoaderFromJsonFile(Loader[TestCases]):
class FactorTestCaseLoaderFromJsonFile:
def load(self, json_file_path: Path) -> TestCases:
with open(json_file_path, "r") as file:
factor_dict = json.load(file)
test_cases = TestCases()
for factor_name, factor_data in factor_dict.items():
task = FactorTask(
factor_name=factor_name,
factor_description=factor_data["description"],
factor_formulation=factor_data["formulation"],
variables=factor_data["variables"],
)
gt = FactorFBWorkspace(task, raise_exception=False)
code = {"factor.py": factor_data["gt_code"]}
gt.inject_files(**code)
test_cases.test_case_l.append(TestCase(task, gt))
return test_cases