Skip to content

Commit

Permalink
Turn warning about two-val choice parameter being considered ordered,…
Browse files Browse the repository at this point in the history
… into a debug log (#2920)

Summary:
Pull Request resolved: #2920

As titled

Reviewed By: saitcakmak

Differential Revision: D64604105

fbshipit-source-id: 54d636bb14c85771178d06ddf45ac2c926bae42d
  • Loading branch information
Lena Kashtelyan authored and facebook-github-bot committed Oct 18, 2024
1 parent c7382f8 commit 37e5740
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
5 changes: 4 additions & 1 deletion ax/core/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
from ax.core.types import TNumeric, TParamValue, TParamValueList
from ax.exceptions.core import AxParameterWarning, UserInputError
from ax.utils.common.base import SortableBase
from ax.utils.common.logger import get_logger
from ax.utils.common.typeutils import not_none
from pyre_extensions import assert_is_instance

logger = get_logger(__name__)

# Tolerance for floating point comparisons. This is relatively permissive,
# and allows for serializing at rather low numerical precision.
# TODO: Do a more comprehensive audit of how floating point precision issues
Expand Down Expand Up @@ -584,7 +587,7 @@ def __init__(

if is_ordered is False and len(values) == 2:
is_ordered = True
warn(
logger.debug(
f"Changing `is_ordered` to `True` for `ChoiceParameter` '{name}' since "
"there are only two possible values.",
AxParameterWarning,
Expand Down
21 changes: 8 additions & 13 deletions ax/core/tests/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,14 @@ def test_two_values_is_ordered(self) -> None:
)
self.assertEqual(p._is_ordered, True)

# Change `is_ordered` to True and warn
with self.assertWarnsRegex(
AxParameterWarning,
"Changing `is_ordered` to `True` for `ChoiceParameter` 'x' since "
"there are only two possible values",
):
p = ChoiceParameter(
name="x",
parameter_type=parameter_type,
values=values, # pyre-ignore
is_ordered=False,
)
self.assertEqual(p._is_ordered, True)
# Change `is_ordered` to True
p = ChoiceParameter(
name="x",
parameter_type=parameter_type,
values=values, # pyre-ignore
is_ordered=False,
)
self.assertEqual(p._is_ordered, True)

# Set to True if `is_ordered` is not specified
with self.assertWarnsRegex(
Expand Down

0 comments on commit 37e5740

Please sign in to comment.