dotnet/machinelearning · error · InvalidOperationException
SMAC sweeper localSearch threw exception
Error message
SMAC sweeper localSearch threw exception
What it means
LocalSearch in SmacSweeper evaluates expected improvement over candidate configurations; any exception inside that optimization is rethrown as InvalidOperationException with the original exception as InnerException.
Source
Thrown at src/Microsoft.ML.AutoML/Sweepers/SmacSweeper.cs:249
for (; ; )
{
ParameterSet[] neighborhood = GetOneMutationNeighborhood(currentBestConfig);
double[] eis = EvaluateConfigurationsByEI(forest, bestVal, neighborhood, isMetricMaximizing);
int bestIndex = eis.ArgMax();
if (eis[bestIndex] - currentBestEI < _args.Epsilon)
break;
else
{
currentBestConfig = neighborhood[bestIndex];
currentBestEI = eis[bestIndex];
}
}
return new Tuple<double, ParameterSet>(currentBestEI, currentBestConfig);
}
catch (Exception e)
{
throw new InvalidOperationException("SMAC sweeper localSearch threw exception", e);
}
}
/// <summary>
/// Computes a single-mutation neighborhood (one parameter at a time) for a given configuration. For
/// numeric parameters, samples K mutations (i.e., creates K neighbors based on that parameter).
/// </summary>
/// <param name="parent">Starting configuration.</param>
/// <returns>A set of configurations that each differ from parent in exactly one parameter.</returns>
private ParameterSet[] GetOneMutationNeighborhood(ParameterSet parent)
{
List<ParameterSet> neighbors = new List<ParameterSet>();
SweeperProbabilityUtils spu = new SweeperProbabilityUtils();
for (int i = 0; i < _sweepParameters.Length; i++)
{
// This allows us to query possible values of this parameter.
IValueGenerator sweepParam = _sweepParameters[i];View on GitHub (pinned to 7b76e69cf9)
Solutions
- Inspect InnerException for the actual cause and fix that underlying failure.
- Ensure sweeper parameter ranges are valid (min < max, no invalid floats).
- Increase the number of initial trials/history so the EI model is well-formed.
- Catch InvalidOperationException around sweeping and fall back to a simpler sweeper (RandomSweeper).
Example fix
// before
var sweeper = new SmacSweeper(mlContext, smacSweeperArgs);
// after
try { var sweeper = new SmacSweeper(mlContext, smacSweeperArgs); }
catch (InvalidOperationException ex) { /* fall back to random sweeper; check ex.InnerException */ } Defensive patterns
Strategy: try-catch
Validate before calling
foreach (var p in searchSpace)
if (p.MinValue >= p.MaxValue) throw new ArgumentException($"Invalid range for {p.Name}"); Try / catch
try { var best = smacSweeper.Sweep(); }
catch (InvalidOperationException ex) { logger.LogError(ex.InnerException, "SMAC local search failed"); best = randomSweeper.Sweep(); } Prevention
- Use valid numeric parameter ranges
- Accumulate enough history before local search
- Always inspect InnerException, not the wrapper message
When it happens
Trigger: SMAC sweeper's LocalSearch crashes while computing EI over the parameter space — e.g. NaN scores, malformed parameter sets from sweepers, or failures inside EPM (expected improvement model) evaluation.
Common situations: Tuning with SmacSweeper where the surrogate model degenerates (too few trials, constant metric values) or parameter ranges contain invalid values.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Smart sweeper can only sweep over discrete and numeric param
- {nameof(ChannelMessageKind)}.{e.Kind} is not yet implemented
- Training failed with the exception: {_history.Last().Excepti
- Metric {typeof(TMetrics)} not implemented
- Cannot set parameter {param.Name} for {obj.GetType()}
AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11).
Data as JSON: /api/errors/fdb68d2c49f81239.
Report an issue: GitHub.