ribs.schedulers.Scheduler¶
- class ribs.schedulers.Scheduler(archive, emitters, *, result_archive=None, add_mode='batch')[source]¶
A basic class that composes an archive with multiple emitters.
To use this class, first create an archive and list of emitters for the QD algorithm. Then, construct the Scheduler with these arguments. Finally, repeatedly call
ask()
to collect solutions to analyze, and return the objective and measures of those solutions in the same order usingtell()
.As all solutions go into the same archive, the emitters passed in must emit solutions with the same dimension (that is, their
solution_dim
attribute must be the same).Warning
If you are constructing many emitters at once, do not do something like
[EmitterClass(...)] * 5
, as this creates a list with the same instance ofEmitterClass
in each position. Instead, use[EmitterClass(...) for _ in range 5]
, which creates 5 unique instances ofEmitterClass
.- Parameters
archive (ribs.archives.ArchiveBase) – An archive object, e.g. one selected from
ribs.archives
.emitters (list of ribs.archives.EmitterBase) – A list of emitter objects, e.g.
ribs.emitters.GaussianEmitter
.add_mode (str) – Indicates how solutions should be added to the archive. The default is “batch”, which adds all solutions with one call to
add()
. Alternatively, use “single” to add the solutions one at a time withadd_single()
. “single” mode is included for legacy reasons, as it was the only mode of operation in pyribs 0.4.0 and before. We highly recommend using “batch” mode since it is significantly faster.result_archive (ribs.archives.ArchiveBase) – In some algorithms, such as CMA-MAE, the archive does not store all the best-performing solutions. The result_archive is a secondary archive where we can store all the best-performing solutions.
- Raises
ValueError – The emitters passed in do not have the same solution dimensions.
ValueError – There is no emitter passed in.
ValueError – The same emitter instance was passed in multiple times. Each emitter should be a unique instance (see the warning above).
ValueError – Invalid value for add_mode.
Methods
ask
()Generates a batch of solutions by calling ask() on all emitters.
ask_dqd
()Generates a batch of solutions by calling ask_dqd() on all DQD emitters.
tell
(objective_batch, measures_batch[, ...])Returns info for solutions from
ask()
.tell_dqd
(objective_batch, measures_batch, ...)Returns info for solutions from
ask_dqd()
.Attributes
EMPTY_WARNING
Archive for storing solutions found in this scheduler.
Emitters for generating solutions in this scheduler.
Another archive for storing solutions found in this optimizer.
- ask()[source]¶
Generates a batch of solutions by calling ask() on all emitters.
Note
The order of the solutions returned from this method is important, so do not rearrange them.
- Returns
An array of n solutions to evaluate. Each row contains a single solution.
- Return type
(batch_size, dim) array
- Raises
RuntimeError – This method was called without first calling
tell()
.
- ask_dqd()[source]¶
Generates a batch of solutions by calling ask_dqd() on all DQD emitters.
Note
The order of the solutions returned from this method is important, so do not rearrange them.
- Returns
An array of n solutions to evaluate. Each row contains a single solution.
- Return type
(batch_size, dim) array
- Raises
RuntimeError – This method was called without first calling
tell()
.
- tell(objective_batch, measures_batch, metadata_batch=None)[source]¶
Returns info for solutions from
ask()
.Note
The objective batch, measures batch, and metadata batch must be in the same order as the solutions created by
ask_dqd()
; i.e.objective_batch[i]
,measures_batch[i]
, andmetadata_batch[i]
should be the objective, measures, and metadata forsolution_batch[i]
.- Parameters
objective_batch ((batch_size,) array) – Each entry of this array contains the objective function evaluation of a solution.
measures_batch ((batch_size, measures_dm) array) – Each row of this array contains a solution’s coordinates in measure space.
metadata_batch ((batch_size,) array) – Each entry of this array contains an object holding metadata for a solution.
- Raises
RuntimeError – This method is called without first calling
ask()
.ValueError –
objective_batch
,measures_batch
, ormetadata
has the wrong shape.
- tell_dqd(objective_batch, measures_batch, jacobian_batch, metadata_batch=None)[source]¶
Returns info for solutions from
ask_dqd()
.Note
The objective batch, measures batch, jacobian batch, and metadata batch must be in the same order as the solutions created by
ask_dqd()
; i.e.objective_batch[i]
,measures_batch[i]
,jacobian_batch[i]
, andmetadata_batch[i]
should be the objective, measures, jacobian, and metadata forsolution_batch[i]
.- Parameters
objective_batch ((batch_size,) array) – Each entry of this array contains the objective function evaluation of a solution.
measures_batch ((batch_size, measure_dim) array) – Each row of this array contains a solution’s coordinates in measure space.
jacobian_batch (numpy.ndarray) –
(batch_size, 1 + measure_dim, solution_dim)
array consisting of Jacobian matrices of the solutions obtained fromask_dqd()
. Each matrix should consist of the objective gradient of the solution followed by the measure gradients.metadata_batch ((batch_size,) array) – Each entry of this array contains an object holding metadata for a solution.
- Raises
RuntimeError – This method is called without first calling
ask()
.ValueError –
objective_batch
,measures_batch
, ormetadata_batch
has the wrong shape.
- property archive¶
Archive for storing solutions found in this scheduler.
- property emitters¶
Emitters for generating solutions in this scheduler.
- Type
list of ribs.archives.EmitterBase