QDpy
Loading...
Searching...
No Matches
qdpy.algorithms.base.QDAlgorithm Class Reference
Inheritance diagram for qdpy.algorithms.base.QDAlgorithm:
qdpy.algorithms.base.QDAlgorithmLike qdpy.base.Summarisable qdpy.base.Saveable qdpy.base.Copyable qdpy.base.CreatableFromConfig qdpy.algorithms.base.AlgWithBatchSuggestions qdpy.algorithms.base.AlgWrapper qdpy.algorithms.base.FromArchive qdpy.algorithms.base.Lambda qdpy.algorithms.dynamic_mutation.DynamicMutationMAPElites qdpy.algorithms.evolution.CMAES qdpy.algorithms.evolution.Evolution qdpy.algorithms.evolution.MutGaussian.CMAES qdpy.algorithms.gram_elites.GramElites qdpy.algorithms.modern.IsoLineMAPElites qdpy.algorithms.modern._FixedGeneration qdpy.algorithms.monte_carlo.MonteCarloElites qdpy.algorithms.sampling.SamplingDecorator qdpy.algorithms.search.RandomUniform sequence_distribution_qd._TileBaseline

Public Member Functions

None reinit (self)
Union[str, Sequence[float]] optimisation_task (self)
None optimisation_task (self, Union[str, Sequence[float]] optimisation_task)
int nb_suggestions (self)
int nb_suggestions_in_iteration (self)
int nb_evaluations (self)
int nb_evaluations_in_iteration (self)
int nb_updated (self)
int nb_updated_in_iteration (self)
int batch_size (self)
Union[int, float] nb_max_iter (self)
int current_iter (self)
IndividualLike ask (self)
bool tell (self, IndividualLike individual, Optional[Any] fitness=None, Optional[FeaturesLike] features=None, Optional[ScoresDictLike] scores=None, Optional[float] elapsed=None, bool verbose=False, tell_container=True)
None tell_container_entries (self, Optional[Container] cont=None)
IndividualLike best (self)
IndividualLike optimise (self, Callable evaluate, Optional[int] budget=None, bool batch_mode=True, Optional[ExecutorLike] executor=None, bool send_several_suggestions_to_fn=False, int max_nb_suggestions_per_call=10, bool verbose=False)
None add_callback (self, str event, Callable fn)
Public Member Functions inherited from qdpy.base.Summarisable
Mapping[str, Any] __get_summary_state__ (self)
str summary (self, Optional[int] max_depth=None, Optional[int] max_entry_length=250)
Public Member Functions inherited from qdpy.base.Saveable
Mapping[str, Any] __get_saved_state__ (self)
None save (self, str output_path, str output_type="pickle")
Public Member Functions inherited from qdpy.base.CreatableFromConfig
Any from_config (cls, Mapping[str, Any] config, **Any kwargs)

Protected Member Functions

 _check_archive_weights (self)
IndividualLike _internal_ask (self, IndividualLike base_ind)
None _attach_evaluation (self, ind, fitness, features, scores, elapsed)
Tuple[MutableMapping[str, Any], bool] _tell_before_container_update (self, IndividualLike individual)
 Read pre-admission state for optimiser feedback.
None _tell_after_container_update (self, IndividualLike individual, bool added, Mapping[str, Any] xattr={})
 Account for a completed tell and send feedback.
None _internal_tell (self, IndividualLike individual, bool added_to_container, Mapping[str, Any] xattr={})
IndividualLike _internal_best (self)
bool _verify_if_finished_iteration (self, float batch_start_time)
None _transfer_suggestion (self, IndividualLike individual, IndividualLike evaluated)
 Transfer coordinator-side metadata when evaluation returns a new object.
None _start_fixed_batch (self, int size)
None _receive_fixed_batch (self, records, verbose, batch_start_time)
 _fixed_batch_plan (self, size, evaluate, packed)

Detailed Description

Combine a candidate generator, an evaluation budget, and an archive.

The container resolves objective and descriptor vectors and controls
admission. The optimiser generates genomes and consumes feedback.
Ask and tell support an application-managed evaluator. Optimise adds
scheduling, timing, and callbacks to the same protocol.

:param container: Archive used for admission and best-candidate queries.
:param budget: Candidate evaluations available to each managed run.
:param batch_size: Candidates in one iteration and maximum number
    pending at once. Defaults to the budget.
:param dimension: Genome length for algorithms that generate vectors.
:param nb_objectives: Objective count. When omitted, infer it from
    the container's fitness domain or use one objective.
:param optimisation_task: Minimise, maximise, or supply one finite
    comparison weight per objective.
:param base_ind_gen: Iterator supplying a fresh candidate for each ask.
:param tell_container_at_init: Feed stored entries to the algorithm
    when true or ``"yes"``. Use ``"parents"`` to feed entries from
    immediate parents and pass their child membership to the hook.
:param add_default_logger: Attach the shared console logger.
:param name: Name for callbacks, logs, and saved result metadata.

Definition at line 244 of file base.py.

Member Function Documentation

◆ _attach_evaluation()

None qdpy.algorithms.base.QDAlgorithm._attach_evaluation ( self,
ind,
fitness,
features,
scores,
elapsed )
protected
Apply the native evaluator payload without admitting the candidate.

Definition at line 567 of file base.py.

◆ _check_archive_weights()

qdpy.algorithms.base.QDAlgorithm._check_archive_weights ( self)
protected
Catch conflicting objective directions before proposing or admitting candidates.

Reimplemented in qdpy.algorithms.base.AlgWrapper.

Definition at line 427 of file base.py.

◆ _fixed_batch_plan()

qdpy.algorithms.base.QDAlgorithm._fixed_batch_plan ( self,
size,
evaluate,
packed )
protected
Select the size and evaluator for the next fixed phase.

Reimplemented in qdpy.algorithms.differentiable.CMAMAEGA.

Definition at line 772 of file base.py.

◆ _internal_ask()

IndividualLike qdpy.algorithms.base.QDAlgorithm._internal_ask ( self,
IndividualLike base_ind )
protected
Internal ask method. To be implemented by subclasses.

Parameters
----------
:param base_ind: IndividualLike
    The base (empty) individual object. The `_internal_ask` method must change
    this object, by filling out the genome and providing other information.

Returns
-------
out: IndividualLike
    The suggested individual.

Reimplemented in qdpy.algorithms.base.AlgWithBatchSuggestions, qdpy.algorithms.base.AlgWrapper, qdpy.algorithms.base.FromArchive, qdpy.algorithms.base.Lambda, qdpy.algorithms.bayesian.BOPElites, qdpy.algorithms.bayesian_batch.BatchBOPElites, qdpy.algorithms.cmame.CMAMEOptimizingEmitter, qdpy.algorithms.conditional_bayesian.ConditionalBayesianQD, qdpy.algorithms.constrained.ConstrainedMAPElites, qdpy.algorithms.constrained.HiGeME, qdpy.algorithms.dde.DDEElites, qdpy.algorithms.differential.DifferentialMAPElites, qdpy.algorithms.diffusion_evolution.DiffusionEvolution, qdpy.algorithms.dynamic_mutation.DynamicMutationMAPElites, qdpy.algorithms.evolution.CMAES, qdpy.algorithms.evolution.CuriosityMutPolyBounded, qdpy.algorithms.evolution.Evolution, qdpy.algorithms.evolution.MutGaussian.CMAES, qdpy.algorithms.feasible_mome.FeasibleMOME, qdpy.algorithms.gram_elites.GramElites, qdpy.algorithms.graph_qd.GraphMAPElites, qdpy.algorithms.jedi.JEDi, qdpy.algorithms.learned_qd.LearnedQD, qdpy.algorithms.mcbo_elites.MCBOElites, qdpy.algorithms.me_gide.MEGIDE, qdpy.algorithms.mepgd.MEPGD, qdpy.algorithms.mix_me.MixME, qdpy.algorithms.mixed_bayesian.MixedBayesianQD, qdpy.algorithms.modern._CMAEmitter, qdpy.algorithms.modern.DominatedNoveltySearch, qdpy.algorithms.modern.IsoLineCrossMAPElites, qdpy.algorithms.modern.IsoLineMAPElites, qdpy.algorithms.modern.MOME, qdpy.algorithms.modern.MOURQD, qdpy.algorithms.monte_carlo.MonteCarloElites, qdpy.algorithms.multi_descriptor_nslc.MultiDescriptorNSLC, qdpy.algorithms.multi_descriptor_selection.MultiDescriptorMAPElites, qdpy.algorithms.nss.NSSMAPElites, qdpy.algorithms.occupancy_me._TrajectoryMAPElites, qdpy.algorithms.omg_mega.OMGMEGA, qdpy.algorithms.policy_manifold.PolicyManifoldSearch, qdpy.algorithms.preference.PreferenceLearningMAPElites, qdpy.algorithms.sampling.SamplingDecorator, qdpy.algorithms.search.RandomUniform, qdpy.algorithms.search.Sobol, qdpy.algorithms.sphen.SPHEN, qdpy.algorithms.voronoi_elites.VoronoiElites, qdpy.algorithms.youth.YouthMAPElites, and sequence_distribution_qd._TileBaseline.

Definition at line 515 of file base.py.

◆ _internal_best()

IndividualLike qdpy.algorithms.base.QDAlgorithm._internal_best ( self)
protected
Return the individual with the best quality. To be overridden by subclasses.
By default, returns the best individual of `self.container`.

Definition at line 686 of file base.py.

◆ _internal_tell()

None qdpy.algorithms.base.QDAlgorithm._internal_tell ( self,
IndividualLike individual,
bool added_to_container,
Mapping[str, Any] xattr = {} )
protected
Internal tell method. To be overridden by subclasses, or left empty.

Parameters
----------
:param individual: IndividualLike
    The `individual` provided to the algorithm.
:param added_to_container: bool
    True if `individual` was successfully added to the container.

Reimplemented in qdpy.algorithms.base.Lambda, qdpy.algorithms.cmame.CMAMEImprovementEmitter, qdpy.algorithms.cmame.CMAMERandomDirectionEmitter, qdpy.algorithms.evolution.CuriosityMutPolyBounded, qdpy.algorithms.evolution.Evolution, qdpy.algorithms.evolution.MutGaussian.CMAES, qdpy.algorithms.monte_carlo.MonteCarloElites, and qdpy.algorithms.surrogate.SurrogateAssistedAlg.

Definition at line 647 of file base.py.

◆ _receive_fixed_batch()

None qdpy.algorithms.base.QDAlgorithm._receive_fixed_batch ( self,
records,
verbose,
batch_start_time )
protected
Commit a generation in proposal order for an opted-in optimiser.

Reimplemented in qdpy.algorithms.differentiable.CMAMAEGA, qdpy.algorithms.modern._FixedGeneration, and qdpy.algorithms.omg_mega.OMGMEGA.

Definition at line 768 of file base.py.

◆ _start_fixed_batch()

◆ _tell_after_container_update()

None qdpy.algorithms.base.QDAlgorithm._tell_after_container_update ( self,
IndividualLike individual,
bool added,
Mapping[str, Any] xattr = {} )
protected

Account for a completed tell and send feedback.

Parameters
individualEvaluated candidate.
addedWhether admission reported a local update.
xattrMetadata captured by the pre-admission hook.

Feedback runs before the evaluation count advances. Tell callbacks run afterwards and can read the updated counters.

Definition at line 630 of file base.py.

◆ _tell_before_container_update()

Tuple[MutableMapping[str, Any], bool] qdpy.algorithms.base.QDAlgorithm._tell_before_container_update ( self,
IndividualLike individual )
protected

Read pre-admission state for optimiser feedback.

Parameters
individualCandidate with its reported evaluation attached.
Returns
A metadata mapping and a flag permitting archive admission.

Improvement emitters read the incumbent here so the signed gain is measured against the previous cell quality.

Called by the ``tell`` method before adding the individual to the container. Can be used to compile
a dictionary of information about the individual or container before the update operation occurs.
Return a dictionary of extended attributes and a boolean flag indicating whether the algorithm is allowed to tell the
individual or not.

Parameters
----------
:param individual: IndividualLike
    The `individual` provided to the algorithm.

Reimplemented in qdpy.algorithms.cmame.CMAMEImprovementEmitter, and qdpy.algorithms.gram_elites.GramElites.

Definition at line 610 of file base.py.

◆ _verify_if_finished_iteration()

bool qdpy.algorithms.base.QDAlgorithm._verify_if_finished_iteration ( self,
float batch_start_time )
protected
Emit the iteration event at an exact evaluation boundary.

Callbacks can read the just-finished iteration counters. Reset those
counters only after callbacks have run. Partial final batches leave
their counters available in the result.

Definition at line 693 of file base.py.

◆ add_callback()

None qdpy.algorithms.base.QDAlgorithm.add_callback ( self,
str event,
Callable fn )
Attach a callable `fn` to the optimiser. `fn` will be called each time the event specified in `event` occurs.

Parameters
----------
:param event: str
    The event triggering the callback. Can be either 'ask', 'tell', 'iteration' (when an iteration finishes)
    'started_optimisation', or 'finished_optimisation'.
:param fn: Callable
    The callback function called when the event specified in `event` occurs.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 934 of file base.py.

◆ ask()

IndividualLike qdpy.algorithms.base.QDAlgorithm.ask ( self)
Return the next candidate for evaluation.

Create the base individual, let the subclass propose its genome,
assign a name if empty, increment the suggestion counters, and
invoke ask callbacks. Keep the suggested object available when
sending feedback to a wrapper with multiple emitters.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Reimplemented in qdpy.algorithms.modern._FixedGeneration.

Definition at line 481 of file base.py.

◆ batch_size()

int qdpy.algorithms.base.QDAlgorithm.batch_size ( self)
Configured candidate count per iteration, or the current budget when omitted.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 466 of file base.py.

◆ best()

IndividualLike qdpy.algorithms.base.QDAlgorithm.best ( self)
Return the best retained candidate.

:raises RuntimeError: If the container has no candidates.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Reimplemented in qdpy.algorithms.base.AlgWrapper, and qdpy.algorithms.constrained.ConstrainedMAPElites.

Definition at line 675 of file base.py.

◆ current_iter()

int qdpy.algorithms.base.QDAlgorithm.current_iter ( self)
Number of full batches accounted for by the evaluation counter.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Reimplemented in qdpy.algorithms.modern._FixedGeneration.

Definition at line 476 of file base.py.

◆ nb_evaluations()

int qdpy.algorithms.base.QDAlgorithm.nb_evaluations ( self)
Number of tell calls or candidate slots consumed by the managed scheduler.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 446 of file base.py.

◆ nb_evaluations_in_iteration()

int qdpy.algorithms.base.QDAlgorithm.nb_evaluations_in_iteration ( self)
Number of accounted evaluations since the last iteration ended.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 451 of file base.py.

◆ nb_max_iter()

Union[int,float] qdpy.algorithms.base.QDAlgorithm.nb_max_iter ( self)
Ceiling of the current budget divided by the batch size for a finite run.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 471 of file base.py.

◆ nb_suggestions()

int qdpy.algorithms.base.QDAlgorithm.nb_suggestions ( self)
Number of candidates returned by ask since initialisation or reinitialisation.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 436 of file base.py.

◆ nb_suggestions_in_iteration()

int qdpy.algorithms.base.QDAlgorithm.nb_suggestions_in_iteration ( self)
Number of asks recorded since the last managed iteration ended.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 441 of file base.py.

◆ nb_updated()

int qdpy.algorithms.base.QDAlgorithm.nb_updated ( self)
Number of evaluations for which the archive reported a local update.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 456 of file base.py.

◆ nb_updated_in_iteration()

int qdpy.algorithms.base.QDAlgorithm.nb_updated_in_iteration ( self)
Number of reported archive updates since the last iteration ended.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 461 of file base.py.

◆ optimisation_task() [1/2]

Union[str, Sequence[float]] qdpy.algorithms.base.QDAlgorithm.optimisation_task ( self)
The objective direction or explicit comparison weights.

Definition at line 384 of file base.py.

◆ optimisation_task() [2/2]

None qdpy.algorithms.base.QDAlgorithm.optimisation_task ( self,
Union[str, Sequence[float]] optimisation_task )
Update the kind of optimisation task performed by this `QDAlgorithm`.

Parameters
----------
:param optimisation_task: Union[str, Sequence[float]]
    The kind of optimisation task to perform for all objectives of the fitness functions.
    If `optimisation_task` is a string, it can take the following values:
        - for minimising all fitness objectives: 'minimisation', 'minimization', 'minimise', 'minimize', 'min'
        - for maximising all fitness objectives: 'maximisation', 'maximization', 'maximise', 'maximize', 'max'
    If `optimisation_task` is a Sequence of floats, its length corresponds to the number of objectives, and each
    entry is a weight to apply to each objective score.
    Maximised objectives have a corresponding weight > 0 while minimised objectives have weights < 0.
    The length of this Sequence must be same as the length of the `self.container.fitness_domain` attribute.

Definition at line 390 of file base.py.

◆ optimise()

IndividualLike qdpy.algorithms.base.QDAlgorithm.optimise ( self,
Callable evaluate,
Optional[int] budget = None,
bool batch_mode = True,
Optional[ExecutorLike] executor = None,
bool send_several_suggestions_to_fn = False,
int max_nb_suggestions_per_call = 10,
bool verbose = False )
Manage evaluation and return the best candidate in the archive.

A single-candidate evaluator can return a fitness and descriptor
pair, that pair followed by named scores, or an evaluated individual.
Return an empty sequence after updating the supplied object in place
during in-process execution. A packed evaluator receives a list and
returns one such result per candidate in the same order.

Both the budget and batch size count candidates. A failed evaluation or
malformed group consumes its dispatched slots. Results are consumed in
completion order, which can affect archive-dependent searches.
Iteration callbacks run after full batches.

:param evaluate: Callable executed for each candidate or packed group.
:param budget: Optional override of the configured budget.
:param batch_mode: Wait for the current batch before asking for the
    next one. In steady state, refill available slots as work completes.
:param executor: Evaluation executor. Defaults to in-process sequential
    execution. The caller manages any supplied executor's lifetime.
:param send_several_suggestions_to_fn: Pass a list per evaluator call.
:param max_nb_suggestions_per_call: Positive cap on a packed call.
:param verbose: Emit archive validation warnings.
:returns: The best retained candidate after the run.
:raises RuntimeError: If no candidate is available to return.
:raises ValueError: If the budget is missing or a positive run has an
    invalid batch size or packed-call limit.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Reimplemented in qdpy.algorithms.boil.BOIL, qdpy.algorithms.modern._FixedGeneration, qdpy.algorithms.occupancy_me._TrajectoryMAPElites, and qdpy.algorithms.sampling.SamplingDecorator.

Definition at line 776 of file base.py.

◆ reinit()

None qdpy.algorithms.base.QDAlgorithm.reinit ( self)
Reset counters for suggestions, evaluation, and archive updates.

This base method leaves the archive and callbacks in place.
Subclasses may also reset their generator or optimiser state.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Reimplemented in ordered_qd._TimedBOP, qdpy.algorithms.base.AlgWrapper, qdpy.algorithms.base.FromArchive, qdpy.algorithms.bayesian.BOPElites, qdpy.algorithms.bayesian_batch.BatchBOPElites, qdpy.algorithms.bayesian_deep_qd.BayesianDeepQD, qdpy.algorithms.boil.BOIL, qdpy.algorithms.cmame.CMAMEOptimizingEmitter, qdpy.algorithms.cmame.MEMAPElitesUCB1, qdpy.algorithms.conditional_bayesian.ConditionalBayesianQD, qdpy.algorithms.constrained.ConstrainedMAPElites, qdpy.algorithms.constrained.HiGeME, qdpy.algorithms.dde.DDEElites, qdpy.algorithms.differentiable.CMAMAEGA, qdpy.algorithms.differentiable.CMAMEGA, qdpy.algorithms.differential.DifferentialMAPElites, qdpy.algorithms.diffusion_evolution.DiffusionEvolution, qdpy.algorithms.discount.DiscountModelSearch, qdpy.algorithms.dynamic_mutation.DynamicMutationMAPElites, qdpy.algorithms.evolution.CuriosityMutPolyBounded, qdpy.algorithms.evolution.MutGaussian.CMAES, qdpy.algorithms.feasible_mome.FeasibleMOME, qdpy.algorithms.gram_elites.GramElites, qdpy.algorithms.graph_qd.GraphMAPElites, qdpy.algorithms.jedi.JEDi, qdpy.algorithms.learned_qd.LearnedQD, qdpy.algorithms.mcbo_elites.MCBOElites, qdpy.algorithms.me_gide.MEGIDE, qdpy.algorithms.mepgd.MEPGD, qdpy.algorithms.mix_me.MixME, qdpy.algorithms.mixed_bayesian.MixedBayesianQD, qdpy.algorithms.mo_cma_mae.MOCMAMAE, qdpy.algorithms.modern._FixedGeneration, qdpy.algorithms.modern.CMAMAE, qdpy.algorithms.monte_carlo.MonteCarloElites, qdpy.algorithms.multi_descriptor_nslc.MultiDescriptorNSLC, qdpy.algorithms.multi_descriptor_selection.MultiDescriptorMAPElites, qdpy.algorithms.occupancy_me._TrajectoryMAPElites, qdpy.algorithms.omg_mega.OMGMEGA, qdpy.algorithms.policy_manifold.PolicyManifoldSearch, qdpy.algorithms.preference.PreferenceLearningMAPElites, qdpy.algorithms.sampling.SamplingDecorator, qdpy.algorithms.sphen.SPHEN, qdpy.algorithms.voronoi_elites.VoronoiElites, qdpy.algorithms.windowed_map_elites.WindowedMAPElites, qdpy.algorithms.youth.YouthMAPElites, and verified_symmetry_manifold._TimedDDE.

Definition at line 348 of file base.py.

◆ tell()

bool qdpy.algorithms.base.QDAlgorithm.tell ( self,
IndividualLike individual,
Optional[Any] fitness = None,
Optional[FeaturesLike] features = None,
Optional[ScoresDictLike] scores = None,
Optional[float] elapsed = None,
bool verbose = False,
tell_container = True )
Report an evaluated candidate and offer it to the container.

A call updates the candidate's supplied evaluation attributes. The
container applies comparison weights to raw objective values. The
algorithm's pre-admission hook may add feedback metadata or decline
insertion. Feedback and evaluation counters still run when archive
insertion is disabled.

:param individual: Candidate associated with this evaluation.
:param fitness: Objective values or a fitness object. If omitted,
    use the candidate's existing or named fitness.
:param features: Descriptor values or a descriptor object.
:param scores: Named scores to store on the candidate first.
:param elapsed: Evaluation duration in seconds.
:param verbose: Report archive validation warnings.
:param tell_container: Permit an archive update.
:returns: Whether the container reported a local update.
:raises ValueError: If the objective count differs from the configured count.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Reimplemented in qdpy.algorithms.base.AlgWrapper, qdpy.algorithms.bayesian.BOPElites, and qdpy.algorithms.sampling.SamplingDecorator.

Definition at line 532 of file base.py.

◆ tell_container_entries()

None qdpy.algorithms.base.QDAlgorithm.tell_container_entries ( self,
Optional[Container] cont = None )
Send stored entries to the optimiser's internal feedback hook.

:param cont: Source of the warm-start entries. Defaults to the
    optimiser's own archive.

Entries are marked as accepted for the hook. Archive admission,
evaluation counters, and tell callbacks are bypassed.

Reimplemented from qdpy.algorithms.base.QDAlgorithmLike.

Definition at line 660 of file base.py.


The documentation for this class was generated from the following file: