Support special step customization (#123)

* Support special step customization

* lint
This commit is contained in:
you-n-g
2024-07-26 14:29:19 +08:00
committed by GitHub
parent 38ac4cffcd
commit 45c9726133
2 changed files with 16 additions and 1 deletions
+12
View File
@@ -2,16 +2,28 @@
Factor workflow with session control
"""
from typing import Any
import fire
from rdagent.app.qlib_rd_loop.conf import FACTOR_PROP_SETTING
from rdagent.components.workflow.rd_loop import RDLoop
from rdagent.core.exception import FactorEmptyError
from rdagent.log import rdagent_logger as logger
class FactorRDLoop(RDLoop):
skip_loop_error = (FactorEmptyError,)
def exp_gen(self, prev_out: dict[str, Any]):
with logger.tag("r"): # research
exp = self.hypothesis2experiment.convert(prev_out["propose"], self.trace)
if exp is None:
logger.error(f"Factor extraction failed.")
raise FactorEmptyError("Factor extraction failed.")
logger.log_object(exp.sub_tasks, tag="experiment generation")
return exp
def main(path=None, step_n=None):
"""
+4 -1
View File
@@ -35,7 +35,10 @@ class LoopMeta(type):
steps = LoopMeta._get_steps(bases) # all the base classes of parents
for name, attr in attrs.items():
if not name.startswith("__") and isinstance(attr, Callable):
steps.append(name)
if name not in steps:
# NOTE: if we override the step in the subclass
# Then it is not the new step. So we skip it.
steps.append(name)
attrs["steps"] = steps
return super().__new__(cls, clsname, bases, attrs)