HyperStudy Tips and Tricks: #29 - Using ‘External Optimizer’ in HyperStudy
Using ‘External Optimizer’ in HyperStudy
HyperStudy has proprietary optimization methods such as ARSM (Adaptive Response Surface Method) & GRSM (Global Response Search Method). ARSM optimization method should be used if the number of design variables are less than 7 and/or a local optimal solution is required, or the optimization formulation is single-objective. However, if the number of design variables are greater than 7 and/or a global optima is required or it is a multi-objective optimization formulation, then it is recommended to use the GRSM optimization method.
However, if you have a requirement of using an ‘External Optimizer’ in HyperStudy then you can leverage the ‘Register External Optimizer’ feature of HyperStudy (as shown in Figure 1) which can use Python-based optimizers as external optimizers.
Figure 1 : Register External Optimizer’ feature of HyperStudy
Important points related to the ‘Registered External Optimizer’ in HyperStudy:
- In HyperStudy, when an external optimizer is used in the optimization approach, it is called a ‘User method’.
- When the ‘User method’ is selected in HyperStudy, HyperOpt is invoked to manage the optimization process using the external optimizer. HyperOpt manages the optimization by providing information on problem definition to the external optimizer, initializing solver runs using input variable values obtained from the external optimizer, and providing results from analyses to the external optimizer. The external optimizer performs the optimization using problem definition and analysis result information provided by HyperOpt. It determines when the optimization has converged and relates this to HyperOpt, which then terminates the study.
- An optimizer will only appear in the user-defined pull-down menu if it is registered using the ‘Register External Optimizer’ option under ‘Edit’ tab in HyperStudy (as shown in Figure 1).
This new method of using Python API for integrating external optimizers with HyperStudy supersedes the depreciated method Xopt (User-Defined Optimization Engine).
Procedure of integrating the Python-based optimizers as ‘External Optimizers’ in HyperStudy:
In this example, the optimizer being used is a generic optimizer from the ‘SciPy’ Python library & serves as a template/guide.
- Firstly, register the external optimizer using the Edit> Register External Optimizer’ option (as shown in Figure 1).
- Use the ‘Add External Optimizer’ option to integrate the ‘script_multi_objective.py’ in HyperStudy (as shown in Figure 2).
- The example external optimizer script (script_multi_objective.py) has been provided in this blog as a text file (script_multi_objective.txt file) & hence, should be renamed as .py extension i.e. script_multi_objective.py file.
Figure 2: Adding script_multi_objective.py as an external optimizer in HyperStudy
- The external optimizer script must be added before setting up a new study in HyperStudy as the below shown ‘message’ will appear in HyperStudy.
- Then, under the Optimization approach i.e. ‘Optimization 1> Specifications’, the Python-based optimizers will appear as ‘Python Optimization’ & can be selected as the optimization method for the optimization studies.
Figure 3: Python External Optimization method added in HyperStudy from script_multi_objective.py file
Additional important points related to using ‘script_multi_objective.py’ as an external optimizer in HyperStudy:
- The traditional script only supports continuous variable & single-objective optimization formulation.
- We have updated the script so that it can support the multi-objective optimization formulations as well.
- For the customer to troubleshoot the process of creating/editing this script, the ‘hstlogging library ‘ can be used using the command ‘import alt.hst.utl.hstlogging as hstlogging library’ & the command hstlogging.logger.LogInfo() can be added to the sections which needs to print an error for the user.
- In this example (as shown in Figure 4), if a multi-objective optimization setup has been defined under ‘Define Output Responses’ in the Optimization approach & external optimizer added only supports single-objective setup, then, in the HyperStudy Message tab ‘Message: single objective only’ will be printed for the user (as shown in Figure 5).
Figure 4: Example of using ‘hstlogging’ library to print the error messages in the HyperStudy Message window.
Figure 5 : Error message printed in the HyperStudy Message window.