Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 78

Coil Optimization with Gradient and Genetic Algorithms

Recommended resources

Hello! Welcome back to our course on high-field magnet design.

In the last lesson, we established the crucial first step in automated design: formally defining an optimization problem. We learned how to break down the complex task of designing a magnet into a set of design variables (the parameters we can change), objective functions (the metrics we want to optimize), and constraints (the physical limits we must respect).

This lesson addresses the next logical step and a key learning outcome for this module: Apply a gradient-based or genetic algorithm to explore the design space and find an optimal coil geometry. We will move from formulating the problem to solving it, exploring the powerful algorithms that search through millions of potential designs to find the best ones.

We will investigate two major families of optimization algorithms:

  1. Local search methods, which are excellent for refining an existing design.
  2. Genetic algorithms, which are powerful global explorers capable of discovering truly novel designs.

1. The "Hill-Climbing" Approach: Local Optimization

Imagine your design space is a vast, mountainous landscape shrouded in fog. Your objective is to find the lowest point (e.g., to minimize stress). A local optimization algorithm works like a hiker who can only feel the slope directly under their feet. They take a step in the steepest downward direction, reassess, and repeat. This process is often called "hill-climbing" or, in our case, "valley-descending."

Gradient-Based Methods

The most mathematically direct way to find the "steepest direction" is to compute the gradient of the objective function, . This vector points in the direction of the greatest increase of the function . To minimize , the algorithm simply takes a step in the direction of .

  • Pros: When the design landscape is smooth and has only one valley (i.e., it's a convex problem), gradient-based methods are extremely fast and efficient.
  • Cons: They are easily trapped in the first local minimum they find, potentially missing a much deeper valley elsewhere. Furthermore, for our complex multi-physics simulations, calculating the gradient (which requires a "sensitivity analysis") can be computationally expensive or numerically unstable.

Direct Search Methods (Gradient-Free)

What if you can't compute the gradient? Direct search methods provide an alternative. They don't use derivative information but instead evaluate the objective function at a pattern of points to decide where to move next.

A classic example, and one highly relevant to our topic, is the Nelder-Mead simplex method. This is the algorithm used in the dissertation we've been studying.

Design and Optimization of Force-Reduced High Field ...

The dissertation 'Design and Optimization of Force-Reduced High Field ...' by Szabolcs Rembeczki provides an excellent practical example of applying a direct search method. The author uses the Nelder-Mead algorithm to find the optimal winding pitch angles.

Please read section 3.4.1, 'Optimization Based on Force-Free Magnetic Field Theory'. Focus on the description of the optimization routine. You'll see that the author minimizes the angle κ by varying the pitch angles γ, using the Nelder-Mead simplex method. This is a perfect example of a local optimization strategy applied to coil design.

The Nelder-Mead method works by forming a "simplex" (e.g., a triangle in a 2D design space) of trial points. It evaluates the objective at each vertex and iteratively improves the simplex by reflecting, expanding, or contracting it away from the worst-performing vertex. It's a robust way to find the bottom of the nearest valley, even if the terrain is a bit rough. However, like gradient-based methods, it has no mechanism for escaping that valley to find a better one elsewhere.


2. The Power of Evolution: Genetic Algorithms (GAs)

To overcome the limitations of local search, we turn to a different inspiration: natural selection. Genetic Algorithms (GAs) are global search methods that maintain a "population" of candidate designs. Over many "generations," the population evolves towards optimal solutions.

This approach is especially powerful for magnet design because it can handle complex problems with both continuous variables (like winding angles) and discrete variables (like the number of turns in a block), a significant challenge for traditional methods.

The following paper from CERN demonstrates beautifully why and how GAs are used for designing accelerator magnets.

Genetic Algorithms for the Optimal Design of ...

This paper, 'Genetic Algorithms for the Optimal Design of Superconducting Accelerator Magnets', is a seminal work on applying GAs in our field. It clearly lays out the motivation and methodology.

Please read sections 1, 2, and 3. Pay close attention to: Section 1: The reasons why deterministic methods were insufficient for their design problem. Section 2: How they define the optimization problem (objectives, variables). Section 3: The core mechanics of the GA: how designs are encoded into 'chromosomes' and the roles of the three main operators: Selection, Crossover, and Mutation.

As you read, the core workflow of a GA is:

  1. Initialization: Create a large, random population of designs (chromosomes).
  2. Evaluation: Calculate the "fitness" of each design by running a simulation (e.g., FEM) and evaluating the objective function.
  3. Selection: Choose parent designs for the next generation. Fitter individuals have a higher probability of being selected.
  4. Reproduction:
    • Crossover: Combine parts of two parent chromosomes to create one or more offspring. This is the primary exploration mechanism, mixing and matching good features from different designs.
    • Mutation: Introduce small, random changes to an offspring's chromosome. This maintains genetic diversity and prevents the algorithm from converging too early.
  5. Repeat: The new generation replaces the old, and the cycle repeats.

The remarkable outcome of this process is that GAs can uncover non-intuitive, high-performance designs that a human designer, or a local optimizer, might never find. The CERN paper showcases this by finding a novel 6-block coil design that outperformed the existing 5-block design.

3D Magnetic Flux Density Simulation of an Optimized Coil
This image shows a typical output from an optimization run, visualizing the magnetic field for one of the final, optimized coil designs found by the algorithm.

3. Multi-Objective Genetic Algorithms (MOGAs)

In our previous lesson, we established that real-world design involves trading off between multiple, often conflicting, objectives (e.g., maximizing field vs. minimizing stress). A simple GA that optimizes for a single fitness value isn't enough. We need a method that can find the entire Pareto front of optimal trade-offs.

Multi-Objective Genetic Algorithms (MOGAs) achieve this by changing how individuals are selected. Instead of a single fitness score, individuals are ranked based on the concept of Pareto dominance.

A design A dominates a design B if A is better than or equal to B in all objectives, and strictly better in at least one objective. The goal of a MOGA is to find the set of non-dominated solutions.

A key challenge in this process is ensuring the final population is spread out across the entire Pareto front, giving the designer a diverse set of trade-offs to choose from. The following video explains this beautifully.

Multi-Objective Optimisation - Writing your own Genetic Algorithm Part 6

This video from 'Tutorials with Gary' gives an excellent and intuitive explanation of how a Multi-Objective Genetic Algorithm works, focusing on the concepts of Pareto fronts and a mechanism to ensure diversity.

Please watch the entire video (0:37-13:26). It will reinforce the concept of Pareto optimality and introduce two key algorithmic ideas: Front Sorting: How the population is ranked into successive Pareto fronts. Crowding Distance: The clever mechanism used to promote diversity and ensure the algorithm finds solutions across the full spectrum of trade-offs, from one extreme to the other.

Algorithms like NSGA-II (Non-dominated Sorting Genetic Algorithm II) are industry-standard tools that implement exactly these concepts: non-dominated sorting to identify the Pareto fronts, and crowding distance to maintain diversity along those fronts.

Test your understanding!

You are using a MOGA to optimize a coil design with two objectives: (1) Maximize the central field and (2) Minimize the peak von Mises stress . The algorithm returns two solutions from the final Pareto front:

  • Design A: T, MPa
  • Design B: T, MPa

Which design is "better"? How does the concept of crowding distance influence the likelihood that the algorithm would find both of these solutions?

Show answer

Neither design is objectively "better" in an absolute sense; they represent different optimal trade-offs. Design B achieves a higher field but at the cost of higher stress. Design A is a more conservative choice with lower stress but also a lower field. Both are "Pareto optimal" because you cannot improve one objective without worsening the other.

The role of crowding distance is to encourage the algorithm to find and keep both of these solutions. If the algorithm only found solutions clustered around Design B, it might miss the valuable, lower-stress option offered by Design A. By assigning a higher fitness priority to solutions in less-crowded regions of the design space, the algorithm is incentivized to spread its population along the entire front, exploring the full range of possibilities from high-field/high-stress to lower-field/lower-stress.


4. A Practical Optimization Workflow

In practice, designers often combine the strengths of both local and global search methods. A typical workflow for designing a novel magnet might look like this:

  1. Global Exploration: Use a Multi-Objective Genetic Algorithm (e.g., NSGA-II) to perform a broad search of the design space. This computationally intensive step might run for hours or days, calling your FEM solver thousands of times to evaluate different designs. The output is not a single answer but the Pareto front of promising candidate topologies.
  2. Analysis and Selection: The engineer examines the Pareto front, plotting the trade-offs (e.g., peak field vs. coil mass vs. peak stress). Based on the project's specific priorities, one or a few candidate designs are selected from the front for further refinement.
  3. Local Refinement: Starting from a promising design found by the GA, a local search algorithm (like Nelder-Mead or a gradient-based method) is used to "polish" the solution. This fine-tunes the continuous parameters to find the precise local minimum in that region of the design space.

This hybrid approach gives you the best of both worlds: the creative, exploratory power of GAs and the fast, precise convergence of local optimizers. The Rembeczki dissertation is a great example of the latter part of this process, applying a local optimizer to refine a well-defined "variable pitch" concept.


Conclusion

Today, we've opened the black box of design optimization and looked at the algorithms inside. You now understand the fundamental differences between local "hill-climbers" and global "evolutionary explorers" and how they are applied to the problem of magnet design.

Key Takeaways:

  • Local vs. Global Search: Gradient-based and direct search methods (like Nelder-Mead) are efficient for refining a design locally but can get stuck in suboptimal solutions.
  • Genetic Algorithms (GAs): GAs use principles of evolution (population, selection, crossover, mutation) to perform a robust global search, making them ideal for discovering novel designs with mixed continuous and discrete variables.
  • Multi-Objective GAs (MOGAs): By using Pareto dominance ranking and diversity-preservation techniques like crowding distance, MOGAs can identify the entire family of optimal trade-off solutions for problems with conflicting objectives.
  • Hybrid Workflow: A powerful strategy combines a GA for initial global exploration with a local optimizer for final refinement of the chosen design.

Next Lesson Preview

We have now learned how to build complex multi-physics simulations and use sophisticated algorithms to find optimal designs based on those simulations. But this all hinges on one critical assumption: that our simulations are an accurate reflection of reality. How can we be sure?

In our final lesson of this module, we will tackle this question head-on. The topic is "Validate simulation results against analytical solutions for simple geometries and available experimental data." We will explore the essential engineering practice of Verification and Validation (V&V), which provides the confidence needed to trust our simulation results and, by extension, the designs they produce.