microsoft/qlib · error · NotImplementedError
Please implement the `generate` method.
Error message
Please implement the `generate` method.
What it means
RecordTemp.generate is the abstract entry point of the record-template hierarchy: it should run the record generation (IC, backtest, signal analysis...) and save results to the recorder. The base class raises NotImplementedError to force subclasses to define generation logic. Seeing it means generate() was called on the base class or on a subclass that did not override it.
Source
Thrown at qlib/workflow/record_temp.py:79
@property
def recorder(self):
if self._recorder is None:
raise ValueError("This RecordTemp did not set recorder yet.")
return self._recorder
def generate(self, **kwargs):
"""
Generate certain records such as IC, backtest etc., and save them.
Parameters
----------
kwargs
Return
------
"""
raise NotImplementedError(f"Please implement the `generate` method.")
def load(self, name: str, parents: bool = True):
"""
It behaves the same as self.recorder.load_object.
But it is an easier interface because users don't have to care about `get_path` and `artifact_path`
Parameters
----------
name : str
the name for the file to be load.
parents : bool
Each recorder has different `artifact_path`.
So parents recursively find the path in parents
Sub classes has higher priority
Return
------View on GitHub (pinned to 79633dd950)
Solutions
- Subclass an existing record (SignalRecord, PortAnaRecord, IC record) instead of RecordTemp when possible
- Implement generate(self, **kwargs) in your custom record class performing the computation and calling self.save(...)
- Check spelling/signature of the override so it truly replaces the base method
Example fix
# before
class MyRecord(RecordTemp):
def __init__(self, recorder):
super().__init__(recorder)
# generate missing
# after
class MyRecord(RecordTemp):
def __init__(self, recorder):
super().__init__(recorder)
def generate(self, **kwargs):
pred = self.load('pred.pkl')
self.save(my_metric=len(pred)) Defensive patterns
Strategy: type-guard
Validate before calling
from qlib.workflow.record_temp import RecordTemp
def assert_generatable(record):
if type(record).generate is RecordTemp.generate:
raise TypeError(f'{type(record).__name__} must implement generate()') Type guard
from qlib.workflow.record_temp import RecordTemp
def has_generate(record) -> bool:
return type(record).generate is not RecordTemp.generate Try / catch
try:
record.generate()
except NotImplementedError as e:
raise TypeError(f'{type(record).__name__} is not a usable record: {e}') from e Prevention
- Subclass SignalRecord/PortAnaRecord rather than RecordTemp for common analyses
- Validate custom record classes in unit tests by calling generate on a dummy recorder
- Keep the exact method name generate(self, **kwargs) in overrides
When it happens
Trigger: Instantiating RecordTemp directly and calling generate(); defining a custom record class without a generate method and listing it in the workflow 'record' config, which Qlib will call after training; misspelling the override (e.g. genrate).
Common situations: Writing a custom analysis record for the first time; copying an existing record class and renaming its generate method; upgrading qlib where generate's expected signature stayed the same but the subclass was dropped.
Related errors
- Please implement the `_generate` method
- Please implement the `get_all_stock` method
- Please implement the `get_data` method
- Please implement the `__init__` method
- Subclass of SeriesDFilter must reimplement `getFilterSeries`
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/51bc5665c5b8aad7.
Report an issue: GitHub.