{"record":{"id":"fdb68d2c49f81239","repo":"dotnet/machinelearning","slug":"smac-sweeper-localsearch-threw-exception","errorCode":null,"errorMessage":"SMAC sweeper localSearch threw exception","messagePattern":"SMAC sweeper localSearch threw exception","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/Sweepers/SmacSweeper.cs","lineNumber":249,"sourceCode":"                for (; ; )\n                {\n                    ParameterSet[] neighborhood = GetOneMutationNeighborhood(currentBestConfig);\n                    double[] eis = EvaluateConfigurationsByEI(forest, bestVal, neighborhood, isMetricMaximizing);\n                    int bestIndex = eis.ArgMax();\n                    if (eis[bestIndex] - currentBestEI < _args.Epsilon)\n                        break;\n                    else\n                    {\n                        currentBestConfig = neighborhood[bestIndex];\n                        currentBestEI = eis[bestIndex];\n                    }\n                }\n\n                return new Tuple<double, ParameterSet>(currentBestEI, currentBestConfig);\n            }\n            catch (Exception e)\n            {\n                throw new InvalidOperationException(\"SMAC sweeper localSearch threw exception\", e);\n            }\n        }\n\n        /// <summary>\n        /// Computes a single-mutation neighborhood (one parameter at a time) for a given configuration. For\n        /// numeric parameters, samples K mutations (i.e., creates K neighbors based on that parameter).\n        /// </summary>\n        /// <param name=\"parent\">Starting configuration.</param>\n        /// <returns>A set of configurations that each differ from parent in exactly one parameter.</returns>\n        private ParameterSet[] GetOneMutationNeighborhood(ParameterSet parent)\n        {\n            List<ParameterSet> neighbors = new List<ParameterSet>();\n            SweeperProbabilityUtils spu = new SweeperProbabilityUtils();\n\n            for (int i = 0; i < _sweepParameters.Length; i++)\n            {\n                // This allows us to query possible values of this parameter.\n                IValueGenerator sweepParam = _sweepParameters[i];","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/Sweepers/SmacSweeper.cs#L231-L267","documentation":"LocalSearch in SmacSweeper evaluates expected improvement over candidate configurations; any exception inside that optimization is rethrown as InvalidOperationException with the original exception as InnerException.","triggerScenarios":"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.","commonSituations":"Tuning with SmacSweeper where the surrogate model degenerates (too few trials, constant metric values) or parameter ranges contain invalid values.","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)."],"exampleFix":"// before\nvar sweeper = new SmacSweeper(mlContext, smacSweeperArgs);\n// after\ntry { var sweeper = new SmacSweeper(mlContext, smacSweeperArgs); }\ncatch (InvalidOperationException ex) { /* fall back to random sweeper; check ex.InnerException */ }","handlingStrategy":"try-catch","validationCode":"foreach (var p in searchSpace)\n    if (p.MinValue >= p.MaxValue) throw new ArgumentException($\"Invalid range for {p.Name}\");","typeGuard":null,"tryCatchPattern":"try { var best = smacSweeper.Sweep(); }\ncatch (InvalidOperationException ex) { logger.LogError(ex.InnerException, \"SMAC local search failed\"); best = randomSweeper.Sweep(); }","preventionTips":["Use valid numeric parameter ranges","Accumulate enough history before local search","Always inspect InnerException, not the wrapper message"],"tags":["csharp","sweeper","optimization"],"backgroundTag":"internal-invariant-violation","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}