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_ids (Optional[Tuple[Tuple[str, ...], ...]] = None) โ€“ Task IDs for the simulation run in each data point. Only available if the parameter sweep function is split into pre and post processing and run with โ€˜Design.run_batch()โ€™, otherwise is None. To access all of the data, see batch_data.

  • batch_data (Optional[BatchData] = None) โ€“ BatchData object storing all of the data for the simulations used in this Result. Can be iterated through like a dictionary with for task_name, sim_data in batch_data.items(). Only available if the parameter sweep function is split into pre and post processing and run with โ€˜Design.run_batch()โ€™, otherwise is None.

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

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_ids#
batch_data#
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()[source]#

Data as a pandas.DataFrame.

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

__hash__()#

Hash method.