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 (Annotated[Medium | AnisotropicMedium | PECMedium | PMCMedium | 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 (Annotated[Sequence[int], _]) – Component symmetries.
boundary_spec (BoundarySpec | None) – Simulation boundary specifications (absorber by default).
monitors (Sequence[Annotated[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 (Annotated[float, exclusiveMinimum=0] | GridSpec | None) – Simulation grid specification. A single float can be used to specify the
min_steps_per_wvlfor an auto grid.shutoff (Annotated[float, exclusiveMinimum=0] | 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 (Annotated[float, maximum=1, minimum=0] | None) – Courant stability factor.
port_symmetries (Sequence[Annotated[Sequence[str, str, dict[str, str]], _]] | Sequence[Annotated[Sequence[str | int], _]] | Sequence[Annotated[Sequence[Sequence[str, str], Sequence[str, str], complex | Sequence[Sequence[complex]]], _]]) – Port symmetries to reduce the number of simulation runs. See note below.
bounds (Annotated[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 (Annotated[float, minimum=0] | 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, analogously to thepathargument in theupdated_copymethod fromtidy3dobjects. For indexing into a tuple or list, an integer value is used. The first part of the path can be an input in the formport@modeto specify that the update should be applied to a that simulation only.>>> simulation_updates = { ... "P0@0/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(component, frequencies, *[, ...])Return the Tidy3D BatchData for a given component.
batch_data_for(component, *[, _skip_warning])DEPRECATED: Use Tidy3DModel.batch_data.
batch_file_for(component, *[, _skip_warning])DEPRECATED: Use Tidy3DModel.batch_data.
data_path_for(component, *[, _skip_warning])DEPRECATED: Use Tidy3DModel.batch_data.
estimate_cost(*args, **kwargs)Estimate the cost for 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.
setup_time_stepper(component, time_step[, ...])Obtain a time stepper 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
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.
time_stepperTime stepper associated with this model.
- batch_data(component, frequencies, *, inputs=(), verbose=None, show_progress=True, **kwargs)[source]¶
Return the Tidy3D BatchData for a given component.
Uses the same arguments as
Tidy3DModel.start().- Parameters:
component (Component)
frequencies (Sequence[float])
inputs (Sequence[str])
verbose (bool | None)
show_progress (bool)
kwargs (Any)
- batch_data_for(component, *, _skip_warning=False)[source]¶
DEPRECATED: Use Tidy3DModel.batch_data.
- Parameters:
component (Component)
- Return type:
Any | None
- batch_file_for(component, *, _skip_warning=False)[source]¶
DEPRECATED: Use Tidy3DModel.batch_data.
- Parameters:
component (Component)
- Return type:
Path
- data_path_for(component, *, _skip_warning=False)[source]¶
DEPRECATED: Use Tidy3DModel.batch_data.
- Parameters:
component (Component)
- Return type:
Path
- 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, cost_estimation=False, **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.
cost_estimation (bool) – If set, simulations are uploaded, but not executed. S matrix will not be computed.
**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