microsoft/qlib · error · NotImplementedError

Please implement the `load_object` method.

Error message

Please implement the `load_object` method.

What it means

Recorder.load_object is the abstract method that loads a previously saved artifact (e.g. pred.pkl, model checkpoint) from the recorder's artifact store; MLflowRecorder implements it via mlflow's download/load. The base class raises NotImplementedError, so the error indicates load_object was invoked on the abstract Recorder or on a custom subclass that never implemented it.

Source

Thrown at qlib/workflow/recorder.py:103

        artifact_path=None : str
            the relative path for the artifact to be stored in the URI.
        """
        raise NotImplementedError(f"Please implement the `save_objects` method.")

    def load_object(self, name):
        """
        Load objects such as prediction file or model checkpoints.

        Parameters
        ----------
        name : str
            name of the file to be loaded.

        Returns
        -------
        The saved object.
        """
        raise NotImplementedError(f"Please implement the `load_object` method.")

    def start_run(self):
        """
        Start running or resuming the Recorder. The return value can be used as a context manager within a `with` block;
        otherwise, you must call end_run() to terminate the current run. (See `ActiveRun` class in mlflow)

        Returns
        -------
        An active running object (e.g. mlflow.ActiveRun object).
        """
        raise NotImplementedError(f"Please implement the `start_run` method.")

    def end_run(self):
        """
        End an active Recorder.
        """
        raise NotImplementedError(f"Please implement the `end_run` method.")

View on GitHub (pinned to 79633dd950)

Solutions

  1. Obtain recorders through the working API (R.get_recorder / active run) so you get an MLflowRecorder whose load_object works
  2. Implement load_object(self, name) in your Recorder subclass returning the deserialized object from the artifact URI
  3. Ensure the object was actually saved first — loading before save_objects would also fail, but with this error if the recorder is abstract

Example fix

# before
rec = Recorder(...)         # abstract
pred = rec.load_object('pred.pkl')  # NotImplementedError

# after
with R.start('my_exp'):
    rec = R.get_recorder()
    pred = rec.load_object('pred.pkl')
Defensive patterns

Strategy: type-guard

Validate before calling

from qlib.workflow.recorder import Recorder

def assert_loadable(rec):
    if type(rec).load_object is Recorder.load_object:
        raise TypeError(f'{type(rec).__name__} does not implement load_object')

Type guard

from qlib.workflow.recorder import Recorder

def can_load_objects(rec) -> bool:
    return type(rec).load_object is not Recorder.load_object

Try / catch

try:
    obj = rec.load_object('pred.pkl')
except NotImplementedError as e:
    raise TypeError(f'abstract recorder cannot load artifacts: {e}') from e

Prevention

When it happens

Trigger: Calling recorder.load_object('pred.pkl') on a base Recorder instance; a custom Recorder backend missing the override; helper code (RecordTemp.load, collectors, PredUpdater) receiving an abstract recorder because the recorder factory fell back to the base class.

Common situations: Writing a custom tracking backend; test fixtures stubbing Recorder without load_object; accessing recorders before any MLflow run exists so the resolved object is the abstract default.

Related errors


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