Robust optimisation

An ordinary optimisation scores each candidate at its nominal shape. A robust optimisation scores it under its manufacturing tolerances: with a uq_config in the candidates’ eigenmode settings, each candidate’s figures of merit come back as a mean and a standard deviation, and the candidates are ranked by a value that penalises a large spread. The front then holds designs that stay good across their tolerances.

The search here is kept small, two candidates and one generation, because every candidate is a whole set of perturbed solves.

import os
import tempfile

import matplotlib.pyplot as plt

from cavsim2d import Study, EllipticalCavity
from cavsim2d.utils.style import apply_style

apply_style()

1. The search and the tolerances

The search varies the equator half-axes A and B, tunes every candidate to 1300 MHz, and minimises the two peak-field ratios. Each candidate’s A and B vary by up to 0.2 mm either side of their values.

cavs = Study(os.path.join(tempfile.mkdtemp(), 'robust_opt'))
midcell = [42, 42, 12, 19, 35, 57.7, 103.353]
cavs.add_cavity([EllipticalCavity(1, midcell, midcell, midcell, beampipe='none')], ['TESLA'])

config = {
    'initial_points': 2, 'no_of_generation': 1,
    'method': {'LHS': {'seed': 5}},
    'bounds': {'A': [40, 46], 'B': [40, 46]},
    'objectives': [['min', 'monopole:Epk/Eacc []'],
                   ['min', 'monopole:Bpk/Eacc [mT/MV/m]']],
    'tune_config': {
        'freqs': 1300.0, 'cell_type': {'mid-cell': 'Req'},
        'eigenmode_config': {
            'boundary_conditions': 'mm',
            'uq_config': {
                'variables': ['A', 'B'],
                'delta': [0.2, 0.2],                   # mm
                'method': ['Quadrature', 'Stroud3'],
                'objectives': ['monopole:Epk/Eacc []', 'monopole:Bpk/Eacc [mT/MV/m]'],
            },
        },
    },
    'mutation_factor': 2, 'crossover_factor': 2, 'elites_for_crossover': 2,
    'chaos_factor': 2,
}

2. Run it

cavs.run_optimisation(config)
opt = cavs.optimisation
print(f'evaluated candidates: {len(opt.history)}')
  0%|          | 0/1 [00:00<?, ?it/s]
100%|██████████| 1/1 [00:23<00:00, 23.92s/it]
100%|██████████| 1/1 [00:23<00:00, 23.92s/it]
evaluated candidates: 2

3. The robust objectives

For each objective, the history holds the mean E[...], the standard deviation std[...], and the value the candidates are ranked by, E[...] + 6*std[...]. A design with a slightly worse mean but a much smaller spread can therefore win.

cols = [c for c in opt.history.columns
        if c.startswith(('E[', 'std['))]
opt.history[cols].round(4)
E[monopole:Epk/Eacc []] std[monopole:Epk/Eacc []] E[monopole:Epk/Eacc []] + 6*std[monopole:Epk/Eacc []] E[monopole:Bpk/Eacc [mT/MV/m]] std[monopole:Bpk/Eacc [mT/MV/m]] E[monopole:Bpk/Eacc [mT/MV/m]] + 6*std[monopole:Bpk/Eacc [mT/MV/m]]
0 2.0215 0.0021 2.0339 4.0835 0.0045 4.1107
1 1.9928 0.0071 2.0353 4.1903 0.0073 4.2341

The two candidates show what the ranking does. By their means alone neither beats the other: candidate 1 has the lower peak electric field, 1.9928 times the gradient against 2.0215, and candidate 0 the lower peak magnetic field, 4.0835 against 4.1903 mT/(MV/m). But candidate 1’s peak electric field spreads more than three times as much, 0.0071 against 0.0021, so its robust value, 2.0353, is above candidate 0’s, 2.0339. On the robust values candidate 0 is better in both objectives.

4. The Pareto front

The front holds candidate 0 alone, drawn at its mean figures of merit.

opt.plot_pareto(kind='scatter', normalise=False);
../../_images/9edd6dc24b5fb20021dbd2eebcd8197af6bef3a2340fa9fed7241ef98e51fd38.png

See also: the optimisation guide, the uncertainty quantification guide, and robust tuning.