{"record":{"id":"9f5705b301900fa7","repo":"microsoft/qlib","slug":"please-implement-the-get-collector-method","errorCode":null,"errorMessage":"Please implement the `get_collector` method.","messagePattern":"Please implement the `get_collector` method\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/workflow/online/strategy.py","lineNumber":89,"sourceCode":"\n    def first_tasks(self) -> List[dict]:\n        \"\"\"\n        Generate a series of tasks firstly and return them.\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `first_tasks` method.\")\n\n    def get_collector(self) -> Collector:\n        \"\"\"\n        Get the instance of `Collector <../advanced/task_management.html#Task Collecting>`_ to collect different results of this strategy.\n\n        For example:\n            1) collect predictions in Recorder\n            2) collect signals in a txt file\n\n        Returns:\n            Collector\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `get_collector` method.\")\n\n\nclass RollingStrategy(OnlineStrategy):\n    \"\"\"\n    This example strategy always uses the latest rolling model sas online models.\n    \"\"\"\n\n    def __init__(\n        self,\n        name_id: str,\n        task_template: Union[dict, List[dict]],\n        rolling_gen: RollingGen,\n    ):\n        \"\"\"\n        Init RollingStrategy.\n\n        Assumption: the str of name_id, the experiment name, and the trainer's experiment name are the same.\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/workflow/online/strategy.py#L71-L107","documentation":"OnlineStrategy.get_collector is an abstract hook: the base class raises NotImplementedError so that each concrete strategy supplies the Collector used to gather results (predictions from recorders, signals from files, etc.). The error surfaces when OnlineManager (or user code) asks the strategy for its collector and the subclass never implemented get_collector.","triggerScenarios":"Calling strategy.get_collector() or an OnlineManager API that collects results (e.g. OnlineManager.get_collector) on a subclass lacking the override; building a custom OnlineStrategy and forgetting this hook; returning None instead of a Collector is fine only if you never call collectors.","commonSituations":"First-time implementation of a custom online strategy; copying a strategy example but dropping the collector part; only needing prepare/first tasks and being surprised that collect workflows require get_collector.","solutions":["Implement get_collector() -> Collector in your subclass, typically building a RecorderCollector on your experiment (see RollingStrategy.get_collector for the pattern)","If you only need collect-from-recorder behavior, reuse or subclass RollingStrategy instead of OnlineStrategy","Ensure the returned object is a real qlib.utils.paral / collector Collector instance, not None"],"exampleFix":"# before\nclass MyStrategy(OnlineStrategy):\n    ...\n    # get_collector missing\n\n# after\nfrom qlib.workflow在线 import collector as ...\n# see qlib.workflow.online.strategy.RollingStrategy\nclass MyStrategy(OnlineStrategy):\n    def get_collector(self) -> Collector:\n        from qlib.workflow import R\n        from qlib.workflow.collector import RecorderCollector\n        return RecorderCollector(exp_name=self.name_id, process_type=...)","handlingStrategy":"type-guard","validationCode":"from qlib.workflow.online.strategy import OnlineStrategy\n\ndef assert_collector_ready(strategy):\n    if strategy.get_collector.__func__ is OnlineStrategy.get_collector:\n        raise TypeError(f'{type(strategy).__name__} must implement get_collector before collecting')","typeGuard":"from qlib.workflow.online.strategy import OnlineStrategy\n\ndef has_collector(strategy) -> bool:\n    return strategy.get_collector.__func__ is not OnlineStrategy.get_collector","tryCatchPattern":"try:\n    collector = strategy.get_collector()\nexcept NotImplementedError as e:\n    raise TypeError(f'cannot collect results: {e}') from e","preventionTips":["Only call collect workflows on strategies advertising a collector","Mirror RollingStrategy.get_collector when writing custom strategies","Keep collector construction next to the strategy class so the hook is not forgotten"],"tags":["qlib","online-strategy","collector","abstract-method"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}