Tidy3DModel¶
- class photonforge.Tidy3DModel(run_time=None, medium=None, symmetry=(0, 0, 0), boundary_spec=None, monitors=(), structures=(), grid_spec=None, shutoff=None, subpixel=None, courant=None, port_symmetries=(), bounds=((None, None, None), (None, None, None)), source_gap=None, simulation_updates={}, verbose=True)[source]¶
S matrix model based on Tidy3D FDTD calculation.
- Parameters:
run_time (RunTimeSpec | float | None) – Maximal simulation run-time (in seconds) or an instance of
tidy3d.RuntImeSpec.medium (Medium | AnisotropicMedium | PECMedium | PoleResidue | Sellmeier | Lorentz | Debye | Drude | FullyAnisotropicMedium | CustomMedium | CustomPoleResidue | CustomSellmeier | CustomLorentz | CustomDebye | CustomDrude | CustomAnisotropicMedium | PerturbationMedium | PerturbationPoleResidue | LossyMetalMedium | None) – Background medium. If
None, the technology default is used.symmetry (Sequence[int]) – Component symmetries.
boundary_spec (BoundarySpec | None) – Simulation boundary specifications (absorber by default).
monitors (Sequence[FieldMonitor | FieldTimeMonitor | AuxFieldTimeMonitor | PermittivityMonitor | FluxMonitor | FluxTimeMonitor | ModeMonitor | ModeSolverMonitor | FieldProjectionAngleMonitor | FieldProjectionCartesianMonitor | FieldProjectionKSpaceMonitor | DiffractionMonitor | DirectivityMonitor]) – Extra field monitors added to the simulation.
structures (Sequence[Structure]) – Additional structures included in the simulations.
grid_spec (float | GridSpec | None) – Simulation grid specification. A single float can be used to specify the
min_steps_per_wvlfor an auto grid.shutoff (float | None) – Field decay factor for simulation termination.
subpixel (SubpixelSpec | bool | None) – Flag controlling subpixel averaging in the simulation grid or an instance of
tidy3d.SubpixelSpec.courant (float | None) – Courant stability factor.
port_symmetries (Sequence[Sequence[str, str, dict[str, str]]] | Sequence[Sequence[str | int]] | Sequence[Sequence[Sequence[str, str], Sequence[str, str], float | ndarray]]) – Port symmetries to reduce the number of simulation runs. See note below.
bounds (Sequence[Sequence[float | None]]) – Bound overrides for the final simulation in the form
((xmin, ymin, zmin), (xmax, ymax, zmax)). Values set toNoneare ignored.source_gap (float | None) – Separation between source and monitor representing a component port. Defaults to 2 grid cells for optical simulations and 1% of the maximum wavelength for electrical ones. The defaults are used when this is unset or set to 0.
simulation_updates (dict[str, Any]) – Dictionary of updates applied to all simulations generated by this model. See example below.
verbose (bool) – Control solver verbosity.
If not set, the default grid specification for the component simulations is defined based on the wavelengths used in the
s_matrixcall. Defaults forrun_time,boundary_spec,shutoff,subpixel,courant, andsource_gapcan be defined in a"tidy3d"dictionary inconfig.default_kwargs. Note that the values used are the ones available at the time of thes_matrixorstartcall, not when model is initialized.The
startmethod accepts aninputsargument as a sequence or set of port names to limit the computation to those inputs. Instead of port names,{port}@{mode}specifications are also accepted.Note
Each item in the
port_symmetriessequence is a tuple of port names indicating the port replacements that do not affect the S matrix computation. Usually, that means each item is a permutation of the sorted list of component ports.For example, in a Y junction with input “P0” and outputs “P1” and “P2” operating in the fundamental TE mode, we can exchange ports “P1” and “P2” and the S matrix remains the same, because S₁₀ = S₂₀ and S₁₁ = S₂₂. This symmetry is represented as the sequence
("P0", "P2", "P1"), which exchange “P1” anf “P2” with respect to the sorted port list “P0”, “P1”, “P2”. We could also use indices instead of port names to the same effect:(0, 2, 1).It is also possible to represent S matrix symmetries for individual elements and with correction factors. This form requires a reference element, a mapped element, and a multiplication factor:
((src, dst1), (src2, dst2), c), which translates intoS[src2@i, dst2@j] = c[i,j] * S[src1@i, dst1@j]for all mode indicesiandjsupported by the source and destination ports, respectively. Note that the multiplicative factor is an array so that each mode can be phase-compensated according to its field symmetry (ifcis an scalar, all modes use the same value).Example
Keys in
simulation_updatesspecify a path to the value that will be updated using a'/'as separator, analagously to thepathargument in theupdated_copymethod fromtidy3dobjects. For indexing into a tuple or list, an integer value is used.>>> simulation_updates = { ... "grid_spec/grid_x/max_scale": 1.3, ... "boundary_spec/z/plus": td.PML(), ... "center/2": 0.0, ... } >>> model = pf.Tidy3DModel(simulation_updates=simulation_updates)
See also
Methods
batch_data_for(component)Return the Tidy3D
BatchDatafor a given component.batch_file_for(component)Return the file used to store the Tidy3D
BatchDatafor a component.data_path_for(component)Return the path for the cached data for a component.
estimate_cost(component, frequencies, *[, ...])Estimate the cost of the S matrix computation.
from_bytes(byte_repr)De-serialize this model.
get_simulations(component, frequencies[, ...])Return all simulations required by this component.
s_matrix(component, frequencies[, ...])Compute the S matrix for a component using this model.
start(component, frequencies, *[, inputs, ...])Start computing the S matrix response from a component.
test_port_symmetries(component, frequencies)Test this models port symmetries with a component.
update(*args, **kwargs)Update this model.
Attributes
Serialize this model.
parametric_functionFunction used to update a parametric component.
parametric_kwargsKeyword arguments used to update a parametric component.
propertiesObject properties.
random_variablesRandom variables associated to this modles's parameters.
- property as_bytes: bytes¶
Serialize this model.
- batch_data_for(component)[source]¶
Return the Tidy3D
BatchDatafor a given component.- Parameters:
component (Component)
- Return type:
Any | None
- batch_file_for(component)[source]¶
Return the file used to store the Tidy3D
BatchDatafor a component.- Parameters:
component (Component)
- Return type:
Path
- data_path_for(component)[source]¶
Return the path for the cached data for a component.
- Parameters:
component (Component)
- Return type:
Path
- estimate_cost(component, frequencies, *, inputs=(), verbose=None)[source]¶
Estimate the cost of the S matrix computation.
The estimation ignores any cached data.
- Parameters:
component (Component) – Component from which to compute the S matrix.
frequencies (Sequence[float]) – Sequence of frequencies at which to perform the computation.
inputs (Sequence[str]) – Limit calculation to specific inputs. Each item must be a port name or a
{port}@{mode}specification.verbose (bool | None) – If set, overrides the model’s verbose attribute.
- Returns:
Estimated computation cost.
- Return type:
float
Important
When using geometry symmetry, the mode numbering in
inputsis relative to the solver run with the symmetry applied, not the mode number presented in the final S matrix.
- classmethod from_bytes(byte_repr)[source]¶
De-serialize this model.
- Parameters:
byte_repr (bytes)
- Return type:
- get_simulations(component, frequencies, sources=())[source]¶
Return all simulations required by this component.
- Parameters:
component (Component) – Instance of Component for calculation.
frequencies (Sequence[float]) – Sequence of frequencies for the simulation.
sources (Sequence[str]) – Port names to be used as sources (
{port}@{mode}specifications are also accepted). If empty, use all required sources based on this model’s port symmetries.
- Returns:
Dictionary of
tidy3d.Simulationindexed by source name or a single simulation if the component has no ports.- Return type:
dict[str, Simulation] | Simulation
- start(component, frequencies, *, inputs=(), verbose=None, **kwargs)[source]¶
Start computing the S matrix response from a component.
- Parameters:
component (Component) – Component from which to compute the S matrix.
frequencies (Sequence[float]) – Sequence of frequencies at which to perform the computation.
inputs (Sequence[str]) – Limit calculation to specific inputs. Each item must be a port name or a
{port}@{mode}specification.verbose (bool | None) – If set, overrides the model’s verbose attribute.
**kwargs (Any) – Unused.
- Returns:
Result object with attributes
statusands_matrix.- Return type:
_Tidy3DModelRunner
Important
When using geometry symmetry, the mode numbering in
inputsis relative to the solver run with the symmetry applied, not the mode number presented in the final S matrix.
- test_port_symmetries(component, frequencies, plot_error=True, atol=0.02, **kwargs)[source]¶
Test this models port symmetries with a component.
Effectively executes all simulations required without symmetries and compares with the symmetry setting.
- Parameters:
component (Component) – Component to test.
frequencies (Sequence[float]) – Frequencies to use during the test.
plot_error (bool) – Create a plot for elements with symmetry errors.
atol (float) – Absolute tolerance when comparing results.
**kwargs (Any) – Arguments to replace in the model during the test.
- Returns:
Boolean indicating whether the symmetries for all Tidy3D models in the component are correct.
- Return type:
bool