-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tidy3d pluging to allow for symmetries #268
Comments
yes, it would be great to add it Also it would be to get support directly from tidy3d team to review support and improve this plugin :) |
Pascual, can you |
Dear all, I just run the very same script above and now the output to the very last command (having symmetries) is:
|
Your mode source and monitors |
Hi, I run the simulation now with: sp = gt.write_sparameters(
component = sw_test,
layer_stack = LAYER_STACK,
material_mapping = md,
symmetry = (0,-1,0),
) and the result error is exactly the same for the source and monitor. Having a closer look to the y coordinate for both (see above) is 2.816687638038912e-16 ... which to me is zero but, is it for tidy3d? Best. |
Hm, maybe @momchil-flex can comment on the numerical precision handling for symmetry. |
Hi all, so as far as I can see there are two separate issues here:
|
Another point is perhaps that in general, for essentially all components that are not straight waveguides or tapers, symmetries (other than z) are tricky to handle. For example, a 1x2 splitter could exploit a mirror plane only for the simulation of |
Hi, thanks @yaugenst for the comments. I agree it makes little sense for automatic centering at z = 0, and apologies for this not being there but at z = 0.11 µm, it comes from some other example. For the case then z-symmetry doesn't make any sense, so my apologies once more. |
All, in my quest to save time-money on simulations, I have read the tidy3d documentation on S-parameters: https://www.flexcompute.com/tidy3d/examples/notebooks/SMatrix/ With slight modifications in the example above: inp = ("o1", 0)
out = ("o2", 0)
c_ii = (inp, inp)
c_io = (inp, out)
c_oi = (out, inp)
c_oo = (out, out)
map_xx = (c_ii, c_oo, +1)
map_xy = (c_io, c_oi, +1)
element_mappings = (map_xx, map_xy)
sp_port_sym_em_ro = gt.write_sparameters(
component = sw_test,
layer_stack = LAYER_STACK,
material_mapping = md,
symmetry = (0,-1,0),
element_mappings=element_mappings,
run_only = ( inp, )
) I was able to reduce the use of FlexCredits (computation time is equivalent to the same without "element_mappings" and without "run_only" though). However the call to write_sparameters does not end, and the output is the following: 17:30:45 CET loading simulation from
/Users/pascual/.gdsfactory/sparameters/8b77f32deba9d3328164504fcffc
774fd72de6843311afd6799ea80caea23a14/fdve-fd324b19-8d0b-451d-9430-5
b7b93ab5d12.hdf5
{
"name": "KeyError",
"message": "\"not all values found in index 'port_in'. Try setting the `method` keyword argument (example: method='nearest').\"",
"stack": "---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File ~/anaconda3/lib/python3.11/site-packages/pandas/core/indexes/base.py:3790, in Index.get_loc(self, key)
3789 try:
-> 3790 return self._engine.get_loc(casted_key)
3791 except KeyError as err:
File index.pyx:152, in pandas._libs.index.IndexEngine.get_loc()
File index.pyx:181, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:7080, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:7088, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'o2'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
File ~/anaconda3/lib/python3.11/site-packages/xarray/core/indexes.py:486, in PandasIndex.sel(self, labels, method, tolerance)
485 try:
--> 486 indexer = self.index.get_loc(label_value)
487 except KeyError as e:
File ~/anaconda3/lib/python3.11/site-packages/pandas/core/indexes/base.py:3797, in Index.get_loc(self, key)
3796 raise InvalidIndexError(key)
-> 3797 raise KeyError(key) from err
3798 except TypeError:
3799 # If we have a listlike key, _check_indexing_error will raise
3800 # InvalidIndexError. Otherwise we fall through and re-raise
3801 # the TypeError.
KeyError: 'o2'
The above exception was the direct cause of the following exception:
[... omitted ...]
File ~/anaconda3/lib/python3.11/site-packages/gplugins/tidy3d/component.py:606, in write_sparameters(component, layer_stack, material_mapping, extend_ports, port_offset, pad_xy_inner, pad_xy_outer, pad_z_inner, pad_z_outer, dilation, wavelength, bandwidth, num_freqs, min_steps_per_wvl, center_z, sim_size_z, port_size_mult, run_only, element_mappings, extra_monitors, mode_spec, boundary_spec, symmetry, run_time, shutoff, folder_name, dirpath, verbose, plot_simulation_layer_name, plot_simulation_port_index, plot_simulation_z, plot_simulation_x, plot_mode_index, plot_mode_port_name, plot_epsilon, filepath, overwrite, **kwargs)
604 else:
605 time.sleep(0.2)
--> 606 s = modeler.run()
607 for port_in in s.port_in.values:
608 for port_out in s.port_out.values:
File ~/anaconda3/lib/python3.11/site-packages/tidy3d/plugins/smatrix/smatrix.py:502, in ComponentModeler.run(self, path_dir)
499 path_dir = self.get_path_dir(path_dir)
501 batch_data = self._run_sims(path_dir=path_dir)
--> 502 return self._construct_smatrix(batch_data=batch_data)
File ~/anaconda3/lib/python3.11/site-packages/tidy3d/plugins/smatrix/smatrix.py:493, in ComponentModeler._construct_smatrix(self, batch_data)
486 port_in_to, mode_index_in_to = col_out
487 coords_to = dict(
488 port_in=port_in_to,
489 mode_index_in=mode_index_in_to,
490 port_out=port_out_to,
491 mode_index_out=mode_index_out_to,
492 )
--> 493 s_matrix.loc[coords_to] = mult_by * s_matrix.loc[coords_from].values
495 return s_matrix
File ~/anaconda3/lib/python3.11/site-packages/xarray/core/dataarray.py:222, in _LocIndexer.__setitem__(self, key, value)
219 labels = indexing.expanded_indexer(key, self.data_array.ndim)
220 key = dict(zip(self.data_array.dims, labels))
--> 222 dim_indexers = map_index_queries(self.data_array, key).dim_indexers
223 self.data_array[dim_indexers] = value
File ~/anaconda3/lib/python3.11/site-packages/xarray/core/indexing.py:190, in map_index_queries(obj, indexers, method, tolerance, **indexers_kwargs)
188 results.append(IndexSelResult(labels))
189 else:
--> 190 results.append(index.sel(labels, **options))
192 merged = merge_sel_results(results)
194 # drop dimension coordinates found in dimension indexers
195 # (also drop multi-index if any)
196 # (.sel() already ensures alignment)
File ~/anaconda3/lib/python3.11/site-packages/xarray/core/indexes.py:488, in PandasIndex.sel(self, labels, method, tolerance)
486 indexer = self.index.get_loc(label_value)
487 except KeyError as e:
--> 488 raise KeyError(
489 f\"not all values found in index {coord_name!r}. \"
490 \"Try setting the `method` keyword argument (example: method='nearest').\"
491 ) from e
493 elif label_array.dtype.kind == \"b\":
494 indexer = label_array
KeyError: \"not all values found in index 'port_in'. Try setting the `method` keyword argument (example: method='nearest').\""
} What do you suggest? Thanks once more. |
It looks like it's not finding the data for port |
Hi @yaugenst thanks for the comment. I assumed the same but I had run several simulations, first one without element mapping and second one with the mapping. They took the same (FlexCredits). So I added the run_only for one port and then the FlexCredits halved, the simulation completed, but the retrieving / assembling of results fails as detailed. |
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
Result is:
--> 114 sp = gt.write_sparameters(
115 component = sw_test,
116 layer_stack = LAYER_STACK,
117 material_mapping = md,
118 symmetry = (0,-1,1),
119 )
TypeError: write_sparameters() got an unexpected keyword argument 'symmetry'
I have looked into the different .py files for the tidy3d plugin, and to my very poor understanding it seems the native Tidy3D symmetry feature is not included in gplugin/tidy3d.
If that is the case, please consider including it (saves time-money).
The text was updated successfully, but these errors were encountered: