HyperStudy Tips and Tricks: #29 - Using ‘External Optimizer’ in HyperStudy

Garima_Singh
Garima_Singh
Altair Employee
edited June 11 in Altair HyperWorks

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.

image

Figure 1 : Register External Optimizer’ feature of HyperStudy

Important points related to the ‘Registered External Optimizer’ in HyperStudy:

  1. In HyperStudy, when an external optimizer is used in the optimization approach, it is called a ‘User method’.
  2. 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.
  3. 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.

  1. Firstly, register the external optimizer using the Edit> Register External Optimizer’ option (as shown in Figure 1).
  2. Use the ‘Add External Optimizer’ option to integrate the ‘script_multi_objective.py’ in HyperStudy (as shown in Figure 2).
  3. 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.

image

Figure 2: Adding script_multi_objective.py as an external optimizer in HyperStudy

  1. The external optimizer script must be added before setting up a new study in HyperStudy as the below shown ‘message’ will appear in HyperStudy.

image

  1. 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.

image

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:

  1. The traditional script only supports continuous variable & single-objective optimization formulation.
  2. We have updated the script so that it can support the multi-objective optimization formulations as well.
  3. 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.
  4. 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).

image

Figure 4: Example of using ‘hstlogging’ library to print the error messages in the HyperStudy Message window.

image

Figure 5 : Error message printed in the HyperStudy Message window.