> ## Documentation Index
> Fetch the complete documentation index at: https://proto.evodesign.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# CMA-ES Optimizer

> Gradient-free evolution strategy: samples per-position residue logits from an adaptive diagonal Gaussian, decodes and scores each sample with the constraints, and moves the distribution toward the lowest-energy samples (separable CMA-ES).

![CMA-ES Optimizer](https://proto-bio.github.io/proto-assets/images/optimizer/cma-es/hero.png)

This optimizer is open source. Any third-party models, product names, or trademarks referenced are the property of their respective owners, and Proto is not affiliated with them.

***

&#x20;Source

![Proto](https://mintcdn.com/bio-pro/cMLt8hAqaP9M3LKy/assets/logo/logo-light.svg?fit=max\&auto=format\&n=cMLt8hAqaP9M3LKy\&q=85\&s=f5e5dfd1b8f9b9db3a0be0e2eb01f678)

evo-design/proto-language

&#x20;View source

[Open](https://github.com/evo-design/proto-language/blob/1a97e675c7e5e4ae0e92be91b1bb7b49f1331104/proto_language/optimizer/cma_es_optimizer.py#L120)

Optimizer contributors[![](https://avatars.githubusercontent.com/u/61667248?v=4\&s=64)adititm](https://github.com/adititm)[![](https://avatars.githubusercontent.com/u/21143637?v=4\&s=64)bviggiano](https://github.com/bviggiano)
Separable (diagonal) CMA-ES over a single segment's logits.

Each trajectory adapts a Gaussian mean, diagonal covariance and step size over the
flattened `(L, |vocab|)` logits, starting from the target's logits (else its one-hot, else zeros).
Samples are decoded by the `PositionWeightGenerator` and scored with `score_energy`;
the best half of each generation's passing samples updates the distribution. Results are each
trajectory's best decoded sequence and energy, with the trajectory's current mean as
`logits`: the learned position-weight matrix, reusable by a later stage.

With `constraint_weight_schedules`, generation `t` scores its samples at the weights
scheduled for `t`; each generation's ranking uses one set of weights, and each trajectory's
best-so-far energy is shifted to those weights from its recorded per-constraint scores before
the generation's best is compared with it.

Reference: Ros & Hansen (2008), "A Simple Modification in CMA-ES Achieving Linear
Time and Space Complexity", PPSN X.

## API Reference

ConfigCMAESOptimizerConfig[ Source](https://github.com/evo-design/proto-language/blob/1a97e675c7e5e4ae0e92be91b1bb7b49f1331104/proto_language/optimizer/cma_es_optimizer.py#L62)

Configuration for separable CMA-ES logit search.

> [!NOTE]
>
> The search dimension is `n = L * |vocab|` (about 4000 for a 200-residue protein),
> so with the default population the covariance and step-size learning rates are small
> and the search moves slowly. It suits short segments or modest budgets of expensive
> scorers; raise `population_size` for longer segments.

**num\_steps** `integer` *required*

Number of CMA-ES generations; each samples, scores, and updates the search distribution.

**num\_results** `integer`

Independent CMA-ES trajectories; each yields one candidate. Overrides program count.

**population\_size** `integer` (default: 16)

Logit samples per trajectory per generation (lambda).

**sigma0** `number` (default: 1.0)

Initial global step size (standard deviation) in logit units.

**seed** `integer`

Random seed for reproducible optimization, generator, and constraint tool streams.

**tracking\_interval** `integer` (default: 1)

Save history and log progress every N steps. Step 0 and final step always saved.

**track\_proposals** `boolean` (default: False)

Save granular per-proposal results (accept/reject) in history snapshots.

**verbose** `boolean` (default: False)

Emit per-step debug information about proposals, scores, and acceptance through the logger.

**checkpoint\_interval** `integer`

With a checkpoint\_dir, checkpoint the running stage every N iterations. None: stage ends only.

**plateau\_patience** `integer`

Stop after N iterations in a row without improving the best energy (first sets it). None disables.

**plateau\_min\_delta** `number` (default: 0.0)

Minimum decrease of the best energy that counts as improvement for plateau\_patience.

**constraint\_weight\_schedules** `array`

Per-constraint weight schedules that override the constraint's static weight at each step.

## Usage

```python python icon="python" theme={null}
>>> optimizer = CMAESOptimizer(
...     target_segment=seg,
...     constructs=[Construct([seg])],
...     generators=[PositionWeightGenerator(PositionWeightGeneratorConfig())],
...     constraints=[gc],
...     config=CMAESOptimizerConfig(num_results=2, num_steps=50),
... )
>>> optimizer.run()
```

## Metadata

| Property | Value |
| - | - |
| Key | `cma-es` |
| Class | `CMAESOptimizer` |
| Targets Single Segment | `True` |
| Uses GPU | `False` |
| Required Constraint Mode | `discrete` |
| Compatible Generators | `position-weight` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.