microsoft/qlib · error · ValueError

Config path is invalid.

Error message

Config path is invalid.

What it means

TunerConfigManager (qlib/contrib/tuner/config.py) validates its input at construction: a falsy config_path (empty string, None) raises ValueError('Config path is invalid.'). The tuner cannot proceed without a YAML file describing experiment, tuner_pipeline and optimization criteria, so it fails immediately rather than erroring later on a missing file handle.

Source

Thrown at qlib/contrib/tuner/config.py:15

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# pylint: skip-file
# flake8: noqa

import copy
import os
from ruamel.yaml import YAML


class TunerConfigManager:
    def __init__(self, config_path):
        if not config_path:
            raise ValueError("Config path is invalid.")
        self.config_path = config_path

        with open(config_path) as fp:
            yaml = YAML(typ="safe", pure=True)
            config = yaml.load(fp)
        self.config = copy.deepcopy(config)

        self.pipeline_ex_config = PipelineExperimentConfig(config.get("experiment", dict()), self)
        self.pipeline_config = config.get("tuner_pipeline", list())
        self.optim_config = OptimizationConfig(config.get("optimization_criteria", dict()), self)

        self.time_config = config.get("time_period", dict())
        self.data_config = config.get("data", dict())
        self.backtest_config = config.get("backtest", dict())
        self.qlib_client_config = config.get("qlib_client", dict())


class PipelineExperimentConfig:

View on GitHub (pinned to 79633dd950)

Solutions

  1. Pass a real path to a valid tuner YAML config: TunerConfigManager('tuner_config.yaml')
  2. If the path comes from an env var or CLI, check it is set and non-empty before constructing
  3. Note the check only catches empty/None paths; a wrong-but-nonempty path raises FileNotFoundError next, so verify the file exists too

Example fix

# before
path = os.environ.get('TUNER_CONF')
cm = TunerConfigManager(path)

# after
path = os.environ.get('TUNER_CONF')
assert path and os.path.isfile(path), 'set TUNER_CONF to a tuner yaml file'
cm = TunerConfigManager(path)
Defensive patterns

Strategy: validation

Validate before calling

import os

config_path = os.environ.get('TUNER_CONF')
if not config_path or not os.path.isfile(config_path):
    raise FileNotFoundError('provide a valid tuner config path')
cm = TunerConfigManager(config_path)

Prevention

When it happens

Trigger: Calling TunerConfigManager(None) or TunerConfigManager(''), typically because a CLI argument or config variable was never set; note a non-empty but nonexistent path instead fails with FileNotFoundError at open().

Common situations: Running the hyperparameter tuning workflow where the config path argument is optional and the user omitted it; environment/config plumbing returning None (e.g. os.environ.get('TUNER_CONF') with the variable unset).

Related errors


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