nsga module

Define the NSGA-III many-objective optimisation algorithm.

class _LightWinProblem(n_var, n_obj, n_constr, xl, xu, eval_fn, **kwargs)[source]

Bases: Problem

Wrap LightWin’s residual evaluation into a pymoo Problem.

Parameters:
__init__(n_var, n_obj, n_constr, xl, xu, eval_fn, **kwargs)[source]

Init the object.

Parameters:
Return type:

None

_evaluate(x, out, *args, **kwargs)[source]

Evaluate objectives (and constraints) for a batch of individuals.

Parameters:
Return type:

None

class NSGA3Algorithm(*, compensating_elements, objective_factory, design_space, compute_beam_propagation, cavity_settings_factory, reference_simulation_output, optimisation_algorithm_kwargs=None, history_kwargs=None, **kwargs)[source]

Bases: OptimisationAlgorithm

NSGA-III many-objective optimisation algorithm, powered by pymoo.

Suitable for problems with 4+ objectives. Uses structured reference points on a Das-Dennis simplex lattice to maintain diversity across the Pareto front.

All attributes but solution are inherited from OptimisationAlgorithm.

See also

pymoo.algorithms.moo.nsga3.NSGA3

Parameters:
supports_constraints: bool = True
optimize()[source]

Set up the optimisation and solve the problem.

Return type:

OptiSol

Returns:

Gives list of solutions, corresponding objectives, constraint violations if applicable, etc.

property _default_kwargs: dict[str, Any]

Compute sensible NSGA-III defaults from the problem dimensions.

n_partitions is the smallest value that yields at least _MIN_REF_DIRS Das-Dennis reference directions, ensuring enough diversity pressure across the Pareto front.

pop_size is set to the number of reference directions (the natural lower bound for NSGA-III) rounded up to the nearest hundred.

n_gen scales with the number of variables: more variables generally need more generations to converge.

_evaluate_individual(var)[source]

Evaluate objectives and constraints for a single individual.

Mirrors the logic of OptimisationAlgorithm._wrapper_residuals() but also returns constraint values so that a single beam propagation call covers both, avoiding redundant simulations.

Parameters:

var (ndarray[tuple[Any, ...], dtype[double]]) – Array of variable values for one candidate solution.

Return type:

tuple[ndarray[tuple[Any, ...], dtype[double]], ndarray[tuple[Any, ...], dtype[double]] | None]

Returns:

  • residuals – Objective values.

  • constraints – Constraint values (<= 0 means feasible), or None if no constraints are defined.

_generate_opti_sol(result)[source]

Pick the best solution from the Pareto front and format it.

“Best” is defined as the Pareto-front member with the smallest Euclidean norm of its objective vector - a reasonable neutral choice when no preference ordering over objectives is specified.

Parameters:

result (Result) – The pymoo Result object returned by minimize().

Return type:

OptiSol

_problem()[source]

Create a single-threaded problem.

Return type:

_LightWinProblem

_format_variables()[source]

Extract lower and upper bounds from Variable objects.

Return type:

tuple[ndarray[tuple[Any, ...], dtype[double]], ndarray[tuple[Any, ...], dtype[double]]]

_abc_impl = <_abc._abc_data object at 0x7318f8d5eac0>
class _LightWinProblemMulti(*args, n_workers=1, **kwargs)[source]

Bases: _LightWinProblem

Wrap LightWin’s residual evaluation into a pymoo Problem.

__init__(*args, n_workers=1, **kwargs)[source]

Set a number of CPU cores.

Return type:

None

_evaluate(x, out, *args, **kwargs)[source]

Evaluate a batch of individuals, optionally in parallel.

Parameters:
Return type:

None

class NSGA3AlgorithmMulti(*args, **kwargs)[source]

Bases: NSGA3Algorithm

NSGA-III many-objective optimisation algorithm, powered by pymoo.

Suitable for problems with 4+ objectives. Uses structured reference points on a Das-Dennis simplex lattice to maintain diversity across the Pareto front.

All attributes but solution are inherited from OptimisationAlgorithm.

See also

pymoo.algorithms.moo.nsga3.NSGA3

__init__(*args, **kwargs)[source]

Create object.

Also set _history_lock, which guards history writes, as they are not thread-safe.

Return type:

None

property _default_kwargs: dict[str, Any]

Compute sensible NSGA-III defaults from the problem dimensions.

n_partitions is the smallest value that yields at least _MIN_REF_DIRS Das-Dennis reference directions, ensuring enough diversity pressure across the Pareto front.

pop_size is set to the number of reference directions (the natural lower bound for NSGA-III) rounded up to the nearest hundred.

n_gen scales with the number of variables: more variables generally need more generations to converge.

_evaluate_individual(var)[source]

Evaluate one candidate — thread-safe via lock on history writes.

The simulation runs outside the lock (fully parallel). History writes are batched and serialised via _history_lock.

Parameters:

var (ndarray[tuple[Any, ...], dtype[double]])

Return type:

tuple[ndarray[tuple[Any, ...], dtype[double]], ndarray[tuple[Any, ...], dtype[double]] | None]

_problem()[source]

Create a multi-threaded problem.

Return type:

_LightWinProblemMulti

_abc_impl = <_abc._abc_data object at 0x7318f8d5efc0>