HKUDS/Vibe-Trading · error · RegistryError

{alpha_id}: module has no compute() function

Error message

{alpha_id}: module has no compute() function

What it means

The alpha module imported successfully but exposes no compute function. The registry contract requires each zoo module to define a public compute(panel) -> DataFrame; getattr(module, 'compute', None) returned None.

Source

Thrown at agent/src/factors/registry.py:348

        meta = alpha.meta

        missing = [c for c in meta.get("columns_required", []) if c not in panel]
        if missing:
            raise SkipAlpha(f"{alpha_id}: panel missing required columns {missing}")
        missing_extra = [c for c in meta.get("extras_required", []) if c not in panel]
        if missing_extra:
            raise SkipAlpha(f"{alpha_id}: panel missing extras {missing_extra}")
        if meta.get("requires_sector") and "sector" not in panel:
            raise SkipAlpha(f"{alpha_id}: panel missing sector tag")

        try:
            module = self._load_module(alpha)
        except Exception as exc:  # noqa: BLE001 — isolate import failure
            raise RegistryError(f"{alpha_id}: import failed: {exc}") from exc

        compute_fn = getattr(module, "compute", None)
        if compute_fn is None:
            raise RegistryError(f"{alpha_id}: module has no compute() function")

        try:
            result = compute_fn(panel)
        except Exception as exc:  # noqa: BLE001 — isolate compute failure
            raise RegistryError(f"{alpha_id}: compute() raised: {exc}") from exc

        return self._validate_output(alpha_id, result, panel)

    def _load_module(self, alpha: Alpha) -> ModuleType:
        if not self._use_filesystem_loader:
            return importlib.import_module(alpha.module_path)
        py_file = self._py_paths[alpha.id]
        cached = sys.modules.get(alpha.module_path)
        if cached is not None and getattr(cached, "__file__", None) == str(py_file):
            return cached
        spec = importlib.util.spec_from_file_location(alpha.module_path, py_file)
        if spec is None or spec.loader is None:
            raise RegistryError(f"{alpha.id}: could not build import spec for {py_file}")

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Add/rename the function to `def compute(panel: dict) -> pd.DataFrame` in the module
  2. Exclude non-factor modules from registry scanning
  3. Regenerate the module from the standard zoo template

Example fix

# before
def compute_alpha(panel):
    ...
# after
def compute(panel: dict) -> pd.DataFrame:
    ...
Defensive patterns

Strategy: validation

Validate before calling

import importlib
mod = importlib.import_module(module_path)
if not hasattr(mod, 'compute'): raise/skip

Type guard

def has_compute(module_path: str) -> bool:
    return callable(getattr(importlib.import_module(module_path), 'compute', None))

Try / catch

try:
    out = registry.compute(aid, panel)
except RegistryError as e:
    if 'no compute()' in str(e): skip(aid)
    else: raise

Prevention

When it happens

Trigger: compute(alpha_id, panel) on a module that renamed compute (e.g. _compute or compute_alpha), is a pure helper/util module, or has compute guarded by a failing conditional definition.

Common situations: Hand-written factors that don't follow the zoo template; refactors renaming compute; accidentally registering a non-factor module in the zoo directory.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/2a4b4ca1db57438d. Report an issue: GitHub.