tidy3d.components.base.Tidy3dBaseModel#
- class Tidy3dBaseModel[source]#
Bases:
BaseModelBase pydantic model that all Tidy3d components inherit from. Defines configuration for handling data structures as well as methods for importing, exporting, and hashing tidy3d objects. For more details on pydantic base models, see: Pydantic Models
Attributes
Methods
__init__(**kwargs)Init method, includes post-init validators.
Automatically place "type" field with model name in the model field dictionary.
copy([deep, validate])Copy a Tidy3dBaseModel.
dict_from_file(fname[, group_path])Loads a dictionary containing the model from a .yaml, .json, .hdf5, or .hdf5.gz file.
dict_from_hdf5(fname[, group_path, ...])Loads a dictionary containing the model contents from a .hdf5 file.
dict_from_hdf5_gz(fname[, group_path, ...])Loads a dictionary containing the model contents from a .hdf5.gz file.
dict_from_json(fname)Load dictionary of the model from a .json file.
dict_from_yaml(fname)Load dictionary of the model from a .yaml file.
from_file(fname[, group_path])Loads a
Tidy3dBaseModelfrom .yaml, .json, .hdf5, or .hdf5.gz file.from_hdf5(fname[, group_path, custom_decoders])Loads
Tidy3dBaseModelinstance to .hdf5 file.from_hdf5_gz(fname[, group_path, ...])Loads
Tidy3dBaseModelinstance to .hdf5.gz file.from_json(fname, **parse_obj_kwargs)Load a
Tidy3dBaseModelfrom .json file.from_yaml(fname, **parse_obj_kwargs)Loads
Tidy3dBaseModelfrom .yaml file.Generates a docstring for a Tidy3D mode and saves it to the __doc__ of the class.
get_sub_model(group_path, model_dict)Get the sub model for a given group path.
Return a dictionary of this object's sub-models indexed by their hash values.
get_tuple_group_name(index)Get the group name of a tuple element.
get_tuple_index(key_name)Get the index into the tuple based on its group name.
help([methods])Prints message describing the fields and methods of a
Tidy3dBaseModel.to_file(fname)Exports
Tidy3dBaseModelinstance to .yaml, .json, or .hdf5 fileto_hdf5(fname[, custom_encoders])Exports
Tidy3dBaseModelinstance to .hdf5 file.to_hdf5_gz(fname[, custom_encoders])Exports
Tidy3dBaseModelinstance to .hdf5.gz file.to_json(fname)Exports
Tidy3dBaseModelinstance to .json fileVersion of object with all autograd-traced fields removed.
to_yaml(fname)Exports
Tidy3dBaseModelinstance to .yaml file.tuple_to_dict(tuple_values)How we generate a dictionary mapping new keys to tuple values for hdf5.
updated_copy([path, deep, validate])Make copy of a component instance with
**kwargsindicating updated field values.Inherited Common Usage
- class Config[source]#
Bases:
objectSets config for all
Tidy3dBaseModelobjects.Configuration Options#
- allow_population_by_field_namebool = True
Allow properties to stand in for fields(?).
- arbitrary_types_allowedbool = True
Allow types like numpy arrays.
- extrastr = ‘forbid’
Forbid extra kwargs not specified in model.
- json_encodersDict[type, Callable]
Defines how to encode type in json file.
- validate_allbool = True
Validate default values just to be safe.
- validate_assignmentbool
Re-validate after re-assignment of field in model.
- arbitrary_types_allowed = True#
- validate_all = True#
- extra = 'forbid'#
- validate_assignment = True#
- allow_population_by_field_name = True#
- json_encoders = {<class 'autograd.tracer.Box'>: <function Tidy3dBaseModel.Config.<lambda>>, <class 'complex'>: <function Tidy3dBaseModel.Config.<lambda>>, <class 'numpy.ndarray'>: <function ndarray_encoder>, <class 'xarray.core.dataarray.DataArray'>: <bound method DataArray._json_encoder of <class 'tidy3d.components.data.data_array.DataArray'>>}#
- frozen = True#
- allow_mutation = False#
- copy_on_model_validation = 'none'#
- attrs#
- copy(deep=True, validate=True, **kwargs)[source]#
Copy a Tidy3dBaseModel. With
deep=Trueandvalidate=Trueas default.
- updated_copy(path=None, deep=True, validate=True, **kwargs)[source]#
Make copy of a component instance with
**kwargsindicating updated field values.Note
If
pathsupplied, applies the updated copy with the update performed on the sub- component corresponding to the path. For indexing into a tuple or list, use the integer value.Example
>>> sim = simulation.updated_copy(size=new_size, path=f"structures/{i}/geometry")
- help(methods=False)[source]#
Prints message describing the fields and methods of a
Tidy3dBaseModel.- Parameters:
methods (bool = False) – Whether to also print out information about object’s methods.
Example
>>> simulation.help(methods=True)
- classmethod from_file(fname, group_path=None, **parse_obj_kwargs)[source]#
Loads a
Tidy3dBaseModelfrom .yaml, .json, .hdf5, or .hdf5.gz file.- Parameters:
fname (str) – Full path to the file to load the
Tidy3dBaseModelfrom.group_path (str, optional) – Path to a group inside the file to use as the base level. Only for hdf5 files. Starting / is optional.
**parse_obj_kwargs – Keyword arguments passed to either pydantic’s
parse_objfunction when loading model.
- Returns:
An instance of the component class calling
load.- Return type:
Example
>>> simulation = Simulation.from_file(fname='folder/sim.json')
- classmethod dict_from_file(fname, group_path=None)[source]#
Loads a dictionary containing the model from a .yaml, .json, .hdf5, or .hdf5.gz file.
- Parameters:
fname (str) – Full path to the file to load the
Tidy3dBaseModelfrom.group_path (str, optional) – Path to a group inside the file to use as the base level.
- Returns:
A dictionary containing the model.
- Return type:
dict
Example
>>> simulation = Simulation.from_file(fname='folder/sim.json')
- to_file(fname)[source]#
Exports
Tidy3dBaseModelinstance to .yaml, .json, or .hdf5 file- Parameters:
fname (str) – Full path to the .yaml or .json file to save the
Tidy3dBaseModelto.
Example
>>> simulation.to_file(fname='folder/sim.json')
- classmethod from_json(fname, **parse_obj_kwargs)[source]#
Load a
Tidy3dBaseModelfrom .json file.- Parameters:
fname (str) – Full path to the .json file to load the
Tidy3dBaseModelfrom.- Returns:
Tidy3dBaseModel– An instance of the component class calling load.**parse_obj_kwargs – Keyword arguments passed to pydantic’s
parse_objmethod.
Example
>>> simulation = Simulation.from_json(fname='folder/sim.json')
- classmethod dict_from_json(fname)[source]#
Load dictionary of the model from a .json file.
- Parameters:
fname (str) – Full path to the .json file to load the
Tidy3dBaseModelfrom.- Returns:
A dictionary containing the model.
- Return type:
dict
Example
>>> sim_dict = Simulation.dict_from_json(fname='folder/sim.json')
- to_json(fname)[source]#
Exports
Tidy3dBaseModelinstance to .json file- Parameters:
fname (str) – Full path to the .json file to save the
Tidy3dBaseModelto.
Example
>>> simulation.to_json(fname='folder/sim.json')
- classmethod from_yaml(fname, **parse_obj_kwargs)[source]#
Loads
Tidy3dBaseModelfrom .yaml file.- Parameters:
fname (str) – Full path to the .yaml file to load the
Tidy3dBaseModelfrom.**parse_obj_kwargs – Keyword arguments passed to pydantic’s
parse_objmethod.
- Returns:
An instance of the component class calling from_yaml.
- Return type:
Example
>>> simulation = Simulation.from_yaml(fname='folder/sim.yaml')
- classmethod dict_from_yaml(fname)[source]#
Load dictionary of the model from a .yaml file.
- Parameters:
fname (str) – Full path to the .yaml file to load the
Tidy3dBaseModelfrom.- Returns:
A dictionary containing the model.
- Return type:
dict
Example
>>> sim_dict = Simulation.dict_from_yaml(fname='folder/sim.yaml')
- to_yaml(fname)[source]#
Exports
Tidy3dBaseModelinstance to .yaml file.- Parameters:
fname (str) – Full path to the .yaml file to save the
Tidy3dBaseModelto.
Example
>>> simulation.to_yaml(fname='folder/sim.yaml')
- classmethod tuple_to_dict(tuple_values)[source]#
How we generate a dictionary mapping new keys to tuple values for hdf5.
- classmethod get_sub_model(group_path, model_dict)[source]#
Get the sub model for a given group path.
- classmethod dict_from_hdf5(fname, group_path='', custom_decoders=None)[source]#
Loads a dictionary containing the model contents from a .hdf5 file.
- Parameters:
fname (str) – Full path to the .hdf5 file to load the
Tidy3dBaseModelfrom.group_path (str, optional) – Path to a group inside the file to selectively load a sub-element of the model only.
custom_decoders (List[Callable]) – List of functions accepting (fname: str, group_path: str, model_dict: dict, key: str, value: Any) that store the value in the model dict after a custom decoding.
- Returns:
Dictionary containing the model.
- Return type:
dict
Example
>>> sim_dict = Simulation.dict_from_hdf5(fname='folder/sim.hdf5')
- classmethod from_hdf5(fname, group_path='', custom_decoders=None, **parse_obj_kwargs)[source]#
Loads
Tidy3dBaseModelinstance to .hdf5 file.- Parameters:
fname (str) – Full path to the .hdf5 file to load the
Tidy3dBaseModelfrom.group_path (str, optional) – Path to a group inside the file to selectively load a sub-element of the model only. Starting / is optional.
custom_decoders (List[Callable]) – List of functions accepting (fname: str, group_path: str, model_dict: dict, key: str, value: Any) that store the value in the model dict after a custom decoding.
**parse_obj_kwargs – Keyword arguments passed to pydantic’s
parse_objmethod.
Example
>>> simulation = Simulation.from_hdf5(fname='folder/sim.hdf5')
- to_hdf5(fname, custom_encoders=None)[source]#
Exports
Tidy3dBaseModelinstance to .hdf5 file.- Parameters:
fname (str) – Full path to the .hdf5 file to save the
Tidy3dBaseModelto.custom_encoders (List[Callable]) – List of functions accepting (fname: str, group_path: str, value: Any) that take the
valuesupplied and write it to the hdf5fnameatgroup_path.
Example
>>> simulation.to_hdf5(fname='folder/sim.hdf5')
- classmethod dict_from_hdf5_gz(fname, group_path='', custom_decoders=None)[source]#
Loads a dictionary containing the model contents from a .hdf5.gz file.
- Parameters:
fname (str) – Full path to the .hdf5.gz file to load the
Tidy3dBaseModelfrom.group_path (str, optional) – Path to a group inside the file to selectively load a sub-element of the model only.
custom_decoders (List[Callable]) – List of functions accepting (fname: str, group_path: str, model_dict: dict, key: str, value: Any) that store the value in the model dict after a custom decoding.
- Returns:
Dictionary containing the model.
- Return type:
dict
Example
>>> sim_dict = Simulation.dict_from_hdf5(fname='folder/sim.hdf5.gz')
- classmethod from_hdf5_gz(fname, group_path='', custom_decoders=None, **parse_obj_kwargs)[source]#
Loads
Tidy3dBaseModelinstance to .hdf5.gz file.- Parameters:
fname (str) – Full path to the .hdf5.gz file to load the
Tidy3dBaseModelfrom.group_path (str, optional) – Path to a group inside the file to selectively load a sub-element of the model only. Starting / is optional.
custom_decoders (List[Callable]) – List of functions accepting (fname: str, group_path: str, model_dict: dict, key: str, value: Any) that store the value in the model dict after a custom decoding.
**parse_obj_kwargs – Keyword arguments passed to pydantic’s
parse_objmethod.
Example
>>> simulation = Simulation.from_hdf5_gz(fname='folder/sim.hdf5.gz')
- to_hdf5_gz(fname, custom_encoders=None)[source]#
Exports
Tidy3dBaseModelinstance to .hdf5.gz file.- Parameters:
fname (str) – Full path to the .hdf5.gz file to save the
Tidy3dBaseModelto.custom_encoders (List[Callable]) – List of functions accepting (fname: str, group_path: str, value: Any) that take the
valuesupplied and write it to the hdf5fnameatgroup_path.
Example
>>> simulation.to_hdf5_gz(fname='folder/sim.hdf5.gz')
- classmethod add_type_field()[source]#
Automatically place “type” field with model name in the model field dictionary.