{"record":{"id":"19fe0d7c20fe64c5","repo":"dotnet/machinelearning","slug":"smart-sweeper-can-only-sweep-over-discrete-and-num","errorCode":null,"errorMessage":"Smart sweeper can only sweep over discrete and numeric parameters","messagePattern":"Smart sweeper can only sweep over discrete and numeric parameters","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/Sweepers/SweeperProbabilityUtils.cs","lineNumber":114,"sourceCode":"                            result.Add(j == hotIndex ? 1 : 0);\n                    else\n                        result.Add(hotIndex);\n                }\n                else if (sweepParam is LongValueGenerator lvg)\n                {\n                    var longValue = GetIfIParameterValueOfT<long>(pset) ?? long.Parse(pset.ValueText, CultureInfo.InvariantCulture);\n                    // Normalizing all numeric parameters to [0,1] range.\n                    result.Add(lvg.NormalizeValue(new LongParameterValue(pset.Name, longValue)));\n                }\n                else if (sweepParam is FloatValueGenerator fvg)\n                {\n                    var floatValue = GetIfIParameterValueOfT<float>(pset) ?? float.Parse(pset.ValueText, CultureInfo.InvariantCulture);\n                    // Normalizing all numeric parameters to [0,1] range.\n                    result.Add(fvg.NormalizeValue(new FloatParameterValue(pset.Name, floatValue)));\n                }\n                else\n                {\n                    throw new InvalidOperationException(\"Smart sweeper can only sweep over discrete and numeric parameters\");\n                }\n            }\n\n            return result.ToArray();\n        }\n\n        private static T? GetIfIParameterValueOfT<T>(IParameterValue parameterValue)\n            where T : struct =>\n            parameterValue is IParameterValue<T> pvt ? pvt.Value : default(T?);\n\n        public static ParameterSet FloatArrayAsParameterSet(IValueGenerator[] sweepParams, float[] array, bool expandedCategoricals = true)\n        {\n            Runtime.Contracts.Assert(array.Length == sweepParams.Length);\n\n            List<IParameterValue> parameters = new List<IParameterValue>();\n            int currentArrayIndex = 0;\n            for (int i = 0; i < sweepParams.Length; i++)\n            {","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/Sweepers/SweeperProbabilityUtils.cs#L96-L132","documentation":"ParameterSetAsFloatArray converts parameter sets into normalized float arrays for smart sweepers, which only support numeric and discrete (bool/enum-like) parameters. A parameter of any other type (e.g. string) hits the else branch and throws InvalidOperationException.","triggerScenarios":"Using a smart sweeper (SMACEpmSweeper/SmartSweeper) with a sweepable parameter whose IParameterValue is neither numeric nor convertible (e.g. a string search space) while encoding configs as float arrays.","commonSituations":"Defining a Sweepable<string> or string option in a search space swept by SMAC/KD-type smart sweepers that only handle float/bool.","solutions":["Change the parameter to a numeric or discrete type (Sweepable<float>/bool, or searchable strings via discrete choices the sweeper supports).","Remove string parameters from the search space when using smart sweepers.","Use a sweeper that supports arbitrary discrete values (RandomSweeper) instead."],"exampleFix":"// before\nvar param = new Sweepable<string>(\"a\", \"b\"); // swept by SmartSweeper\n// after\nvar param = new Sweepable<string>(\"a\", \"b\"); // use with RandomSweeper, or map to numeric index for SmartSweeper","handlingStrategy":"validation","validationCode":"foreach (var p in parameterSet)\n    if (!(p is FloatParameterValue || p is BoolParameterValue || long.TryParse(p.ValueText, out _) || float.TryParse(p.ValueText, out _)))\n        throw new ArgumentException($\"Parameter {p.Name} is not numeric/discrete\");","typeGuard":"bool IsSweepableBySmartSweeper<T>(T p) where T : IParameterValue => p is FloatParameterValue or DoubleParameterValue or BoolParameterValue;","tryCatchPattern":"try { float[] arr = SweeperProbabilityUtils.ParameterSetAsFloatArray(pset); }\ncatch (InvalidOperationException ex) { /* switch to RandomSweeper for this parameter set */ }","preventionTips":["Restrict smart-sweeper search spaces to numeric/discrete parameters","Handle strings via supported discrete options or a different sweeper","Test search-space encoding before long sweeps"],"tags":["csharp","sweeper","parameters"],"backgroundTag":"unsupported-operation","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}