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
TypeError – The
emitters
argument was not a list of emitters.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
.ValueError – The
result_archive
andarchive
are the same object (result_archive
should not be passed in in this case).ValueError – The
result_archive
andarchive
have different fields.
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, measures, **fields)Returns info for solutions from
ask()
.tell_dqd
(objective, measures, jacobian, **fields)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, measures, **fields)[source]¶
Returns info for solutions from
ask()
.Note
The objective and measures arrays must be in the same order as the solutions created by
ask_dqd()
; i.e.objective[i]
andmeasures[i]
should be the objective and measures forsolution[i]
.- Parameters
objective ((batch_size,) array) – Each entry of this array contains the objective function evaluation of a solution.
measures ((batch_size, measures_dm) array) – Each row of this array contains a solution’s coordinates in measure space.
fields (keyword arguments) – Additional data for each solution. Each argument should be an array with batch_size as the first dimension.
- Raises
RuntimeError – This method is called without first calling
ask()
.ValueError – One of the inputs has the wrong shape.
- tell_dqd(objective, measures, jacobian, **fields)[source]¶
Returns info for solutions from
ask_dqd()
.Note
The objective, measures, and jacobian arrays must be in the same order as the solutions created by
ask_dqd()
; i.e.objective[i]
,measures[i]
, andjacobian[i]
should be the objective, measures, and jacobian forsolution[i]
.- Parameters
objective ((batch_size,) array) – Each entry of this array contains the objective function evaluation of a solution.
measures ((batch_size, measure_dim) array) – Each row of this array contains a solution’s coordinates in measure space.
jacobian (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.fields (keyword arguments) – Additional data for each solution. Each argument should be an array with batch_size as the first dimension.
- Raises
RuntimeError – This method is called without first calling
ask()
.ValueError – One of the inputs 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