Skip to content
Open
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
15 changes: 9 additions & 6 deletions optuna/samplers/_gp/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,15 @@ def after_trial(
def _get_constraint_vals_and_feasibility(
study: Study, trials: list[FrozenTrial]
) -> tuple[np.ndarray, np.ndarray]:
_constraint_vals = [
study._storage.get_trial_system_attrs(trial._trial_id).get(_CONSTRAINTS_KEY, ())
for trial in trials
]
if any(len(_constraint_vals[0]) != len(c) for c in _constraint_vals):
raise ValueError("The number of constraints must be the same for all trials.")
_constraint_vals = []
expected_len = None
for trial in trials:
c = study._storage.get_trial_system_attrs(trial._trial_id).get(_CONSTRAINTS_KEY, ())
if expected_len is None:
expected_len = len(c)
elif len(c) != expected_len:
raise ValueError("The number of constraints must be the same for all trials.")
_constraint_vals.append(c)

constraint_vals = np.array(_constraint_vals)
assert len(constraint_vals.shape) == 2, "constraint_vals must be a 2d array."
Expand Down