tidy3d.plugins.design.Result#
- class Result[source]#
Bases:
Tidy3dBaseModel
Stores the result of a run over a
DesignSpace
. Can be converted topandas.DataFrame
withResult.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 anattr
obj.attrs['foo'] = bar
. Also note that Tidy3D` will raise aTypeError
ifattrs
contain objects that can not be serialized. One can check ifattrs
are serializable by callingobj.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 thelen(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 isNone
. 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 downloadSimulationData
hdf5 files.Only available if the parameter sweep function is split into pre and post processing, otherwise isNone
. 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
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#
- property data#
Dict mapping tuple of fn args to their value.
- to_dataframe(include_aux=False)[source]#
Data as a
pandas.DataFrame
.Output a
pandas.DataFrame
of theResult
. Can include auxiliary data ifinclude_aux
isTrue
and auxiliary data is found in theResult
. If auxiliary data is in a dictionary the keys will be used as column names, otherwise they will be labeledaux_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 theResult
.- 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 aResult
.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:
- 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:
- 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:
- __getitem__(data_index)[source]#
Implement the accessor function to index into the coordinates and values of the result.
- __hash__()#
Hash method.