# ribs.optimizers.Optimizer¶

class ribs.optimizers.Optimizer(archive, emitters)[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 Optimizer with these arguments. Finally, repeatedly call ask() to collect solutions to analyze, and return the objective values and behavior values of those solutions in the same order using tell().

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 of EmitterClass in each position. Instead, use [EmitterClass(...) for _ in range 5], which creates 5 unique instances of EmitterClass.

Parameters
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).

Methods

 Generates a batch of solutions by calling ask() on all emitters. tell(objective_values, behavior_values[, …]) Returns info for solutions from ask().

Attributes

 archive Archive for storing solutions found in this optimizer. emitters Emitters for generating solutions 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

(n_solutions, dim) array

Raises
• RuntimeError – This method was called without first calling tell().

• ValueErroremitter_kwargs is a list of dict but the list length is not the same as the number of emitters.

tell(objective_values, behavior_values, metadata=None)[source]

Returns info for solutions from ask().

Note

The objective values, behavior values, and metadata must be in the same order as the solutions created by ask(); i.e. objective_values[i], behavior_values[i], and metadata[i] should be the objective value, behavior values, and metadata for solutions[i].

Parameters
• objective_values ((n_solutions,) array) – Each entry of this array contains the objective function evaluation of a solution.

• behavior_values ((n_solutions, behavior_dm) array) – Each row of this array contains a solution’s coordinates in behavior space.

• metadata ((n_solutions,) array) – Each entry of this array contains an object holding metadata for a solution.

Raises
• RuntimeError – This method is called without first calling ask().

• ValueErrorobjective_values, behavior_values, or metadata has the wrong shape.

• ValueErroremitter_kwargs is a list of dict but the list length is not the same as the number of emitters.

property archive

Archive for storing solutions found in this optimizer.

Type

ribs.archives.ArchiveBase

property emitters

Emitters for generating solutions in this optimizer.

Type

list of ribs.archives.EmitterBase