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_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, seebatch_data
.batch_data (Optional[BatchData] = None) โ
BatchData
object storing all of the data for the simulations used in thisResult
. Can be iterated through like a dictionary withfor 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 isNone
.
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..
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#
- property data#
Dict mapping tuple of fn args to their value.
- to_dataframe()[source]#
Data as a pandas.DataFrame.
- 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:
- __hash__()#
Hash method.