File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222# TODO: Do a more comprehensive audit of how floating point precision issues
2323# may creep up and implement a more principled fix
2424EPS = 1.5e-7
25-
25+ MAX_VALUES_CHOICE_PARAM = 1000
2626FIXED_CHOICE_PARAM_ERROR = (
2727 "ChoiceParameters require multiple feasible values. "
2828 "Please use FixedParameter instead when setting a single possible value."
@@ -474,6 +474,12 @@ def __init__(
474474 # A choice parameter with only one value is a FixedParameter.
475475 if not len (values ) > 1 :
476476 raise UserInputError (f"{ self ._name } ({ values } ): { FIXED_CHOICE_PARAM_ERROR } " )
477+ # Cap the number of possible values
478+ if len (values ) > MAX_VALUES_CHOICE_PARAM :
479+ raise UserInputError (
480+ f"`ChoiceParameter` with more than { MAX_VALUES_CHOICE_PARAM } values "
481+ "is not supported! Use a `RangeParameter` instead."
482+ )
477483 # pyre-fixme[4]: Attribute must be annotated.
478484 self ._values = self ._cast_values (values )
479485 # pyre-fixme[4]: Attribute must be annotated.
Original file line number Diff line number Diff line change @@ -315,6 +315,23 @@ def testHierarchicalValidation(self) -> None:
315315 dependents = {"not_a_value" : "other_param" },
316316 )
317317
318+ def testMaxValuesValidation (self ) -> None :
319+ ChoiceParameter (
320+ name = "x" ,
321+ parameter_type = ParameterType .INT ,
322+ values = list (range (999 )), # pyre-ignore
323+ )
324+ with self .assertRaisesRegex (
325+ UserInputError ,
326+ "`ChoiceParameter` with more than 1000 values is not supported! Use a "
327+ "`RangeParameter` instead." ,
328+ ):
329+ ChoiceParameter (
330+ name = "x" ,
331+ parameter_type = ParameterType .INT ,
332+ values = list (range (1001 )), # pyre-ignore
333+ )
334+
318335 def testHierarchical (self ) -> None :
319336 # Test case where only some of the values entail dependents.
320337 hierarchical_param = ChoiceParameter (
You can’t perform that action at this time.
0 commit comments