Optimizer#

Gradient-based optimization through scipy.optimize. Suited to a single, smooth objective started from a reasonable initial guess — root finding against a target value, or local minimization. It evaluates one candidate per step, so there is no parallelism to configure; the cost is one nextnano simulation per function evaluation.

The scipy method is chosen with optimization_method at construction and its arguments are supplied through Optimizer.set_optimization_parameters(), which forwards them to the underlying scipy call. When the objective should hit a particular value rather than be driven to zero, set it with Optimizer.set_target().

Optimizer(nextnanoio, metric[, ...])

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

Optimizer.set_optimization_parameters(*args)

Updates the optimization parameters method_args and method_kwargs

Optimizer.set_target(target)

Sets the target, only for root finders optimization methods

Optimizer.run()

Runs optimization

Optimizer.validate_optimization()

Validates the optimization parameters.

Usage#

Root finding against a target transition energy:

from nextnano_optimizers.optimizer import Optimizer

optimizer = Optimizer(io, metric, optimization_method="root")
optimizer.set_optimization_parameters(x0=[10.0])
optimizer.set_target(0.25)
optimizer.run()

set_optimization_parameters passes keyword arguments straight through to the chosen scipy routine, so method-specific options are set the same way:

optimizer.set_optimization_parameters(x0=[10.0], tol=1e-6, rewrite=True)

rewrite=True replaces the stored parameters instead of merging into them.

Worked examples: Optimizing well width for specific target transition energy in an infinite quantum well and Optimization of a 2DEG structure.

Reference#

class nextnano_optimizers.optimizer.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 optimizations.

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: Callable | None = None) Callable#

Loads the optimization method function from scipy.optimize

run()#

Runs optimization

run_optimization()#

Runs optimizations.

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:
ValueError

If the optimization parameters are not valid.