88
99from __future__ import annotations
1010
11+ import warnings
1112from collections .abc import Mapping
1213from itertools import groupby
1314from typing import Self
@@ -80,11 +81,17 @@ def __init__(
8081 consideration, and if not, the parameter value will be replaced with
8182 the corresponding value in the target arm.
8283 """
84+ if objective is not None :
85+ warnings .warn (
86+ "Passing `objective` to OptimizationConfig is deprecated. "
87+ "Use `objectives=[objective]` instead." ,
88+ DeprecationWarning ,
89+ stacklevel = 2 ,
90+ )
8391 if objective is not None and objectives is not None :
8492 raise UserInputError (
8593 "Cannot specify both `objective` and `objectives`. "
86- "Use `objective` for single-objective optimization or "
87- "`objectives` for multi-objective optimization."
94+ "Use `objectives=[objective]` instead."
8895 )
8996 if objective is None and objectives is None :
9097 raise UserInputError ("Must specify either `objective` or `objectives`." )
@@ -113,7 +120,6 @@ def clone(self) -> Self:
113120 def clone_with_args (
114121 self ,
115122 * ,
116- objective : Objective | None = None ,
117123 objectives : list [Objective ] | None = None ,
118124 outcome_constraints : None | (list [OutcomeConstraint ]) = _NO_OUTCOME_CONSTRAINTS ,
119125 pruning_target_parameterization : Arm
@@ -122,21 +128,12 @@ def clone_with_args(
122128 """Make a copy of this optimization config.
123129
124130 Args:
125- objective: Replace with a single objective. Mutually exclusive
126- with ``objectives``.
127- objectives: Replace with a list of objectives. Mutually exclusive
128- with ``objective``.
131+ objectives: Replace with a list of objectives.
129132 outcome_constraints: Replace outcome constraints. Pass ``None``
130133 to clear them.
131134 pruning_target_parameterization: Replace the pruning target.
132135 """
133- if objective is not None and objectives is not None :
134- raise UserInputError (
135- "Cannot specify both `objective` and `objectives` in clone_with_args."
136- )
137- if objective is not None :
138- cloned_objectives = [objective ]
139- elif objectives is not None :
136+ if objectives is not None :
140137 cloned_objectives = objectives
141138 else :
142139 cloned_objectives = [obj .clone () for obj in self ._objectives ]
@@ -182,15 +179,6 @@ def objective(self) -> Objective:
182179 )
183180 return self ._objectives [0 ]
184181
185- @objective .setter
186- def objective (self , objective : Objective ) -> None :
187- """Set objective. Only valid for single-objective configs."""
188- self ._validate_transformed_optimization_config (
189- objectives = [objective ],
190- outcome_constraints = self .outcome_constraints ,
191- )
192- self ._objectives = [objective ]
193-
194182 @property
195183 def all_constraints (self ) -> list [OutcomeConstraint ]:
196184 """Get outcome constraints."""
@@ -449,7 +437,6 @@ def __init__(
449437 def clone_with_args (
450438 self ,
451439 * ,
452- objective : Objective | None = None ,
453440 objectives : list [Objective ] | None = None ,
454441 outcome_constraints : None | (list [OutcomeConstraint ]) = _NO_OUTCOME_CONSTRAINTS ,
455442 objective_thresholds : None
@@ -458,13 +445,7 @@ def clone_with_args(
458445 | None = _NO_PRUNING_TARGET_PARAMETERIZATION ,
459446 ) -> "MultiObjectiveOptimizationConfig" :
460447 """Make a copy of this optimization config."""
461- if objective is not None and objectives is not None :
462- raise UserInputError (
463- "Cannot specify both `objective` and `objectives` in clone_with_args."
464- )
465- if objective is not None :
466- cloned_objectives = [objective ]
467- elif objectives is not None :
448+ if objectives is not None :
468449 cloned_objectives = objectives
469450 else :
470451 cloned_objectives = [obj .clone () for obj in self ._objectives ]
@@ -702,15 +683,19 @@ def is_bope_problem(self) -> bool:
702683 def clone_with_args (
703684 self ,
704685 * ,
705- objective : Objective | None = None ,
686+ objectives : list [ Objective ] | None = None ,
706687 preference_profile_name : str | None = None ,
707688 outcome_constraints : list [OutcomeConstraint ] | None = _NO_OUTCOME_CONSTRAINTS ,
708689 expect_relativized_outcomes : bool | None = None ,
709690 pruning_target_parameterization : Arm
710691 | None = _NO_PRUNING_TARGET_PARAMETERIZATION ,
711692 ) -> PreferenceOptimizationConfig :
712693 """Make a copy of this optimization config."""
713- objective = self ._objectives [0 ].clone () if objective is None else objective
694+ cloned_objectives = (
695+ [obj .clone () for obj in self ._objectives ]
696+ if objectives is None
697+ else objectives
698+ )
714699
715700 preference_profile_name = (
716701 self .preference_profile_name
@@ -734,7 +719,7 @@ def clone_with_args(
734719 )
735720
736721 return PreferenceOptimizationConfig (
737- objective = objective ,
722+ objectives = cloned_objectives ,
738723 preference_profile_name = preference_profile_name ,
739724 outcome_constraints = outcome_constraints ,
740725 expect_relativized_outcomes = expect_relativized_outcomes ,
0 commit comments