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

Added CustomSourceTime #994

Merged
merged 1 commit into from
Jul 27, 2023
Merged

Added CustomSourceTime #994

merged 1 commit into from
Jul 27, 2023

Conversation

caseyflex
Copy link
Contributor

@caseyflex caseyflex commented Jul 11, 2023

Features:

  • Validation heuristic for sufficiently fast sampling to avoid interpolation artifacts

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.

added a few notes for discussion

tidy3d/components/source.py Outdated Show resolved Hide resolved
tidy3d/components/source.py Show resolved Hide resolved
tidy3d/components/source.py Outdated Show resolved Hide resolved
tidy3d/components/source.py Outdated Show resolved Hide resolved
tidy3d/components/source.py Show resolved Hide resolved
@caseyflex caseyflex self-assigned this Jul 12, 2023
@momchil-flex
Copy link
Collaborator

I think Tyler's question about using interp instead of sel makes sense, and also validating under-sampling.

@caseyflex caseyflex changed the base branch from develop to pre/2.4 July 19, 2023 19:24
@caseyflex caseyflex requested a review from tylerflex July 19, 2023 19:25
tidy3d/components/simulation.py Outdated Show resolved Hide resolved
@tylerflex tylerflex added the 2.4 label Jul 21, 2023
@caseyflex caseyflex force-pushed the casey/customsourcetime branch 5 times, most recently from 4dde2c3 to 00f56d2 Compare July 25, 2023 17:31
@caseyflex caseyflex requested a review from tylerflex July 25, 2023 17:31
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 to me, let's wait to merge until @momchil-flex has a final look in conjunction with the backend tests, thanks @caseyflex !

@caseyflex caseyflex marked this pull request as draft July 27, 2023 16:08
@caseyflex caseyflex marked this pull request as ready for review July 27, 2023 17:42
@caseyflex caseyflex requested a review from tylerflex July 27, 2023 17:43
@caseyflex
Copy link
Contributor Author

looks good to me, let's wait to merge until @momchil-flex has a final look in conjunction with the backend tests, thanks @caseyflex !

I changed a minor thing -- allowing a dt of tolerance in covering the Simulation.tmesh, and just using the end values if needed in this case.

@tylerflex
Copy link
Collaborator

Just occurred to me, eventually, it would probably be useful to provide a class method to generate this source time from data in the frequency domain as well.

continue
times = dataset.values.coords["t"].values
if (
min(times) >= self.tmesh[0] + CUSTOMSOURCETIME_TOL * self.dt
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the intuition behind this choice? so the user can essentially start the time coordinates at dt and end them at run_time - dt and it should pass?

@caseyflex
Copy link
Contributor Author

caseyflex commented Jul 27, 2023 via email

@caseyflex
Copy link
Contributor Author

caseyflex commented Jul 27, 2023 via email

@caseyflex
Copy link
Contributor Author

caseyflex commented Jul 27, 2023 via email

@caseyflex
Copy link
Contributor Author

caseyflex commented Jul 27, 2023 via email

@tylerflex
Copy link
Collaborator

A few things:

  • The point of this validator is to ensure that the user-supplied data is enough to cover the tmesh right? so this change seems to reduce the size of the range from (tmesh[0], tmesh[-1]) to (tmesh[0] + 1.1 dt, tmesh[-1] - 1.1dt). Basically with this change, it seems a could not supply data for t=0 and a nan would get created on our side right? That seems problematic.
  • the tmesh is np.arange(0.0, self.run_time + dt, dt), np.arange doesnt include the final value so the final value is actually self.run_time, just FYI.
image

So the problem you're having is that if a user supplies run_time=x to the Simulation and then makes a t coordinate grid for the custom time source dataset using np.linspace(0, run_time, N), the validator will sometimes complain due to numerical precision? If so, maybe one option is to relax the validator for the [0] and [-1] values by -fp_eps and +fp_eps (opposite direction as current?) and then make sure to also apply this on the solver side?

@caseyflex
Copy link
Contributor Author

caseyflex commented Jul 27, 2023

A few things:

  • The point of this validator is to ensure that the user-supplied data is enough to cover the tmesh right? so this change seems to reduce the size of the range from (tmesh[0], tmesh[-1]) to (tmesh[0] + 1.1 dt, tmesh[-1] - 1.1dt). Basically with this change, it seems a could not supply data for t=0 and a nan would get created on our side right? That seems problematic.
  • the tmesh is np.arange(0.0, self.run_time + dt, dt), np.arange doesnt include the final value so the final value is actually self.run_time, just FYI.
image So the problem you're having is that if a user supplies `run_time=x` to the Simulation and then makes a `t` coordinate grid for the custom time source dataset using `np.linspace(0, run_time, N)`, the validator will sometimes complain due to numerical precision? If so, maybe one option is to relax the validator for the [0] and [-1] values by -fp_eps and +fp_eps (opposite direction as current?) and then make sure to also apply this on the solver side?

I changed source.py to also account for these edge cases, and produce the end values instead of nan. I also added a test for this. I think the signs on the tolerance are correct.

Can you look at the most recent version? I think 0 tolerance at the start time and dt tolerance at the end time is reasonable, since we warn for sampling below dt anyway, it is fair to extrapolate one dt past the stop time. Although fp_eps would also be fine at the stop time.

@tylerflex
Copy link
Collaborator

Alright momchil pointed me to the backend code and the handling for out of bounds and that looks fine. I thought for a second that we just evaluated the amp function server side and injected whatever came out of that. I think from my perspective it looks good to go.

@momchil-flex momchil-flex merged commit 3966137 into pre/2.4 Jul 27, 2023
0 of 11 checks passed
@momchil-flex momchil-flex deleted the casey/customsourcetime branch July 27, 2023 18:49
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.

3 participants