tidy3d.components.base.Tidy3dBaseModel#

class tidy3d.components.base.Tidy3dBaseModel#

Base pydantic model that all Tidy3d components inherit from. Defines configuration for handling data structures as well as methods for imporing, exporting, and hashing tidy3d objects. For more details on pydantic base models, see: Pydantic Models

Show JSON schema
{
   "title": "Tidy3dBaseModel",
   "description": "Base pydantic model that all Tidy3d components inherit from.\nDefines configuration for handling data structures\nas well as methods for imporing, exporting, and hashing tidy3d objects.\nFor more details on pydantic base models, see:\n`Pydantic Models <https://pydantic-docs.helpmanual.io/usage/models/>`_",
   "type": "object",
   "properties": {},
   "additionalProperties": false
}

add_to_handle(hdf5_group: h5py._hl.group.Group) None#

Saves a Tidy3dBaesModel instance to an hdf5 group,

Parameters

hdf5_group (h5py.Group) – The hdf5 group containing data correponding to the dict() of the object.

classmethod add_type_field() None#

Automatically place “type” field with model name in the model field dictionary.

copy(validate: bool = True, **kwargs) tidy3d.components.base.Tidy3dBaseModel#

Copy a Tidy3dBaseModel. With deep=True as default.

classmethod dump_hdf5(data_dict: dict, fname: str) None#

Writes a dictionary of data into an hdf5 file.

Parameters
  • data_dict (dict) – A dictionary of data with strings or tuples as keys and data or other dicts as values.

  • fname (str) – path to the .hdf5 file.

classmethod from_file(fname: str, **parse_kwargs) tidy3d.components.base.Tidy3dBaseModel#

Loads a Tidy3dBaseModel from .yaml, .json, or .hdf5 file.

Parameters
  • fname (str) – Full path to the .yaml or .json file to load the Tidy3dBaseModel from.

  • **parse_kwargs – Keyword arguments passed to either pydantic’s parse_file or parse_raw methods for .json and .yaml file formats, respectively.

Returns

An instance of the component class calling load.

Return type

Tidy3dBaseModel

Example

>>> simulation = Simulation.from_file(fname='folder/sim.json') 
classmethod from_hdf5(fname: str, **parse_raw_kwargs) tidy3d.components.base.Tidy3dBaseModel#

Loads Tidy3dBaseModel from .yaml file.

Parameters
  • fname (str) – Full path to the .hdf5 file to load the Tidy3dBaseModel from.

  • **parse_raw_kwargs – Keyword arguments passed to pydantic’s parse_raw method.

Returns

An instance of the component class calling from_hdf5.

Return type

Tidy3dBaseModel

Example

>>> simulation = Simulation.from_hdf5(fname='folder/sim.hdf5') 
classmethod from_json(fname: str, **parse_file_kwargs) tidy3d.components.base.Tidy3dBaseModel#

Load a Tidy3dBaseModel from .json file.

Parameters

fname (str) – Full path to the .json file to load the Tidy3dBaseModel from.

Returns

  • Tidy3dBaseModel – An instance of the component class calling load.

  • **parse_file_kwargs – Keyword arguments passed to pydantic’s parse_file method.

Example

>>> simulation = Simulation.from_json(fname='folder/sim.json') 
classmethod from_yaml(fname: str, **parse_raw_kwargs) tidy3d.components.base.Tidy3dBaseModel#

Loads Tidy3dBaseModel from .yaml file.

Parameters
  • fname (str) – Full path to the .yaml file to load the Tidy3dBaseModel from.

  • **parse_raw_kwargs – Keyword arguments passed to pydantic’s parse_raw method.

Returns

An instance of the component class calling from_yaml.

Return type

Tidy3dBaseModel

Example

>>> simulation = Simulation.from_yaml(fname='folder/sim.yaml') 
classmethod generate_docstring() str#

Generates a docstring for a Tidy3D mode and saves it to the __doc__ of the class.

classmethod hdf5_to_dict(fname: str) dict#

Load an hdf5 file into a dictionary storing its unpacked contents.

Parameters

fname (str) – Path to the hdf5 file.

Returns

The dictionary containing all group names as keys and datasets as values.

Return type

dict

help(methods: bool = False) None#

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 load_from_handle(hdf5_group: h5py._hl.group.Group, **kwargs) tidy3d.components.base.Tidy3dBaseModel#

Loads an instance of the class from an hdf5 group,

Parameters
  • hdf5_group (h5py.Group) – The hdf5 group containing data correponding to the dict() of the object.

  • kwargs (dict) – Keyword arguments passed to pydantic.BaseModel.parse_obj

Return type

Tidy3dBaseModel

classmethod load_without_validation(**values) tidy3d.components.base.Tidy3dBaseModel#

Creates a new model setting from trusted or pre-validated data.

Parameters

**values – The fields and values of the model as keyword arguments.

static pack_dataset(hdf5_group: h5py._hl.group.Group, key: str, value: Any) None#

Loads a key value pair as a dataset in the hdf5 group.

to_file(fname: str, data_file: Optional[str] = None) None#

Exports Tidy3dBaseModel instance to .yaml, .json, or .hdf5 file

Parameters
  • fname (str) – Full path to the .yaml or .json file to save the Tidy3dBaseModel to.

  • data_file (str = None) – Path to a separate hdf5 file to write DataArray objects to.

Example

>>> simulation.to_file(fname='folder/sim.json') 
to_hdf5(fname: str) None#

Exports Tidy3dBaseModel instance to .hdf5 file.

Parameters

fname (str) – Full path to the .hdf5 file to save the Tidy3dBaseModel to.

Example

>>> simulation.to_hdf5(fname='folder/sim.hdf5') 
to_json(fname: str, data_file: Optional[str] = None) None#

Exports Tidy3dBaseModel instance to .json file

Parameters
  • fname (str) – Full path to the .json file to save the Tidy3dBaseModel to.

  • data_file (str = None) – Path to a separate hdf5 file to write DataArray objects to.

Example

>>> simulation.to_json(fname='folder/sim.json') 
to_yaml(fname: str, data_file: Optional[str] = None) None#

Exports Tidy3dBaseModel instance to .yaml file.

Parameters
  • fname (str) – Full path to the .yaml file to save the Tidy3dBaseModel to.

  • data_file (str = None) – Path to a separate hdf5 file to write DataArray objects to.

Example

>>> simulation.to_yaml(fname='folder/sim.yaml') 
static unpack_dataset(dataset: h5py._hl.dataset.Dataset, keep_numpy: bool = False) Any#

Gets the value contained in a dataset in a form ready to insert into final dict.

Parameters
  • item (h5py.Dataset) – The raw value coming from the dataset, which needs to be decoded.

  • keep_numpy (bool = False) – Whether to load a np.ndarray as such or convert it to list.

Return type

Value taken from the dataset ready to insert into returned dict.