tidy3d.plugins.design.MethodParticleSwarm#
- class MethodParticleSwarm[source]#
Bases:
MethodOptimize
,ABC
A standard method for performing particle swarm search, build around the PySwarms package. The fitness function is maximising by default.
- Parameters:
attrs (dict = {}) β Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields,
attrs
are mutable. For example, the following is allowed for setting anattr
obj.attrs['foo'] = bar
. Also note that Tidy3D` will raise aTypeError
ifattrs
contain objects that can not be serialized. One can check ifattrs
are serializable by callingobj.json()
.name (Optional[str] = None) β Optional name for the sweep method.
seed (Optional[PositiveInt] = None) β Set the seed used by the optimizers to ensure consistant random number generation.
n_particles (PositiveInt) β The number of particles to be used in the swarm for the optimization.
n_iter (PositiveInt) β The maxmium number of iterations to run the optimization.
cognitive_coeff (PositiveFloat = 1.5) β The cognitive parameter decides how attracted the particle is to its previous best position.
social_coeff (PositiveFloat = 1.5) β The social parameter decides how attracted the particle is to the global best position found by the swarm.
weight (PositiveFloat = 0.9) β The weight or inertia of particles in the optimization.
ftol (Union[ConstrainedFloatValue, Literal[-inf]] = -inf) β Relative error in
objective_func(best_solution)
acceptable for convergence. See the PySwarms docs for details. Off by default.ftol_iter (PositiveInt = 1) β Number of iterations over which the relative error in the objective_func is acceptable for convergence.
init_pos (Optional[ndarray] = None) β Set the initial positions of the swarm using a numpy array of appropriate size.
Example
>>> import tidy3d.plugins.design as tdd >>> method = tdd.MethodParticleSwarm(n_particles=5, n_iter=3)
Attributes
Methods
Inherited Common Usage
- n_particles#
- n_iter#
- cognitive_coeff#
- social_coeff#
- weight#
- ftol#
- ftol_iter#
- init_pos#
- __hash__()#
Hash method.