dotnet/machinelearning · error · InvalidOperationException
Smart sweeper can only sweep over discrete and numeric param
Error message
Smart sweeper can only sweep over discrete and numeric parameters
What it means
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.
Source
Thrown at src/Microsoft.ML.AutoML/Sweepers/SweeperProbabilityUtils.cs:114
result.Add(j == hotIndex ? 1 : 0);
else
result.Add(hotIndex);
}
else if (sweepParam is LongValueGenerator lvg)
{
var longValue = GetIfIParameterValueOfT<long>(pset) ?? long.Parse(pset.ValueText, CultureInfo.InvariantCulture);
// Normalizing all numeric parameters to [0,1] range.
result.Add(lvg.NormalizeValue(new LongParameterValue(pset.Name, longValue)));
}
else if (sweepParam is FloatValueGenerator fvg)
{
var floatValue = GetIfIParameterValueOfT<float>(pset) ?? float.Parse(pset.ValueText, CultureInfo.InvariantCulture);
// Normalizing all numeric parameters to [0,1] range.
result.Add(fvg.NormalizeValue(new FloatParameterValue(pset.Name, floatValue)));
}
else
{
throw new InvalidOperationException("Smart sweeper can only sweep over discrete and numeric parameters");
}
}
return result.ToArray();
}
private static T? GetIfIParameterValueOfT<T>(IParameterValue parameterValue)
where T : struct =>
parameterValue is IParameterValue<T> pvt ? pvt.Value : default(T?);
public static ParameterSet FloatArrayAsParameterSet(IValueGenerator[] sweepParams, float[] array, bool expandedCategoricals = true)
{
Runtime.Contracts.Assert(array.Length == sweepParams.Length);
List<IParameterValue> parameters = new List<IParameterValue>();
int currentArrayIndex = 0;
for (int i = 0; i < sweepParams.Length; i++)
{View on GitHub (pinned to 7b76e69cf9)
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.
Example fix
// before
var param = new Sweepable<string>("a", "b"); // swept by SmartSweeper
// after
var param = new Sweepable<string>("a", "b"); // use with RandomSweeper, or map to numeric index for SmartSweeper Defensive patterns
Strategy: validation
Validate before calling
foreach (var p in parameterSet)
if (!(p is FloatParameterValue || p is BoolParameterValue || long.TryParse(p.ValueText, out _) || float.TryParse(p.ValueText, out _)))
throw new ArgumentException($"Parameter {p.Name} is not numeric/discrete"); Type guard
bool IsSweepableBySmartSweeper<T>(T p) where T : IParameterValue => p is FloatParameterValue or DoubleParameterValue or BoolParameterValue;
Try / catch
try { float[] arr = SweeperProbabilityUtils.ParameterSetAsFloatArray(pset); }
catch (InvalidOperationException ex) { /* switch to RandomSweeper for this parameter set */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Defining a Sweepable<string> or string option in a search space swept by SMAC/KD-type smart sweepers that only handle float/bool.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SMAC sweeper localSearch threw exception
- {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/19fe0d7c20fe64c5.
Report an issue: GitHub.