modopt.Optimizer
- class modopt.Optimizer(problem, recording=False, out_dir=None, hot_start_from=None, hot_start_atol=0.0, hot_start_rtol=0.0, visualize=[], keep_viz_open=False, turn_off_outputs=False, **kwargs)[source]
Base class for all optimization algorithms in modOpt. This class provides the common functionalities for all the optimization algorithms, such as checking the correctness of first derivatives, recording the outputs, hot-starting the optimization, and visualizing the scalar variables. The user-defined optimization algorithms should inherit from this class.
- Attributes
- problemProblem or ProblemLite
The problem to be solved. Needs to be a Problem() or ProblemLite() object.
- problem_namestr
The name of the problem.
- solver_namestr
The name of the solver.
- optionsOptionsDictionary
The options dictionary for the optimizer.
- recordh5py.File
The record file to store the outputs from all iterations of the optimization.
- hot_start_recordh5py.File
The record file from which to hot-start the optimization. modOpt loads and reuses the outputs stored in this file from a previous optimization.
- out_dirstr
The directory to store all the output files generated from the optimization.
- modopt_output_fileslist
The list of all files generated by modOpt during the optimization.
- visualizerVisualizer
The visualizer object to plot the scalar variables during the optimization.
- timestampstr
The timestamp for the optimization.
- scalar_outputslist
The list of scalar outputs provided by the optimizer after each iteration.
- available_outputsdict
The dictionary of all available outputs from the optimizer after each iteration.
- resultsdict
The dictionary containing the results of the optimization.
- update_outputs_countint
Number of times the
update_outputs()method is called. Only relevant for development and debugging purposes.
Methods
check_first_derivatives([x, step, formulation])Check the first derivatives of the optimization problem using finite differences.
Set solver name and any solver-specific options.
print_results([summary_table, all])Print the results of the optimization problem to the terminal.
setup()Set up any solver-specific attributes or modules (e.g., merit function or Hessian approximation) required by the optimization algorithm, during optimizer instantiation.
solve()Run the optimization algorithm to solve the problem.
- __init__(problem, recording=False, out_dir=None, hot_start_from=None, hot_start_atol=0.0, hot_start_rtol=0.0, visualize=[], keep_viz_open=False, turn_off_outputs=False, **kwargs)[source]
Initialize the Optimizer object. Sets up recording, hot-starting, and visualization.
- Parameters
- problemProblem or ProblemLite
The problem to be solved. Required argument for all optimizers.
- recordingbool, default=False
If
True, record all outputs from the optimization. This needs to be enabled for hot-starting the same problem later, if the optimization is interrupted.- out_dirstr, optional
The directory to store all the output files generated from the optimization.
- hot_start_fromstr, optional
The record file from which to hot-start the optimization.
- hot_start_atolfloat, default=0.
The absolute tolerance check for the inputs when reusing outputs from the hot-start record.
- hot_start_rtolfloat, default=0.
The relative tolerance check for the inputs when reusing outputs from the hot-start record.
- visualizelist, default=[]
The list of scalar variables to be visualized during the optimization.
- keep_viz_openbool, default=False
If
True, keep the visualization window open after the optimization is complete.- turn_off_outputsbool, default=False
If
True, prevent modOpt from generating any output files.- **kwargs
Additional optimizer-specific keyword arguments.
- check_first_derivatives(x=None, step=1e-06, formulation='rs')[source]
Check the first derivatives of the optimization problem using finite differences.
- Parameters
- xnp.ndarray, optional
The design variables at which the derivatives are to be checked. If not provided, the initial design variables are used.
- stepfloat, default=1e-6
The step size for the finite differences.
- print_results(summary_table=False, all=False)[source]
Print the results of the optimization problem to the terminal.
- Parameters
- summary_tablebool, default=False
If
True, print the summary table for the optimization.- allbool, default=False
If
False, print only the scalar outputs of the optimization problem. Otherwise, print all the outputs of the optimization problem.