microsoft/qlib · error · NotImplementedError

Please implement the `online_models` method.

Error message

Please implement the `online_models` method.

What it means

OnlineTool.online_models is an abstract method of the OnlineTool base class; it should return the list of recorders/models currently tagged 'online'. The base raises NotImplementedError by design. The error occurs when something enumerates online models (strategy workflows, OnlineManager routines) through a tool that never implemented online_models.

Source

Thrown at qlib/workflow/online/utils.py:74

    def reset_online_tag(self, recorder: Union[list, object]):
        """
        Offline all models and set the recorders to 'online'.

        Args:
            recorder (Union[list,object]):
                the recorder you want to reset to 'online'.

        """
        raise NotImplementedError(f"Please implement the `reset_online_tag` method.")

    def online_models(self) -> list:
        """
        Get current `online` models

        Returns:
            list: a list of `online` models.
        """
        raise NotImplementedError(f"Please implement the `online_models` method.")

    def update_online_pred(self, to_date=None):
        """
        Update the predictions of `online` models to to_date.

        Args:
            to_date (pd.Timestamp): the pred before this date will be updated. None for updating to the latest.

        """
        raise NotImplementedError(f"Please implement the `update_online_pred` method.")


class OnlineToolR(OnlineTool):
    """
    The implementation of OnlineTool based on (R)ecorder.
    """

    def __init__(self, default_exp_name: str = None):

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use OnlineToolR, whose online_models queries the experiment's recorders filtered by the ONLINE_TAG
  2. Implement online_models(self) -> list in your subclass returning recorders currently marked online
  3. Ensure any OnlineManager routine that runs against your strategy has a fully concrete tool wired in

Example fix

# before
tool = OnlineTool()
tool.online_models()  # NotImplementedError

# after
from qlib.workflow.online.utils import OnlineToolR
tool = OnlineToolR(default_exp_name='my_exp')
online = tool.online_models()
Defensive patterns

Strategy: type-guard

Validate before calling

from qlib.workflow.online.utils import OnlineTool

def assert_online_models_implemented(tool):
    if type(tool).online_models is OnlineTool.online_models:
        raise TypeError(f'{type(tool).__name__} must implement online_models')

Type guard

from qlib.workflow.online.utils import OnlineTool

def can_list_online(tool) -> bool:
    return type(tool).online_models is not OnlineTool.online_models

Try / catch

try:
    models = tool.online_models()
except NotImplementedError:
    models = []  # nothing tracked; or re-raise if online state must be known

Prevention

When it happens

Trigger: Calling tool.online_models() where tool is OnlineTool() or an incomplete subclass; OnlineStrategy.prepare_tasks default docstring flows reading self.tool.online_models; custom OnlineTool backends missing the override.

Common situations: Default-constructed OnlineStrategy (its __init__ sets self.tool = OnlineTool()) being driven through an online routine; porting OnlineToolR to a custom registry and forgetting the query method; test doubles that stub only some methods.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/cef30ff2e9caf9f8. Report an issue: GitHub.