microsoft/qlib · error · ValueError

optim_type should be min, max or correlation

Error message

optim_type should be min, max or correlation

What it means

OptimizationConfig (qlib/contrib/tuner/config.py) validates optim_type, which tells the tuner how to compare trials: 'min' (minimize the factor), 'max' (maximize it), or 'correlation' (rank trials by correlation). Any other value raises ValueError at config load time.

Source

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

            )

        self.report_factor = config.get("report_factor", "information_ratio")
        if self.report_factor not in [
            "annualized_return",
            "information_ratio",
            "max_drawdown",
            "mean",
            "std",
            "model_score",
            "model_pearsonr",
        ]:
            raise ValueError(
                "report_factor should be one of annualized_return, information_ratio, max_drawdown, mean, std, model_pearsonr and model_score"
            )

        self.optim_type = config.get("optim_type", "max")
        if self.optim_type not in ["min", "max", "correlation"]:
            raise ValueError("optim_type should be min, max or correlation")

View on GitHub (pinned to 79633dd950)

Solutions

  1. Set optim_type to exactly 'min', 'max', or 'correlation'
  2. Quote the value in YAML to avoid parser surprises
  3. Remember 'correlation' is for matching trial reports against a reference, not for min/max optimization

Example fix

# before (tuner_config.yaml)
optimization_criteria:
  optim_type: maximize

# after
optimization_criteria:
  optim_type: max
Defensive patterns

Strategy: validation

Validate before calling

assert cfg['optimization_criteria']['optim_type'] in ('min', 'max', 'correlation')

Type guard

def is_valid_optim_type(t: str) -> bool:
    return t in {'min', 'max', 'correlation'}

Prevention

When it happens

Trigger: A tuner YAML with optimization_criteria: optim_type: minimize (or 'Min', 'avg', None-as-string, etc.) raises ValueError when TunerConfigManager parses the file.

Common situations: Writing 'minimize'/'maximize' out of habit from other hyperparameter frameworks (optuna, ray tune); case sensitivity issues; YAML unquoted values being parsed into unexpected types.

Related errors


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