saealib.Optimizer#

class saealib.Optimizer(problem, seed=None)[ソース]#

ベースクラス: object

Optimizer class for evolutionary algorithms.

Integrates problem definition, evolutionary algorithm, surrogate model, model manager, and termination condition, and manages the optimization process.

パラメータ:
  • problem (Problem)

  • seed (int | None)

problem#

The optimization problem.

Type:

Problem

algorithm#

The evolutionary algorithm.

Type:

Algorithm

surrogate#

The surrogate model.

Type:

Surrogate

strategy#

The optimization strategy.

Type:

OptimizationStrategy

termination#

The termination condition.

Type:

Termination

archive#

The archive of evaluated solutions.

Type:

Archive

popsize#

The population size.

Type:

int

seed#

The master random seed. None means non-deterministic.

Type:

int or None

fe#

The current number of function evaluations.

Type:

int

gen#

The current generation number.

Type:

int

cbmanager#

The callback event manager.

Type:

CallbackManager

instance_name#

The name of the optimizer instance.

Type:

str

Methods

__init__

Initialize the Optimizer.

contract_diagnostics

Return diagnostics for the currently configured component graph.

describe

Describe the most recently compiled plan, if one exists.

dispatch

Dispatch an event to the callback manager.

from_problem_file

Build an Optimizer from a Python file defining a problem.

iterate

Iterate the optimization process.

iterate_from

Resume iteration from an existing context (e.g. loaded from checkpoint).

load_pickle

Load an optimizer and context from a pickle checkpoint.

resolve_defaults

Fill unset components with library defaults (Registry + presets file).

run

Run the optimization process.

run_from

Resume and run to completion from an existing context.

save_pickle

Save the optimizer and context together as a pickle checkpoint.

save_preset

Save the currently configured components as a reusable preset file.

set_acquisition

Set the independent acquisition component.

set_algorithm

Set the evolutionary algorithm.

set_async_evaluation_scheduler

Configure asynchronous evaluation for built-in strategies.

set_evaluation_planner

Set the evaluation planner.

set_evaluator

Set the evaluator.

set_feedback_builder

Set the feedback builder.

set_history

Set execution history channels and return self.

set_initializer

Set the initializer.

set_instance_name

Set the instance name.

set_preset

Set a user-defined preset.

set_seed

Set the master random seed.

set_strategy

Set the optimization strategy.

set_surrogate

Wrap a raw Surrogate in a LocalSurrogateManager.

set_surrogate_manager

Set the surrogate manager.

set_termination

Set the termination condition.

validate

Check configuration consistency.

Method Details

Optimizer.__init__(problem, seed=None)[ソース]#

Initialize the Optimizer.

パラメータ:
  • problem (Problem) -- The optimization problem.

  • seed (int or None, optional) -- Master random seed propagated to the initializer. None (default) means non-deterministic.

Optimizer.contract_diagnostics()[ソース]#

Return diagnostics for the currently configured component graph.

戻り値の型:

DiagnosticBag

Optimizer.describe()[ソース]#

Describe the most recently compiled plan, if one exists.

戻り値の型:

str

Optimizer.dispatch(event)[ソース]#

Dispatch an event to the callback manager.

パラメータ:

event (Event)

戻り値の型:

None

classmethod Optimizer.from_problem_file(problem_path, preset=None)[ソース]#

Build an Optimizer from a Python file defining a problem.

The file at problem_path is executed as a standalone module (it is not registered in sys.modules) and must define a top-level problem variable holding a Problem instance. If preset is given, it is applied first via set_preset(); any of the top-level variables algorithm, strategy, surrogate_manager, termination defined in the file are then applied via the corresponding set_*() method, so the file can override individual components of the preset. A top-level seed variable, if present, is passed to the Optimizer constructor.

パラメータ:
  • problem_path (str or Path) -- Path to a .py file defining a top-level problem variable.

  • preset (str, Path, dict, or None, optional) -- Preset applied before the file's own component definitions, so that the file can override individual components. See set_preset().

戻り値:

A configured, not-yet-run Optimizer instance. Call run() or iterate() on it.

戻り値の型:

Optimizer

例外:
  • ValidationError -- If the file does not define a top-level problem variable, or it is not a Problem instance. Also raised if a top-level algorithm, strategy, surrogate_manager, termination, or seed variable is defined but is not an instance of its expected type.

  • FileNotFoundError -- If problem_path does not exist.

サンプル

>>> # problem.py:
>>> #     problem = Problem(func=..., dim=2, n_obj=1, direction=[-1])
>>> #     seed = 42
>>> opt = Optimizer.from_problem_file("problem.py", preset="preset.yaml")
>>> ctx = opt.run()
Optimizer.iterate(checkpoint_path=None, checkpoint_interval=1, checkpoint_format='npz', checkpoint_delete_on_success=False)[ソース]#

Iterate the optimization process.

パラメータ:
  • checkpoint_path (str, Path, or None, optional) -- If provided, checkpoints are saved to this directory every checkpoint_interval generations.

  • checkpoint_interval (int, optional) -- Generations between checkpoints. Default: 1.

  • checkpoint_format ({'npz', 'pickle', 'both'}, optional) -- Checkpoint format. Default: 'npz'.

  • checkpoint_delete_on_success (bool, optional) -- Delete checkpoints on normal termination. Default: False.

戻り値:

Generator of OptimizationState.

戻り値の型:

Generator[OptimizationState]

Optimizer.iterate_from(ctx, checkpoint_path=None, checkpoint_interval=1, checkpoint_format='npz', checkpoint_delete_on_success=False)[ソース]#

Resume iteration from an existing context (e.g. loaded from checkpoint).

Does not call the initializer; all other components must be configured.

パラメータ:
  • ctx (OptimizationState) -- Context to resume from.

  • checkpoint_path (str, Path, or None, optional) -- If provided, checkpoints are saved to this directory every checkpoint_interval generations.

  • checkpoint_interval (int, optional) -- Generations between checkpoints. Default: 1.

  • checkpoint_format ({'npz', 'pickle', 'both'}, optional) -- Checkpoint format. Default: 'npz'.

  • checkpoint_delete_on_success (bool, optional) -- Delete checkpoints on normal termination. Default: False.

戻り値の型:

Generator[OptimizationState, None, None]

classmethod Optimizer.load_pickle(path)[ソース]#

Load an optimizer and context from a pickle checkpoint.

The returned context has resumed=True. Call run_from() or iterate_from() on the returned optimizer to continue the optimization.

警告

Pickle files are tied to specific Python and library versions.

パラメータ:

path (str or Path) -- Path to the .pkl file. The extension is added if absent.

戻り値の型:

tuple[Optimizer, OptimizationState]

Optimizer.resolve_defaults()[ソース]#

Fill unset components with library defaults (Registry + presets file).

Components already set via set_*() are never overwritten. Gaps are filled first from a user preset (set_preset()), if any, then from a bundled preset selected by (1) the algorithm's registered name if algorithm is set, else (2) a Problem-shape rule, else (3) the universal fallback preset. initializer is computed from semantic defaults and is not part of any preset; termination falls back to the resolved maximum-evaluations default (200 * problem.dim unless a provider recommends another value) only if neither set_*() nor a preset supplies one.

戻り値の型:

None

Optimizer.run(checkpoint_path=None, checkpoint_interval=1, checkpoint_format='npz', checkpoint_delete_on_success=False)[ソース]#

Run the optimization process.

パラメータ:
  • checkpoint_path (str, Path, or None, optional) -- If provided, checkpoints are saved to this directory every checkpoint_interval generations.

  • checkpoint_interval (int, optional) -- Generations between checkpoints. Default: 1.

  • checkpoint_format ({'npz', 'pickle', 'both'}, optional) -- Checkpoint format. Default: 'npz'.

  • checkpoint_delete_on_success (bool, optional) -- Delete checkpoints on normal termination. Default: False.

戻り値:

The optimization context.

戻り値の型:

OptimizationState

Optimizer.run_from(ctx, checkpoint_path=None, checkpoint_interval=1, checkpoint_format='npz', checkpoint_delete_on_success=False)[ソース]#

Resume and run to completion from an existing context.

パラメータ:
  • ctx (OptimizationState) -- Context to resume from.

  • checkpoint_path (str, Path, or None, optional) -- If provided, checkpoints are saved to this directory every checkpoint_interval generations.

  • checkpoint_interval (int, optional) -- Generations between checkpoints. Default: 1.

  • checkpoint_format ({'npz', 'pickle', 'both'}, optional) -- Checkpoint format. Default: 'npz'.

  • checkpoint_delete_on_success (bool, optional) -- Delete checkpoints on normal termination. Default: False.

戻り値:

The final optimization context.

戻り値の型:

OptimizationState

Optimizer.save_pickle(ctx, path)[ソース]#

Save the optimizer and context together as a pickle checkpoint.

This preserves fitted surrogate state and all component objects, offering complete reproducibility within the same environment.

警告

Pickle files are tied to specific Python and library versions. Use OptimizationState.save() for a more portable format.

パラメータ:
  • ctx (OptimizationState) -- Current optimization context.

  • path (str or Path) -- Destination file path. The .pkl extension is added if absent.

戻り値の型:

None

Optimizer.save_preset(path)[ソース]#

Save the currently configured components as a reusable preset file.

Serializes algorithm, surrogate_manager, strategy, and termination (whichever are set via set_*()) into a preset dict and writes it as YAML. Problem-owned parameters (dim, direction) are stripped so the preset can be reused across problems of different dimensionality.

パラメータ:

path (str or Path) -- Destination file path. The .yaml extension is added if absent.

戻り値:

The path the preset was written to.

戻り値の型:

Path

例外:

ValidationError -- If no components are configured, or a configured component cannot be serialized (e.g. holds a raw lambda).

Optimizer.set_acquisition(acquisition)[ソース]#

Set the independent acquisition component.

戻り値の型:

Self

Optimizer.set_algorithm(algorithm)[ソース]#

Set the evolutionary algorithm. Returns self.

パラメータ:

algorithm (Algorithm)

戻り値の型:

Self

Optimizer.set_async_evaluation_scheduler(scheduler)[ソース]#

Configure asynchronous evaluation for built-in strategies.

パラメータ:

scheduler (AsyncEvaluationScheduler | None)

戻り値の型:

Self

Optimizer.set_evaluation_planner(planner)[ソース]#

Set the evaluation planner.

パラメータ:

planner (EvaluationPlanner)

戻り値の型:

Self

Optimizer.set_evaluator(evaluator)[ソース]#

Set the evaluator. Returns self.

パラメータ:

evaluator (Evaluator)

戻り値の型:

Self

Optimizer.set_feedback_builder(builder)[ソース]#

Set the feedback builder.

パラメータ:

builder (FeedbackBuilder)

戻り値の型:

Self

Optimizer.set_history(channels)[ソース]#

Set execution history channels and return self.

On resume, the checkpoint's channels take precedence unless this method was called; calling it with a different set fails validation. Assigning to history_channels directly does not count as calling it.

パラメータ:

channels (Sequence[str])

戻り値の型:

Self

Optimizer.set_initializer(initializer)[ソース]#

Set the initializer. Returns self.

パラメータ:

initializer (Initializer)

戻り値の型:

Self

Optimizer.set_instance_name(name)[ソース]#

Set the instance name. Returns self.

パラメータ:

name (str)

戻り値の型:

Self

Optimizer.set_preset(preset)[ソース]#

Set a user-defined preset. Returns self.

The preset fills components that are not already configured via set_*(); explicitly set components take precedence.

パラメータ:

preset (str | Path | dict)

戻り値の型:

Self

Optimizer.set_seed(seed)[ソース]#

Set the master random seed. Returns self.

パラメータ:

seed (int | None)

戻り値の型:

Self

Optimizer.set_strategy(strategy)[ソース]#

Set the optimization strategy. Returns self.

パラメータ:

strategy (OptimizationStrategy)

戻り値の型:

Self

Optimizer.set_surrogate(surrogate, n_neighbors=50)[ソース]#

Wrap a raw Surrogate in a LocalSurrogateManager. Returns self.

Equivalent to set_surrogate_manager(LocalSurrogateManager(surrogate, ...)).

パラメータ:
戻り値の型:

Self

Optimizer.set_surrogate_manager(manager)[ソース]#

Set the surrogate manager. Returns self.

パラメータ:

manager (SurrogateManager)

戻り値の型:

Self

Optimizer.set_termination(termination)[ソース]#

Set the termination condition. Returns self.

パラメータ:

termination (Termination)

戻り値の型:

Self

Optimizer.validate(*, require_initializer=True)[ソース]#

Check configuration consistency. Returns list of issues.

Call resolve_defaults() first when validation results should reflect the components that will be used for execution.

パラメータ:

require_initializer (bool, optional) -- When False, skip the initializer presence check. Use this when resuming from a checkpoint where initialization is not needed.

戻り値の型:

list[str]