Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix INGO implementation #125

Merged
merged 3 commits into from
Aug 2, 2024
Merged
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
9 changes: 4 additions & 5 deletions package/samplers/implicit_natural_gradient/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
self._independent_sampler = independent_sampler or optuna.samplers.RandomSampler(seed=seed)
self._n_startup_trials = n_startup_trials
self._warn_independent_sampling = warn_independent_sampling
self._search_space = optuna.samplers.IntersectionSearchSpace()
self._search_space = optuna.search_space.IntersectionSearchSpace()
self._optimizer: Optional[FastINGO] = None
self._seed = seed
self._population_size = population_size
Expand Down Expand Up @@ -174,7 +174,7 @@ def _pop_from_param_queue(
study._storage.set_trial_system_attr(
trial_id, _GENERATION_ATTR_KEY, self._get_optimizer().generation
)
return self._param_queue.pop()
return self._param_queue.pop(0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of popping must be the same as the _z in FastINGO.


def _check_trial_is_generation(self, trial: FrozenTrial) -> bool:
current_gen = self._get_optimizer().generation
Expand All @@ -192,7 +192,7 @@ def sample_relative(
if len(search_space) == 0:
return {}

completed_trials = study.get_trials(deepcopy=True, states=[TrialState.COMPLETE])
completed_trials = study.get_trials(deepcopy=False, states=[TrialState.COMPLETE])
if len(completed_trials) < self._n_startup_trials:
return {}

Expand Down Expand Up @@ -233,9 +233,8 @@ def sample_relative(
for i, t in enumerate(solution_trials[: self._optimizer.population_size]):
assert t.value is not None, "completed trials must have a value"
solutions_x[i, :] = trans.transform(t.params)
# TODO(c-bata): Check whether FastINGO assumes maximize or minimize problem
solutions_y[i] = (
-t.value if study.direction == StudyDirection.MINIMIZE else t.value
-t.value if study.direction == StudyDirection.MAXIMIZE else t.value
)
self._optimizer.tell(solutions_x, solutions_y)

Expand Down