Beamline optics: costly settings#

Tune magnet and screen settings with a maximin design; no two setups are near-duplicates.

A beam-line tuning study varies the currents of three focusing magnets and the apertures of two collimators to map how the optics respond. Each configuration is expensive to simulate or measure, so a compact space-filling design over the control settings is chosen. The beam observables (emittance, transmission, spot size) are computed downstream, not by Mergen.

The design is scored with phi_p (maximin), which maximises the minimum separation between configurations — the natural objective when each setting is costly and near-duplicate settings would waste beam time.

Parameters (stepped grids, in engineering units)#

  • quad1_current, quad2_current, quad3_current (50-150 A, 10 A steps): the focusing-magnet currents, at the resolution the supplies are set.

  • collimator1_aperture, collimator2_aperture (2-20 mm, 2 mm steps): the collimator gaps.

What to look at#

  • summary() and quality_report(): the design covers the five-factor control space; the min_distance percentile confirms the maximin objective pushed the configurations apart.

  • The saved distances plot: for a maximin design the pairwise-distance distribution should sit well away from zero, meaning no two settings are near-duplicates.

  • beamline_runs.csv: the control-room run list.

Mergen features used#

  • Five stepped numeric factors in engineering units.

  • criteria='phi_p' as the maximin choice for maximally separated, expensive configurations.

  • A validation hold-out via set_design(n_validation=...).

  • Sampler.set_optimizer(): a modest compute budget for a quick demo.

  • plot('distances') as the natural view for a maximin design.

Estimated runtime: a few seconds to a minute.

from mergen import ParameterSpace, Sampler

# 1. Define the five-factor beam-line control space on stepped grids.
space = ParameterSpace({
    'quad1_current':        range(50, 151, 10),     # A
    'quad2_current':        range(50, 151, 10),
    'quad3_current':        range(50, 151, 10),
    'collimator1_aperture': range(2, 21, 2),        # mm
    'collimator2_aperture': range(2, 21, 2),
})

# 2. Build a maximin (phi_p) design with a validation hold-out.
sampler = Sampler(space)
sampler.set_design(n_samples=25, n_validation=5)
sampler.set_optimizer('sa', n_restarts=1, max_iter=300)
result = sampler.run(criteria='phi_p')

# 3. Inspect and save the control-room run list.
result.summary()
result.quality_report()
result.plot('distances', save=True)
result.to_csv('beamline_runs.csv')
  [WARNING]  n_samples (25) < recommended 10*n_parameters (50, Loeppky et al. 2009). Design quality may be reduced.

════════════════════════════════════════════════════════════
  MERGEN — Space-filling Design
════════════════════════════════════════════════════════════
  Parameters      : 5
  Candidates      : 133,100
  n_samples       : 25  (prescribed_in=0, focus_in=0, optimised_slots=25)
  Total design    : 25
  Validation      : 5
  Criterion       : phi_p
  Algorithm(s)    : sa
────────────────────────────────────────────────────────────
  [MERGEN]   Optimising (criterion=phi_p, algorithm=sa)...
  [SA]       Tuning temperature...
  [SA]       Start  log(score)=1.581  T=1.0255e-02  iters=300  swappable=25  hybrid=0.50
  [SA]       Done   log(score)=0.722  (accepted=68/300, rate=22.7%)
  [MERGEN]   sa     done -- score=2.059  (elapsed 2.4s)

────────────────────────────────────────────────────────────
  MERGEN — Final Design
────────────────────────────────────────────────────────────
  Prescribed (in)  : 0
  Prescribed (out) : 0
  Focus (in)       : 0
  Focus (out)      : 0
  Optimised        : 25
  Total design     : 25
  Validation       : 5
════════════════════════════════════════════════════════════

────────────────────────────────────────────────────
  MERGEN Design Summary
────────────────────────────────────────────────────
  Optimised       : 25
  Total design    : 25
  Validation      : 5
────────────────────────────────────────────────────
  Parameters      : 5
  Candidates      : 133100
  Criterion       : phi_p
  Seed            : 44
  Algorithm       : sa
────────────────────────────────────────────────────

  [METRICS]  Computing MC baseline (300 designs)...
  [METRICS]  MC baseline complete (300 designs).

════════════════════════════════════════════════════════════════════════
  MERGEN Design Metrics  (n=25, d=5)
════════════════════════════════════════════════════════════════════════
  Metric                      Value    Baseline  Better when        Rank
────────────────────────────────────────────────────────────────────────
  Min distance               0.5417      0.2497  higher        100th pct  *
  Minimax distance           0.9408      0.9825  lower          80th pct
  Max |correlation|          0.2239      0.3819  lower          98th pct
  2D projection CD2          0.1416      0.1400  lower          48th pct
  CV distances               0.2438      0.2790  lower         100th pct  *
  Mean distance              1.0232      0.9666  higher         90th pct  *
────────────────────────────────────────────────────────────────────────
  Criterion scores
────────────────────────────────────────────────────────────────────────
  PHI_P                          2.0589      4.0868  100th pct  lower
────────────────────────────────────────────────────────────────────────
  * = primarily optimised by 'phi_p'
  For other priorities, see: mergen.criteria.list_criteria()
────────────────────────────────────────────────────────────────────────
  Baseline: 300 MC designs from feasible space  |  Rank = percentile among baseline designs
════════════════════════════════════════════════════════════════════════

  Saved: outputs/distances_3.png
  Saved: outputs/beamline_runs.csv  (30 rows)
15 beamline optics

Total running time of the script: (0 minutes 11.357 seconds)

Gallery generated by Sphinx-Gallery