Skip to content
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

Momchil/sym data #297

Merged
merged 5 commits into from
Apr 13, 2022
Merged

Momchil/sym data #297

merged 5 commits into from
Apr 13, 2022

Conversation

momchil-flex
Copy link
Collaborator

  • Field data with symmetries is now loaded and saved in the smallest required region only. It is automatically expanded upon field_data = sim_data[monitor_name]
  • New PermittivityData and PermittivityMonitor
  • Reorganizing data.py a little bit

@momchil-flex momchil-flex requested a review from tylerflex April 9, 2022 01:15
Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, a few things

  • be sure to put class links in the docstrings where appropriate. also note that the docs probably won't render the types of things like Axis Symmetry.
  • A few more comments won't hurt anyone, especially explaining the _sym_dict usage
  • Consider refactoring getitem in SimulationData.

After these, feel free to merge.

# Apply the correct +/-1 for the data_key component
new_data[{dim_name: flip_inds}] *= sym * self._sym_dict[data_key][dim]
sym_eval = self._sym_dict.get(data_key)
if sym_eval:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sym_eval is not None is recommended here to be explicit. For example, what if it's 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it should be a list, but I agree.

"""Create a new AbstractFieldData subclass by interpolating on the supplied ``new_grid``,
using symmetries as defined by ``sym_center`` and ``symmetry``."""
def apply_syms(self, grid_dict: Dict[str, Coords], sym_center: Coordinate, symmetry: Symmetry):
"""Create a new SpatialCollectionData subclass by interpolating on the supplied
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:class:


Parameters
----------
grid_dict : Dict[str, Coords]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:class: on Coords

Parameters
----------
grid_dict : Dict[str, Coords]
Mapping of the data labels in the SpatialCollectionData to new coordinates on which
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:class:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just apply where appropriate in docstring.

zipped = zip("xyz", sym_center, symmetry)
for dim, (dim_name, center, sym) in enumerate(zipped):
# Continue if no symmetry or the data key is not in the supplied grid_dict
if sym == 0 or not grid_dict.get(data_key):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use grid_dict.get(data_key) is not None instead of not grid_dict.get(data_key).

@@ -349,7 +349,7 @@ def solve(self) -> ModeSolverData:
)

field_data = ModeFieldData(data_dict=data_dict).apply_syms(
plane_grid, self.simulation.center, self.simulation.symmetry
plane_grid.yee.grid_dict, self.simulation.center, self.simulation.symmetry
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call with kwargs here

... name='eps_monitor')
"""

_data_type: Literal["PermittivityData"] = pydantic.Field("PermittivityData")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont think we need these anymore? did we figure that out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need them on the backend. I can show you where if you want to think about how to eliminate them.

----------
axis : Axis
Axis along which to pick the subspace.
ind_beg : int, optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int = 0 instead of Optional

Parameters
----------
axis : Axis
Axis along which to pick the subspace.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of Axis, say Axis index (0,1,2) along which... so people know it's an int

@@ -1018,6 +1133,26 @@ def __getitem__(self, monitor_name: str) -> Union[Tidy3dDataArray, xr.Dataset]:
monitor_data = self.monitor_data.get(monitor_name)
if isinstance(monitor_data, MonitorData):
return monitor_data.data
if isinstance(monitor_data, SpatialCollectionData):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chunk probably needs a bit more documentation at the least. Alternatively, we could create methods / properties in MonitorData, SpatialCollectionData, PermittivityData that define what gets returned when an object of this type is selected by SimulationData. For example

class MonitorData(...):

    # some stuff

    @property
    sim_data_getitem(self) -> xr.DataArray:
         """What gets returned by sim_data['monitor_data_name']"""
         
         return self.data

and then in SimulationData.__get_item__:

def __getitem__(self, name):
    monitor_data = self.monitor_data.get(monitor_name)
    if monitor_data is None:
        raise Tidy3dKeyError("Monitor '{monitor_name}' not found in SimulationData.")
    return monitor_data.sim_data_getitm

what do you think? Would just require putting each of these is instance blocks in their respective classes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@momchil-flex momchil-flex merged commit 4e3cfa9 into develop Apr 13, 2022
@momchil-flex momchil-flex deleted the momchil/sym_data branch April 16, 2022 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants