|
17 | 17 | import numpy as np |
18 | 18 | import numpy.typing as npt |
19 | 19 | import torch |
| 20 | +from ax.adapter.parameter_utils import ( # noqa: F401 |
| 21 | + can_map_to_binary, |
| 22 | + is_unordered_choice, |
| 23 | +) |
20 | 24 | from ax.adapter.transforms.base import Transform |
21 | 25 | from ax.adapter.transforms.utils import ( |
22 | 26 | derelativize_optimization_config_with_raw_status_quo, |
|
35 | 39 | OutcomeConstraint, |
36 | 40 | ScalarizedOutcomeConstraint, |
37 | 41 | ) |
38 | | -from ax.core.parameter import ChoiceParameter, Parameter, ParameterType, RangeParameter |
| 42 | +from ax.core.parameter import ChoiceParameter, ParameterType, RangeParameter |
39 | 43 | from ax.core.parameter_constraint import ParameterConstraint |
40 | 44 | from ax.core.search_space import SearchSpace, SearchSpaceDigest |
41 | 45 | from ax.core.types import TBounds, TCandidateMetadata, TNumeric |
@@ -1438,56 +1442,3 @@ def _consolidate_comparisons(X: Tensor, Y: Tensor) -> tuple[Tensor, Tensor]: |
1438 | 1442 |
|
1439 | 1443 | X, Y, _ = consolidate_duplicates(X, Y) |
1440 | 1444 | return X, Y |
1441 | | - |
1442 | | - |
1443 | | -def is_unordered_choice( |
1444 | | - p: Parameter, min_choices: int | None = None, max_choices: int | None = None |
1445 | | -) -> bool: |
1446 | | - """Returns whether a parameter is an unordered choice (categorical) parameter. |
1447 | | -
|
1448 | | - You can also specify `min_choices` and `max_choices` to restrict how many |
1449 | | - possible values the parameter can take on. |
1450 | | -
|
1451 | | - Args: |
1452 | | - p: Parameter. |
1453 | | - min_choices: The minimum number of possible values for the parameter. |
1454 | | - max_choices: The maximum number of possible values for the parameter. |
1455 | | -
|
1456 | | - Returns: |
1457 | | - A boolean indicating whether p is an unordered choice parameter or not. |
1458 | | - """ |
1459 | | - if min_choices is not None and min_choices < 0: |
1460 | | - raise UserInputError("`min_choices` must be a non-negative integer.") |
1461 | | - if max_choices is not None and max_choices < 0: |
1462 | | - raise UserInputError("`max_choices` must be a non-negative integer.") |
1463 | | - if ( |
1464 | | - min_choices is not None |
1465 | | - and max_choices is not None |
1466 | | - and min_choices > max_choices |
1467 | | - ): |
1468 | | - raise UserInputError("`min_choices` cannot be larger than `max_choices`.") |
1469 | | - return ( |
1470 | | - isinstance(p, ChoiceParameter) |
1471 | | - and not p.is_ordered |
1472 | | - and (min_choices is None or min_choices <= len(p.values)) |
1473 | | - and (max_choices is None or max_choices >= len(p.values)) |
1474 | | - ) |
1475 | | - |
1476 | | - |
1477 | | -def can_map_to_binary(p: Parameter) -> bool: |
1478 | | - """Returns whether a parameter can be transformed to a binary parameter. |
1479 | | -
|
1480 | | - Any choice/range parameters with exactly two values can be transformed to a |
1481 | | - binary parameter. |
1482 | | -
|
1483 | | - Args: |
1484 | | - p: Parameter. |
1485 | | -
|
1486 | | - Returns |
1487 | | - A boolean indicating whether p can be transformed to a binary parameter. |
1488 | | - """ |
1489 | | - return (isinstance(p, ChoiceParameter) and len(p.values) == 2) or ( |
1490 | | - isinstance(p, RangeParameter) |
1491 | | - and p.parameter_type == ParameterType.INT |
1492 | | - and p.lower == p.upper - 1 |
1493 | | - ) |
0 commit comments