microsoft/qlib · error · ValueError

Please give the search space of strategy.

Error message

Please give the search space of strategy.

What it means

QLibTuner.setup_space (qlib/contrib/tuner/tuner.py) also requires the 'strategy' section of the tuner config to carry a 'space' key naming a strategy search-space class in qlib.contrib.tuner.space. Without it, the tuner has no strategy variants to explore and raises ValueError('Please give the search space of strategy.') at setup time.

Source

Thrown at qlib/contrib/tuner/tuner.py:182

        with open(estimator_path, "w") as fp:
            yaml.dump(estimator_config, fp)

        return estimator_path

    def setup_space(self):
        # 1. Setup model space
        model_space_name = self.tuner_config["model"].get("space", None)
        if model_space_name is None:
            raise ValueError("Please give the search space of model.")
        model_space = getattr(
            importlib.import_module(".space", package="qlib.contrib.tuner"),
            model_space_name,
        )

        # 2. Setup strategy space
        strategy_space_name = self.tuner_config["strategy"].get("space", None)
        if strategy_space_name is None:
            raise ValueError("Please give the search space of strategy.")
        strategy_space = getattr(
            importlib.import_module(".space", package="qlib.contrib.tuner"),
            strategy_space_name,
        )

        # 3. Setup data label space if given
        if self.tuner_config.get("data_label", None) is not None:
            data_label_space_name = self.tuner_config["data_label"].get("space", None)
            if data_label_space_name is not None:
                data_label_space = getattr(
                    importlib.import_module(".space", package="qlib.contrib.tuner"),
                    data_label_space_name,
                )
        else:
            data_label_space_name = None

        # 4. Combine the searching space
        space = dict()

View on GitHub (pinned to 79633dd950)

Solutions

  1. Add space: <ClassName> under strategy in the tuner YAML, e.g. strategy: {space: TopkDropoutStrategySpace}
  2. Confirm the class exists in qlib/contrib/tuner/space.py
  3. Start from the tuner example configs so both model and strategy sections keep their space keys

Example fix

# before (tuner_config.yaml)
strategy:
  class: TopkDropoutStrategy
  module_path: qlib.contrib.strategy.signal_strategy

# after
strategy:
  space: TopkDropoutStrategySpace
  class: TopkDropoutStrategy
  module_path: qlib.contrib.strategy.signal_strategy
Defensive patterns

Strategy: validation

Validate before calling

strategy_space = cfg.get('strategy', {}).get('space')
assert strategy_space, 'tuner config strategy section needs a space: entry'
from qlib.contrib.tuner import space as tuner_space
assert hasattr(tuner_space, strategy_space), f'{strategy_space} not found in qlib.contrib.tuner.space'

Prevention

When it happens

Trigger: A tuner YAML whose strategy section omits space: (only class/module_path given); QLibTuner.setup_space() raises during tuner construction, right after the model space check.

Common situations: Converting a normal workflow config (strategy has no search space concept) into a tuner config; the model section was updated but the strategy section forgotten; a misspelled space name resolves later to AttributeError.

Related errors


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