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

BanditScheduler: Add emitter_pool and active attr; remove emitters attr #494

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#### API

- **Backwards-incompatible:** BanditScheduler: Add emitter_pool and active attr;
remove emitters attr ({pr}`494`)
- Add DensityRanker for density descent search ({pr}`483`)
- Add NoveltyRanker for novelty search ({pr}`477`)
- Add proximity_archive_plot for visualizing ProximityArchive ({pr}`476`,
Expand Down
15 changes: 11 additions & 4 deletions ribs/schedulers/_bandit_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np

from ribs._utils import readonly
from ribs.schedulers._scheduler import Scheduler


Expand Down Expand Up @@ -172,10 +173,16 @@ def archive(self):
return self._archive

@property
def emitters(self):
"""list of ribs.archives.EmitterBase: Emitters for generating solutions
in this scheduler."""
return self._active_arr
def emitter_pool(self):
"""list of ribs.archives.EmitterBase: The pool of emitters available in
the scheduler."""
return self._emitter_pool

@property
def active(self):
"""numpy.ndarray: Boolean array indicating which emitters in the
:attr:`emitter_pool` are currently active."""
return readonly(self._active_arr)

@property
def result_archive(self):
Expand Down
23 changes: 23 additions & 0 deletions tests/schedulers/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ def add_mode(request):
return request.param


@pytest.mark.parametrize("scheduler_type", ["Scheduler", "BanditScheduler"])
def test_attributes(scheduler_type):
archive = GridArchive(solution_dim=2,
dims=[100, 100],
ranges=[(-1, 1), (-1, 1)],
threshold_min=1.0,
learning_rate=1.0)
emitters = [GaussianEmitter(archive, sigma=1, x0=[0.0, 0.0], batch_size=4)]

if scheduler_type == "Scheduler":
scheduler = Scheduler(archive, emitters)

assert scheduler.archive == archive
assert scheduler.emitters == emitters
else:
scheduler = BanditScheduler(archive, emitters, 1)

assert scheduler.archive == archive
assert scheduler.emitter_pool == emitters
assert len(scheduler.active) == len(scheduler.emitter_pool)
assert not np.any(scheduler.active)


def test_init_fails_with_non_list():
archive = GridArchive(solution_dim=2,
dims=[100, 100],
Expand Down
Loading