# Global Optimization
Editor: Design Optimization › Global Optimization · Python: tidy3d.plugins.design
Python client only
The editor lists Global Optimization and its three methods, but cannot run them. They run only in the Tidy3D Python client. In the editor, Try it in Python under each method opens an example notebook in a new tab.
Global optimization searches for the best design by running many simulations. At each step, the method picks new parameter values from the results so far. It needs no gradient, so it works with any figure of merit. The editor's Parameter Sweep instead runs a fixed list of designs.
# Python Fields
Each method is a class of tidy3d.plugins.design. Put it in a DesignSpace, with the parameters (for example ParameterFloat(name=..., span=(min, max))), then call run with a function that returns the figure of merit.
| Editor name | Python class | Required fields |
|---|---|---|
| Genetic Algorithm | MethodGenAlg | solutions_per_pop, n_generations, n_parents_mating |
| Particle Swarm | MethodParticleSwarm | n_particles, n_iter |
| Bayesian Optimization | MethodBayOpt | initial_iter, n_iter |
The methods need the optional packages of the client: pip install "tidy3d[design]".
# Python Example
import tidy3d.plugins.design as tdd
# One design parameter: a width between 0.4 and 1.0 µm.
width = tdd.ParameterFloat(name="width", span=(0.4, 1.0))
# Bayesian optimization: 5 random starting points, then 10 guided steps.
method = tdd.MethodBayOpt(initial_iter=5, n_iter=10, seed=1)
design_space = tdd.DesignSpace(parameters=[width], method=method, task_name="global_opt")
def figure_of_merit(width: float) -> float:
# In a real study, build and run a td.Simulation here and return its result.
return -((width - 0.7) ** 2)
result = design_space.run(figure_of_merit)
print(result.optimizer.max) # the best width found, close to 0.7
# When to Use It
Use it when the design has a few parameters, each simulation is short, and you want the best design, not a map of all designs. Use something else when you want to see how the result changes over a grid of values: use the editor's Parameter Sweep.