# Optimize step

An *optimize* step generates optimized configurations according to the defined optimization strategy. During this step, the Akamas AI is used to generate such optimized configurations.

The *optimize* step has the following structure:

| Field                     | Type    | Value restrictions                                                                                                             | Is required | Default value | Description                                                                                                                                                              |
| ------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `type`                    | string  | `optimize`                                                                                                                     | yes         |               | The type of the step, in this case, `optimize`                                                                                                                           |
| `name`                    | string  |                                                                                                                                | yes         |               | The name of the step                                                                                                                                                     |
| `runOnFailure`            | boolean | <p><code>true</code><br><code>false</code></p>                                                                                 | no          | `false`       | <p>Step execution policy:</p><ul><li><code>false</code>: don't run if the previous step failed</li><li><code>true</code>: run even if the previous step failed</li></ul> |
| `numberOfExperiments`     | integer | <p><code>numberOfExperiments</code> > 0 and</p><p><code>numberOfExperiments</code> >= <code>numberOfInitExperiments</code></p> | yes         |               | The number of experiments to execute - see below                                                                                                                         |
| `numberOfTrials`          | integer | `numberOfTrials` > 0                                                                                                           | no          | 1             | The number of trials to execute for each experiment                                                                                                                      |
| `numberOfInitExperiments` | integer | `numberOfInitExperiments` < `numberOfExperiments`                                                                              | no          | 10            | The number of initialization experiment to execute - see below.                                                                                                          |
| `maxFailedExperiments`    | integer | `maxFailedExperiments` > 1                                                                                                     | no          | 30            | The number of experiment failures (as either workflow errors or constraint violations) to accept before the step is marked as failed                                     |
| `optimizer`               | string  | <p><code>AKAMAS</code><br><code>SOBOL</code><br><code>RANDOM</code></p>                                                        | no          | `AKAMAS`      | The type of optimizer to use to generate the configuration of the experiments - see below                                                                                |
| `doNotRenderParameters`   | string  |                                                                                                                                | no          |               | Parameters not to be rendered. - see [Parameter rending](https://docs.akamas.io/akamas-docs/3.6/reference/construct-templates/study-template/parameter-rendering)        |
| `renderParameters`        | string  |                                                                                                                                | no          |               | Parameters to be rendered. - see [Parameter rending](https://docs.akamas.io/akamas-docs/3.6/reference/construct-templates/study-template/parameter-rendering)            |

### Optimizer

The `optimizer` field allows selecting the desired optimizer:

* `AKAMAS` identifies the standard AI optimizer used by Akamas
* `SOBOL` identifies an optimizer that generates configurations using [Sobol sequences](https://en.wikipedia.org/wiki/Sobol_sequence)
* `RANDOM` identifies an optimization that generates configurations using random numbers

Notice that SOBOL and RANDOM optimizers do not perform initialization experiments, hence the field `numberOfInitExperiments` is ignored.

Refer to the page [optimizer-options](https://docs.akamas.io/akamas-docs/3.6/reference/construct-templates/study-template/optimizer-options "mention") for more configuration options for the optimizer

### Failures <a href="#failures" id="failures"></a>

The *optimize* step is fault-tolerant and tries to relaunch experiments on failure. Nevertheless, the step limits the number of failed experiments: if too many experiments fail, then the entire step fails too. By default, at most 30 experiments can fail while Akamas is optimizing systems. An experiment is considered failed when it fails to run (i.e., there is an error in the workflow) or violates some constraint.

### Initializations <a href="#inizialitation-experiments" id="inizialitation-experiments"></a>

The *optimize* step launches some initialization experiments (by default 10) that do not apply the AI optimizer and are used to find good configurations. By default, the step performs 10 initialization experiments.

Initialization experiments take into account bootstrapped experiments, experiments executed in preset steps, and baseline experiments.

### Example

The following snippet shows an optimization step that runs 50 experiments using the SOBOL optimizer:

```yaml
name: "my_optimize"      # name of the step
type: "optimize"         # type of the step (optimize)
optimizer: "SOBOL"
numberOfExperiments: 50  # amount of experiments to execute
numberOfTrials: 2        # amount of trials for each experiment
```
