# Optimization¶

One goal of simulation is to determine system input parameters (like lens voltages and geometric dimensions) that optimize some output parameter (e.g. beam spot radius).

Optimization in SIMION is demonstrated foremost in SIMION Example: tune (voltage optimization) and SIMION Example: geometry_optimization (geometry optimization), and a few other examples apply the techniques like in SIMION Example: lens_properties and SIMION Example: hda. A related example is SIMION Example: spectrum (spectrum generation), which is not strictly speaking an optimization problem but does iterate voltages in a similar manner.

There are a variety of ways to iterate through the parameters,
as the more recent (v8.1.0.40 or higher) versions of
SIMION Example: tune illustrate.
These include exhaustive iteration, binary search, and simplex optimization
(see also *simionx.SimplexOptimizer - Simplex optimizer*).
Some have also used genetic algorithms (GA) listed at bottom.

There are also a variety of ways to measure the parameter being optimized, such as shown in SIMION Example: test_plane and SIMION Example: lens_properties.

The problem gets inherently more complicated when you have more than one input parameter and/or if your output parameter has more than one (or even an infinite number of) local extrema. The larger number of dimensions lengthens the time to do an exhaustive (brute force) search, while on the other hand the possibility of more than one local extrema means that a more directed search (e.g. simplex) may hone in on only one extrema for a given starting position, so you may want to combine both search techniques.

Please note that SIMION 8.1.0.40 provides new programming segments
(see *Workbench Program Extensions in SIMION 8.1*), which simplify and makes more
robust problems involving optimization and reruns (e.g. avoiding problems
in earlier versions with terminate segments not being called and making
loops simpler to write).
Examples were updated accordingly to take advantage of these improvements.

## Genetic Algorithms¶

- SIMION Example: tune (2016-12-06 or latest) includes a tune_genetic.iob example and library (geneticlib), useful as a starting point.
- Dowsett2015. Dowsett, D. Advanced SIMION Techniques: Boundary Matching and Genetic Optimization. Microscopy and Microanalysis, volume 21, issue S4, year 2015, pages 218-223 doi:10.1017/S1431927615013409; link – A parallelized genetic algorithm has been written for use with SIMION. The GA is split into three parts: a gui written in MS Visual C++, a database which stores the population and a series of SIMION workers which evaluate the fitness of each individual.
- KarpovSysoev2015. Karpov, A.V. Sysoev, Alexander A. Poteshin, S.S. Chernyshev, D.M. Sysoev, Alexey A. Genetic Algorithm for Voltage Optimization of Gridless Ion Mirror. Physics Procedia. volume 72, year 2015, pages 236-240. doi:10.1016/j.phpro.2015.09.070
- Pratap Timilsina. Development of an Electron Time of Flight Spectrometer for Ultrafast Pulse Characterization and Ultrafast Dynamics Studies. Kansas State University, 2016. link – “electron time-of-flight (ETOF) spectrometer to be used for characterizing ultrafast electric field pulses” “The precise tuning of the electrostatic lens system is done with a Genetic Algorithm (GA) with an intensity fluctuation discriminator in the fitness.” Uses SIMION.
- Majd Salman. Auto focus for electrons. Lund University, 2011. link – a 3D momentum imaging spectrometer. “A genetic algorithm was implemented for finding optimal parameter values that resolve a set of given energies.” Uses SIMION batch mode with C# driver code.
- Hanh Tuyet Lai. The Construction and Optimization on an Ion Mobility Spectrometer for the Analysis of Explosives and Drugs. Florida International University, dissertation. link – “A Genetic Algorithm (GA) technique was developed to optimize the operating conditions of a commercial IMS (GE Itemizer 2)” “The simulation method developed uses SIMION/SDS and was evaluated with experimental data collected using a commercial IMS (PCP Phemto Chem 110).”
- Some other Lua code, though most of these are binary: link link link
- For an intro to genetic algorithms, see
- Genetic Algorithms - Quick Guide (tutorialspoint)
- Fundamentals of Genetic Algorithms (myreaders.info)