tidy3d.plugins.design.MethodGenAlg#

class MethodGenAlg[source]#

Bases: MethodOptimize, ABC

A standard method for performing genetic algorithm search, built around the PyGAD 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.

  • solutions_per_pop (PositiveInt) – The number of solutions to be generated for each population.

  • n_generations (PositiveInt) – The maximum number of generations to run the genetic algorithm.

  • n_parents_mating (PositiveInt) – The number of solutions to be selected as parents for the next generation. Crossovers of these parents will produce the next population.

  • stop_criteria_type (Optional[Literal['reach', 'saturate']] = None) – Define the early stopping criteria. Supported words are ‘reach’ or ‘saturate’. ‘reach’ stops at a desired fitness, ‘saturate’ stops when the fitness stops improving. Must set stop_criteria_number. See the PyGAD docs for more details.

  • stop_criteria_number (Optional[PositiveFloat] = None) –

    Must set stop_criteria_type. If type is ‘reach’ the number is acceptable fitness value to stop the optimization. If type is ‘saturate’ the number is the number generations where the fitness doesn’t improve before optimization is stopped. See the PyGAD docs for more details.

  • parent_selection_type (Literal['sss', 'rws', 'sus', 'rank', 'random', 'tournament'] = sss) –

    The style of parent selector. See the PyGAD docs for more details.

  • keep_parents (Union[PositiveInt, Literal[-1, 0]] = -1) –

    The number of parents to keep unaltered in the population of the next generation. Default value of -1 keeps all current parents for the next generation. This value is overwritten if keep_parents is > 0. See the PyGAD docs for more details.

  • keep_elitism (Union[PositiveInt, Literal[0]] = 1) –

    The number of top solutions to be included in the population of the next generation. Overwrites keep_parents if value is > 0. See the PyGAD docs for more details.

  • crossover_type (Optional[Literal['single_point', 'two_points', 'uniform', 'scattered']] = single_point) –

    The style of crossover operation. See the PyGAD docs for more details.

  • crossover_prob (ConstrainedFloatValue = 0.8) – The probability of performing a crossover between two parents.

  • mutation_type (Optional[Literal['random', 'swap', 'inversion', 'scramble', 'adaptive']] = random) –

    The style of gene mutation. See the PyGAD docs for more details.

  • mutation_prob (Optional[ConstrainedFloatValue] = 0.2) – The probability of mutating a gene.

  • save_solution (StrictBool = False) – Save all solutions from all generations within a numpy array. Can be accessed from the optimizer object stored in the Result. May cause memory issues with large populations or many generations. See the PyGAD docs <https://pygad.readthedocs.io/en/latest/pygad.html>_ for more details.

Example

>>> import tidy3d.plugins.design as tdd
>>> method = tdd.MethodGenAlg(solutions_per_pop=2, n_generations=1, n_parents_mating=2)

Attributes

Methods

Inherited Common Usage

solutions_per_pop#
n_generations#
n_parents_mating#
stop_criteria_type#
stop_criteria_number#
parent_selection_type#
keep_parents#
keep_elitism#
crossover_type#
crossover_prob#
mutation_type#
mutation_prob#
save_solution#
__hash__()#

Hash method.