Skip to content

Immutable DataArrays for RF data #2715

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

Draft
wants to merge 5 commits into
base: dario/rf_endpoints
Choose a base branch
from

Conversation

dmarek-flex
Copy link
Contributor

@dmarek-flex dmarek-flex commented Aug 4, 2025

WIP attempt at providing immutable DataArray for microwave quantities. The goal here is to get rid of methods like ImpedanceCalculator._set_data_array_attributes, which add some simple data attributes for users.

This can work, but it just seems like a lot of code to get some fairly simple functionality, namely providing units and name for a DataArray.

@dmarek-flex dmarek-flex changed the title Immutable DataArrays for RF solver Immutable DataArrays for RF data Aug 4, 2025
@dmarek-flex
Copy link
Contributor Author

@daquinteroflex @yaugenst-flex Do you think this approach is better for packaging microwave data arrays?

If yes, I will continue by improving some of the data arrays used and produced by the TerminalComponentModeler.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Until we reorganise https://github.com/flexcompute/tidy3d/blob/develop/tidy3d/components/data/data_array.py it should go there. Note the other voltage, index spatial data arrays. Can we reuse?

Copy link
Collaborator

@daquinteroflex daquinteroflex Aug 5, 2025

Choose a reason for hiding this comment

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

I think it's fine to start formalizing these classes even if it's more code, as long as we can reuse or interoperate with the existing ones

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@dmarek-flex dmarek-flex Aug 5, 2025

Choose a reason for hiding this comment

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

Oh that could get confusing. Looks like those VoltageArrays are arrays that have coordinates of voltage, whereas the VoltageArrays I want to introduce hold values related to voltage (with coordinates of freq/time/mode_index)

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is somewhat related to this: https://github.com/flexcompute/tidy3d-core/issues/863
Maybe it is a good time to think about a holistic approach to all this?

Result of voltage computation over remaining dimensions (frequency, time, mode indices).
"""
AxisAlignedPathIntegral._check_monitor_data_supported(em_field=em_field)
voltage = -1.0 * self.compute_integral(field="E", em_field=em_field)
voltage = VoltageIntegralAxisAligned._set_data_array_attributes(voltage)
voltage = VoltageIntegralAxisAligned._make_result_data_array(voltage)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it fine by you that we make this a standalone function rather than a class instantiaton? Like we do for the TerminalComponentModelerData methods https://github.com/flexcompute/tidy3d/blob/bfe45d89cbfd65ead7699b74441157f28f217dc0/tidy3d/plugins/microwave/path_integrals.py#L208C1-L215C69

Copy link
Contributor Author

@dmarek-flex dmarek-flex Aug 7, 2025

Choose a reason for hiding this comment

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

ran into some circular dependency issues, but this is closer to what you want

Comment on lines 121 to 128
def _make_result_data_array(result: DataArray) -> ImpedanceResultTypes:
"""Helper for creating the proper result type."""
cls = ImpedanceFreqDataArray
if "t" in result.coords:
cls = ImpedanceTimeDataArray
if "f" in result.coords and "mode_index" in result.coords:
cls = ImpedanceFreqModeDataArray
return cls.assign_data_attrs(cls(data=result.data, coords=result.coords))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we move this to utils as a standalone function?

Comment on lines 223 to 230
def _make_result_data_array(result: DataArray) -> IntegralResultTypes:
"""Helper for creating the proper result type."""
cls = FreqDataArray
if "t" in result.coords:
return TimeDataArray(data=result.data, coords=result.coords)
cls = TimeDataArray
if "f" in result.coords and "mode_index" in result.coords:
return FreqModeDataArray(data=result.data, coords=result.coords)
return FreqDataArray(data=result.data, coords=result.coords)
cls = FreqModeDataArray
return cls.assign_data_attrs(cls(data=result.data, coords=result.coords))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same this should be a standalone function in utils?

@dmarek-flex dmarek-flex self-assigned this Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants