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 an attr obj.attrs['foo'] = bar. Also note that Tidy3D` will raise a TypeError if attrs contain objects that can not be serialized. One can check if attrs are serializable by calling obj.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.