microsoft/qlib · error · NotImplementedError

`get_support_infra` is not implemented!

Error message

`get_support_infra` is not implemented!

What it means

BaseInfrastructure in qlib/backtest/utils.py is an abstract base for infrastructure containers (trade exchange, accounts, etc.). get_support_infra must return the set of infrastructure names the subclass supports; the base implementation raises NotImplementedError. Because __init__ immediately calls reset_infra, which calls get_support_infra, an incomplete subclass fails at instantiation time.

Source

Thrown at qlib/backtest/utils.py:210

            return min(max(0, idx), self.trade_len - 1)

        return clip(left), clip(right)

    def __repr__(self) -> str:
        return (
            f"class: {self.__class__.__name__}; "
            f"{self.start_time}[{self.start_index}]~{self.end_time}[{self.end_index}]: "
            f"[{self.trade_step}/{self.trade_len}]"
        )


class BaseInfrastructure:
    def __init__(self, **kwargs: Any) -> None:
        self.reset_infra(**kwargs)

    @abstractmethod
    def get_support_infra(self) -> Set[str]:
        raise NotImplementedError("`get_support_infra` is not implemented!")

    def reset_infra(self, **kwargs: Any) -> None:
        support_infra = self.get_support_infra()
        for k, v in kwargs.items():
            if k in support_infra:
                setattr(self, k, v)
            else:
                warnings.warn(f"{k} is ignored in `reset_infra`!")

    def get(self, infra_name: str) -> Any:
        if hasattr(self, infra_name):
            return getattr(self, infra_name)
        else:
            warnings.warn(f"infra {infra_name} is not found!")

    def has(self, infra_name: str) -> bool:
        return infra_name in self.get_support_infra() and hasattr(self, infra_name)

View on GitHub (pinned to 79633dd950)

Solutions

  1. Implement get_support_infra in the subclass returning the set of supported infra keys, e.g. {'trade_exchange', 'trade_account'}.
  2. Prefer composing with the existing CommonInfrastructure (register/replace components via reset_infra kwargs) instead of subclassing.
  3. Check spelling/signature — the method takes only self and must return a Set[str].

Example fix

# before
class MyInfra(BaseInfrastructure):
    pass  # -> NotImplementedError at construction
# after
class MyInfra(BaseInfrastructure):
    def get_support_infra(self):
        return {'trade_exchange', 'trade_account'}
Defensive patterns

Strategy: validation

Validate before calling

from qlib.backtest.utils import BaseInfrastructure
class MyInfra(BaseInfrastructure):
    def get_support_infra(self):
        return {'trade_exchange', 'trade_account'}
# verify before instantiation
assert MyInfra.get_support_infra is not BaseInfrastructure.get_support_infra

Prevention

When it happens

Trigger: Defining a subclass of BaseInfrastructure (e.g. a custom CommonInfrastructure) without overriding get_support_infra, then constructing it; instantiation raises before any other method runs.

Common situations: Users extend qlib's common_infra mechanism to inject custom components and forget the abstract method; silent bugs when a method named get_support_infra is misspelled or returns None instead of a set of strings, causing reset_infra to ignore every kwarg and get() to fail later.

Related errors


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