tidy3d.plugins.design.Result#

class Result[source]#

Bases: Tidy3dBaseModel

Stores the result of a run over a DesignSpace. Can be converted to pandas.DataFrame with Result.to_dataframe() for post processing.

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

  • dims (Tuple[str, ...] = ()) – The dimensions of the design variables (indexed by β€˜name’).

  • values (Tuple[Any, ...] = ()) – The return values from the design problem function.

  • coords (Tuple[Tuple[Any, ...], ...] = ()) – The values of the coordinates corresponding to each of the dims.Note: shaped (D, N) where D is the len(dims) and N is the len(values)

  • output_names (Optional[Tuple[str, ...]] = None) – Names for each of the outputs stored in values. If not specified, default values are assigned.

  • fn_source (Optional[str] = None) – Source code for the function evaluated in the parameter sweep.

  • task_names (Optional[list] = None) – Task name of every simulation run during DesignSpace.run. Only available if the parameter sweep function is split into pre and post processing, otherwise is None. Stored in the same format as the output of fn_pre i.e. if pre outputs a dict, this output is a dict with the keys preserved.

  • task_paths (Optional[list] = None) – Task paths of every simulation run during DesignSpace.run. Useful for loading download SimulationData hdf5 files.Only available if the parameter sweep function is split into pre and post processing, otherwise is None. Stored in the same format as the output of fn_pre i.e. if pre outputs a dict, this output is a dict with the keys preserved.

  • aux_values (Optional[Tuple[Any, ...]] = None) – The auxiliary return values from the design problem function. This is the collection of objects returned alongside the float value used for the optimization. These weren’t used to inform the optimizer, if one was used.

  • optimizer (Optional[Any] = None) – The optimizer returned at the end of an optimizer run. Can be used to analyze and plot how the optimization progressed. Attributes depend on the optimizer used; a full explaination of the optimizer can be found on associated library doc pages. Will be None for sampling based methods.

Example

>>> import tidy3d.plugins.design as tdd
>>> result = tdd.Result(
...     dims=('x', 'y', 'z'),
...     values=(1, 2, 3, 4),
...     coords=((0,1,2), (1,2,3), (2,3,4), (3,4,5)),
...     output_names=("output",),
... )
>>> df = result.to_dataframe()
>>> # df.head() # print out first 5 elements of data

Attributes

data

Dict mapping tuple of fn args to their value.

attrs

Methods

add(fn_args, value)

Add a specific argument and value the result.

combine(other)

Combine data from two results into a new result (also works with '+').

default_value_keys(value)

The default keys for a given value.

delete(fn_args)

Delete a specific set of arguments from the result.

from_dataframe(df[, dims])

Load a result directly from a pandas.DataFrame object.

get_index(fn_args)

Get index into the data for a specific set of arguments.

get_value(coords)

Get a data element indexing by function arg tuple.

items()

Iterate through coordinates (args) and values (outputs) one by one.

sel(**kwargs)

Get a data element by function kwargs..

to_dataframe([include_aux])

Data as a pandas.DataFrame.

value_as_dict(value)

How to convert an output function value as a dictionary.

Inherited Common Usage

dims#
values#
coords#
output_names#
fn_source#
task_names#
task_paths#
aux_values#
optimizer#
value_as_dict(value)[source]#

How to convert an output function value as a dictionary.

static default_value_keys(value)[source]#

The default keys for a given value.

items()[source]#

Iterate through coordinates (args) and values (outputs) one by one.

property data#

Dict mapping tuple of fn args to their value.

get_value(coords)[source]#

Get a data element indexing by function arg tuple.

sel(**kwargs)[source]#

Get a data element by function kwargs..

to_dataframe(include_aux=False)[source]#

Data as a pandas.DataFrame.

Output a pandas.DataFrame of the Result. Can include auxiliary data if include_aux is True and auxiliary data is found in the Result. If auxiliary data is in a dictionary the keys will be used as column names, otherwise they will be labeled aux_key_X for X auxiliary columns.

Parameters:

include_aux (bool = False) – Toggle to include auxiliary values in the dataframe. Requires auxiliary values in the Result.

Returns:

pandas.DataFrame corresponding to the Result.

Return type:

pandas.DataFrame

classmethod from_dataframe(df, dims=None)[source]#

Load a result directly from a pandas.DataFrame object.

Parameters:
  • df (pandas.DataFrame) – `DataFrame object to load into a Result.

  • dims (List[str] = None) – Set of dimensions corresponding to the function arguments. Not required if this dataframe was generated directly from a Result without modification. In that case, it contains the dims in its .attrs metadata.

Returns:

Result loaded from this DataFrame.

Return type:

Result

combine(other)[source]#

Combine data from two results into a new result (also works with β€˜+’).

Parameters:

other (Result) – Results to combine with this object.

Returns:

Combined Result

Return type:

Result

__add__(other)[source]#

Special syntax for design_result1 + design_result2.

get_index(fn_args)[source]#

Get index into the data for a specific set of arguments.

delete(fn_args)[source]#

Delete a specific set of arguments from the result.

Parameters:

fn_args (Dict[str, float]) – dict containing the function arguments one wishes to delete.

Returns:

Copy of the result with that element removed.

Return type:

Result

add(fn_args, value)[source]#

Add a specific argument and value the result.

Parameters:
  • fn_args (Dict[str, float]) – dict containing the function arguments one wishes to add.

  • value (Any) – Data point value corresponding to these arguments.

Returns:

Copy of the result with that element added.

Return type:

Result

__len__()[source]#

Implement len function to return the number of items in the result.

__getitem__(data_index)[source]#

Implement the accessor function to index into the coordinates and values of the result.

__hash__()#

Hash method.