tidy3d.plugins.design.DesignSpace#

class DesignSpace[source]#

Bases: Tidy3dBaseModel

Specification of a design problem / combination of several parameters + algorithm.

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().

  • parameters (Tuple[Union[ParameterInt, ParameterFloat, ParameterAny], ...] = ()) โ€“ Set of parameters defining the dimensions and allowed values for the design space.

  • method (Union[MethodMonteCarlo, MethodGrid, MethodRandom, MethodRandomCustom]) โ€“ Specifications for the procedure used to explore the parameter space.

  • name (Optional[str] = None) โ€“ Optional name for the design space.

Example

>>> import tidy3d.plugins.design as tdd
>>> param = tdd.ParameterFloat(name="x", span=(0,1))
>>> method = tdd.MethodMonteCarlo(num_points=10)
>>> design_space = tdd.DesignSpace(parameters=[param], method=method)
>>> fn = lambda x: x**2
>>> result = design_space.run(fn)
>>> df = result.to_dataframe()
>>> im = df.plot()

Attributes

design_parameter_dict

Mapping of design parameter name to design parameter.

dims

dimensions defined by the design parameter names.

method

Defines the methods used for parameter sweep.

attrs

Methods

get_fn_source(function)

Get the function source as a string, return None if not available.

run(function,ย **kwargs)

Run the design problem on a user defined function of the design parameters.

run_batch(fn_pre,ย fn_post[,ย path_dir])

Run a design problem where the function is split into pre and post processing steps.

Inherited Common Usage

parameters#
method#
name#
property dims#

dimensions defined by the design parameter names.

property design_parameter_dict#

Mapping of design parameter name to design parameter.

static get_fn_source(function)[source]#

Get the function source as a string, return None if not available.

run(function, **kwargs)[source]#

Run the design problem on a user defined function of the design parameters.

Parameters:

function (Callable) โ€“ Function accepting arguments that correspond to the .name fields of the DesignSpace.parameters.

Returns:

Object containing the results of the design space exploration. Can be converted to pandas.DataFrame with .to_dataframe().

Return type:

Result

run_batch(fn_pre, fn_post, path_dir=None, **batch_kwargs)[source]#

Run a design problem where the function is split into pre and post processing steps.

Parameters:
  • fn_pre (Callable[Union[SimulationData, List[SimulationData], Dict[str, SimulationData]], Any]) โ€“ Function accepting arguments that correspond to the .name fields of the DesignSpace.parameters. Returns either a Simulation, list of Simulation`s or a `dict of :class:`.Simulation`s to be run in a batch.

  • fn_pre โ€“ Function accepting the SimulationData object(s) corresponding to the fn_pre and returning the result of the parameter sweep function. If fn_pre returns a single simulation, it will be passed as a single argument to fn_post. If fn_pre returns a list of simulations, their data will be passed as *args. If fn_pre returns a dict of simulations, their data will be passed as **kwargs with the keys corresponding to the argument names.

  • path_dir (str = None) โ€“ Optional directory in which to store the batch results.

Returns:

Object containing the results of the design space exploration. Can be converted to pandas.DataFrame with .to_dataframe().

Return type:

Result

__hash__()#

Hash method.