Skip to content

Commit

Permalink
Merge pull request optuna#5581 from RektPunk/refactor-rank-subplot-info
Browse files Browse the repository at this point in the history
Remove redundant loop in `_get_rank_subplot_info`
  • Loading branch information
c-bata authored Jul 25, 2024
2 parents 8781df0 + 172a0f5 commit 551b1d9
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions optuna/visualization/_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,20 @@ def _get_rank_subplot_info(
yaxis = _get_axis_info(trials, y_param)

infeasible_trial_ids = []
for i in range(len(trials)):
constraints = trials[i].system_attrs.get(_CONSTRAINTS_KEY)
filtered_ids = []
for idx, trial in enumerate(trials):
constraints = trial.system_attrs.get(_CONSTRAINTS_KEY)
if constraints is not None and any([x > 0.0 for x in constraints]):
infeasible_trial_ids.append(i)
infeasible_trial_ids.append(idx)
if x_param in trial.params and y_param in trial.params:
filtered_ids.append(idx)

colors[infeasible_trial_ids] = (204, 204, 204) # equal to "#CCCCCC"

filtered_ids = [
i
for i in range(len(trials))
if x_param in trials[i].params and y_param in trials[i].params
]
filtered_trials = [trials[i] for i in filtered_ids]
xs = [trial.params[x_param] for trial in filtered_trials]
ys = [trial.params[y_param] for trial in filtered_trials]
zs = target_values[filtered_ids]

colors[infeasible_trial_ids] = (204, 204, 204)
colors = colors[filtered_ids]
return _RankSubplotInfo(
xaxis=xaxis,
Expand Down

0 comments on commit 551b1d9

Please sign in to comment.