Skip to content

Commit

Permalink
Support special step customization (#123)
Browse files Browse the repository at this point in the history
* Support special step customization

* lint
  • Loading branch information
you-n-g authored Jul 26, 2024
1 parent aacab8e commit 6b4b4fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions rdagent/app/qlib_rd_loop/factor_w_sc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
5 changes: 4 additions & 1 deletion rdagent/utils/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def __new__(cls, clsname, bases, attrs):
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)

Expand Down

0 comments on commit 6b4b4fc

Please sign in to comment.