Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion ax/storage/json_store/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
OptimizationConfig,
PreferenceOptimizationConfig,
)
from ax.core.outcome_constraint import OutcomeConstraint
from ax.core.outcome_constraint import OutcomeConstraint, ScalarizedOutcomeConstraint
from ax.core.parameter import (
ChoiceParameter,
DerivedParameter,
Expand Down Expand Up @@ -362,6 +362,21 @@ def outcome_constraint_to_dict(outcome_constraint: OutcomeConstraint) -> dict[st
}


def scalarized_outcome_constraint_to_dict(
outcome_constraint: ScalarizedOutcomeConstraint,
) -> dict[str, Any]:
"""Convert Ax scalarized outcome constraint to a dictionary."""
metrics = [Metric(name=name) for name, _ in outcome_constraint.metric_weights]
return {
"__type": outcome_constraint.__class__.__name__,
"metrics": metrics,
"weights": outcome_constraint.weights,
"op": outcome_constraint.op,
"bound": outcome_constraint.bound,
"relative": outcome_constraint.relative,
}


def optimization_config_to_dict(
optimization_config: OptimizationConfig,
) -> dict[str, Any]:
Expand Down
9 changes: 8 additions & 1 deletion ax/storage/json_store/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
OptimizationConfig,
PreferenceOptimizationConfig,
)
from ax.core.outcome_constraint import ObjectiveThreshold, OutcomeConstraint
from ax.core.outcome_constraint import (
ObjectiveThreshold,
OutcomeConstraint,
ScalarizedOutcomeConstraint,
)
from ax.core.parameter import (
ChoiceParameter,
DerivedParameter,
Expand Down Expand Up @@ -159,6 +163,7 @@
range_parameter_to_dict,
runner_to_dict,
scalarized_objective_to_dict,
scalarized_outcome_constraint_to_dict,
search_space_to_dict,
surrogate_to_dict,
threshold_early_stopping_strategy_to_dict,
Expand Down Expand Up @@ -255,6 +260,7 @@
OptimizationConfig: optimization_config_to_dict,
OrEarlyStoppingStrategy: logical_early_stopping_strategy_to_dict,
OutcomeConstraint: outcome_constraint_to_dict,
ScalarizedOutcomeConstraint: scalarized_outcome_constraint_to_dict,
ParameterConstraint: parameter_constraint_to_dict,
pathlib.Path: pathlib_to_dict,
pathlib.PurePath: pathlib_to_dict,
Expand Down Expand Up @@ -410,6 +416,7 @@
"ReductionCriterion": ReductionCriterion,
"Round": Round,
"ScalarizedObjective": ScalarizedObjective,
"ScalarizedOutcomeConstraint": ScalarizedOutcomeConstraint,
"SchedulerOptions": OrchestratorOptions, # DEPRECATED; backward compatibility
"SearchSpace": SearchSpace,
"SimTrial": SimTrial,
Expand Down
2 changes: 2 additions & 0 deletions ax/storage/json_store/tests/test_json_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
get_percentile_early_stopping_strategy_with_non_objective_metric_signature,
get_range_parameter,
get_scalarized_objective,
get_scalarized_outcome_constraint,
get_search_space,
get_sorted_choice_parameter,
get_sum_constraint1,
Expand Down Expand Up @@ -391,6 +392,7 @@
("ParameterConstraint", get_parameter_constraint),
("RangeParameter", get_range_parameter),
("ScalarizedObjective", get_scalarized_objective),
("ScalarizedOutcomeConstraint", get_scalarized_outcome_constraint),
("OrchestratorOptions", get_default_orchestrator_options),
("OrchestratorOptions", get_orchestrator_options_batch_trial),
("SearchSpace", get_search_space),
Expand Down