nextnanoevo.OptimizerClass module

class nextnanoevo.OptimizerClass.Evolution(nextnanoio: IO, metric: Metric, bounds, algorithm='default', size=20)

Bases: object

The evolution class to run the evolutionary optimization with pygmo algorithms.

Parameters:
nextnanoioIO

input-output object defining input file variables and output datafiles

metricMetric

defines how to retrieve numerical (scalar or vector) metric to optimize from output files

boundstuple of list

A tuple containing two lists, the lower and upper bounds for the input variables. Each list should have the same length as the number of input variables.

algorithmstr, optional

The name of the algorithm to be used for the evolution. If “default”, the default algorithm is used. Default is different for single objective and multi-objective problems.

sizeint, optional

The size of the population for the evolution. Default is 20.

Attributes:
_optimization_managerEvolutionManager

The optimization manager for the evolution.

problemNextnanoProblem

The problem definition for the evolution.

_population_sizeint

The size of the population for the evolution.

algorithmstr

The name of the algorithm to be used for the evolution.

populationpygmo.population

The population for the evolution.

pareto_solutionslist

The list of Pareto solutions found during the evolution.

pareto_fitslist

The list of fitness values for the Pareto solutions.

pareto_indexeslist

The list of indexes for the Pareto solutions.

champion_xnumpy.ndarray

The champion solution found during the evolution.

champion_fnumpy.ndarray

The fitness value of the champion solution.

champion_indextuple

The index of the champion solution in the population.

norm_functionCallable

The function used to calculate the criteria for a champion solution.

Methods

add_initial_guess(initial_guess)

Adds the initial guess solutions to the population.

add_json_summary(gen, seed, algorithm_kwargs)

Adds a summary of the evolution to the JSON logger.

create_dat_file(filename[, output_dir])

Creates a .dat output file from the JSON logger data.

create_population(seed[, initial_guess])

Creates the initial population for the evolution.

import_from_json()

Loads the JSON logger data.

load_algorithm(algorithm)

Loads the algorithm for the evolution.

load_default_algorithm()

Loads the default algorithm based on the problem type.

run([gen, keep_pareto_front, interval, ...])

Runs the evolution with the specified parameters.

set_size(size)

Sets the population size for the evolution.

update_champion(solutions, fits, gen)

Updates the champion solution and fit if a better one is found.

update_pareto_front(solutions, fits, gen)

Updates the Pareto front with new solutions and fits.

validate_initial_guess(initial_guess)

Validates the initial guess provided by the user.

add_initial_guess(initial_guess) None

Adds the initial guess solutions to the population.

add_json_summary(gen, seed, algorithm_kwargs)

Adds a summary of the evolution to the JSON logger.

create_dat_file(filename, output_dir=None)

Creates a .dat output file from the JSON logger data.

create_population(seed, initial_guess=None)

Creates the initial population for the evolution.

import_from_json()

Loads the JSON logger data.

load_algorithm(algorithm: str) None

Loads the algorithm for the evolution. Only accepts the algorithms defined in defaults. If “default” is passed, the default algorithm is loaded based on the problem type (single or multi-objective).

load_default_algorithm() None

Loads the default algorithm based on the problem type.

run(gen: int = 20, keep_pareto_front: bool = False, interval: int = 1, seed: int | None = None, initial_guess: list[tuple[Number]] | None = None, algorithm_kwargs: dict | None = None, non_execution_penalty: Number | None = None, keep_output: str = 'all') population

Runs the evolution with the specified parameters.

Parameters:
genint, optional

The number of generations to run the evolution. Default is 20.

keep_pareto_frontbool, optional

If True, the Pareto front is kept and updated during the evolution. Default is False.

intervalint, optional

The interval at which the Pareto front is updated. Default is 1.

seedint, optional

The seed for the random generation of the initial population. If not provided, a random seed is used.

initial_guesslist of tuples or numpy arrays, optional

A list of initial guesses for the population. Each initial guess will be added to the initial population.

algorithm_kwargsdict, optional

A dictionary of keyword arguments to be passed to the algorithm.

non_execution_penaltynumbers.Number, optional

A penalty to be applied for simulations which are failed to execute.

keep_outputstr, optional

Specifies which output to keep after the evolution is finished. Options are “all”, “pareto”, or “champion”. Default is “all”.

Returns:
pygmo.population

The final population after the evolution is finished.

Raises:
ValueError

If keep_output is not one of “all”, “pareto”, or “champion”.

set_size(size: int) None

Sets the population size for the evolution.

update_champion(solutions, fits, gen) None

Updates the champion solution and fit if a better one is found. Champion is the solution with the lowest norm of the fit.

update_pareto_front(solutions, fits, gen) None

Updates the Pareto front with new solutions and fits.

validate_initial_guess(initial_guess) int

Validates the initial guess provided by the user.

Returns:
int

The number of valid initial guess solutions. Returns 0 if no initial guess is provided or if the initial guess is None.

Raises:
AssertionError

If the initial guess is not iterable, contains non numbers, or if the solutions do not match the bounds. If the length of the initial guess is not between 1 and population size.

class nextnanoevo.OptimizerClass.NextnanoProblem(opt_manager)

Bases: object

The problem class for the nextnano evolutions.

Methods

fitness

get_bounds

get_nobj

fitness(input_variables)
get_bounds()
get_nobj()
class nextnanoevo.OptimizerClass.Optimizer(nextnanoio: IO, metric: Metric, optimization_method='root', method_function=None)

Bases: object

The optimization class to run the gradient decent optimization with methods from scipy.optimize

Parameters:
nextnanoioIO

input-output object defining input file variables and output datafiles

metricMetric

defines how to retrieve numerical (scalar or vector) metric to optimize from output files

optimization_methodstr

optimization method used from scipy.optimize

Methods

load_method([method_function])

Loads the optimization method function from scipy.optimize

run()

Runs optimization

run_optimization()

Runs optimizationans.

set_optimization_parameters(*args[, rewrite])

Updates the optimization parameters method_args and method_kwargs

set_target(target)

Sets the target, only for root finders optimization methods

validate_optimization()

Validates the optimization parameters.

load_method(method_function=None) Callable

Loads the optimization method function from scipy.optimize

run()

Runs optimization

run_optimization()

Runs optimizationans.

Returns:
resultscipy.optimize.OptimizeResult
set_optimization_parameters(*args, rewrite=False, **kwargs) None

Updates the optimization parameters method_args and method_kwargs

Parameters:
argslist

The list of arguments to be passed to the optimization function

rewritebool

If True, the method_args and method_kwargs are rewritten with the new values

kwargsdict

The dictionary of keyword arguments to be passed to the optimization function

set_target(target) None

Sets the target, only for root finders optimization methods

validate_optimization() bool

Validates the optimization parameters. This function should do general checks, as well as function specific checks for known scipy functions.

Raises:
AssertionError

If the optimization parameters are not valid.