-
Notifications
You must be signed in to change notification settings - Fork 44
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
Simulation.run_time accepts RunTimeSpec #1495
Conversation
7867ca7
to
6302962
Compare
tidy3d/components/simulation.py
Outdated
@cached_property | ||
def n_max(self) -> float: | ||
"""Maximum refractive index in the ``Simulation``.""" | ||
eps_max = max(abs(struct.medium.eps_model(self.freq_max)) for struct in self.structures) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to use the maximum frequency instead of the central one? It is possible that the maximum index is found at lower frequencies, no?
Also, if you are looking for max(n), that should be max(Re{sqrt(ε)}), not Re{sqrt(argmax(|ε|))}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, so this was basically refactored out of our previous wvl_min_material
, which grabbed the minimum wavelength in the material. I guess I should probably do something like take the central frequency or average over frequencies.
Also, if you are looking for max(n), that should be max(Re{sqrt(ε)}), not Re{sqrt(argmax(|ε|))}.
I wonder also if this means our previous function was wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function used anywhere? In the mesher we just use eps_complex_to_nk
, which is probably best so you don't have to think about it.
tidy3d/tidy3d/components/grid/mesher.py
Line 437 in 89d9d43
n, k = structure.medium.eps_complex_to_nk( |
Note that if you want to average over freqs we may be running in the issue that not all eps_model
-s may work for a list of freqs. #1290
Personally I feel like using the central frequency may be fine. This is all going to be approximate in various ways anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, let's use central frequency and I'll just use eps_complex_to_nk(eps_model(source_time.freq0))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some changes here: maybe double check them to see if they make sense (they affect wvl_mat_min
too. https://github.com/flexcompute/tidy3d/pull/1495/files
6302962
to
7c42cce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some small comments. Apart from that, and as part of testing, we should sprinkle this around in a bunch of notebooks. I feel like in some cases it will be quite long because of the default Q=100, but not sure.
tidy3d/components/source.py
Outdated
def end_time(self) -> float | None: | ||
"""Time after which the source is effectively turned off / close to zero amplitude.""" | ||
if not self.remove_dc_component: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your thinking here in that the DC signal will remain, but I think the same end_time
could apply regardless. For example, frequency domain fields should still be correct after that end time, except at very low frequencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea true. maybe I'm confused as to why the user would want to not remove DC component? is it more of an internal thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in cases where you do want to simulate low frequencies, or rather a broadband pulse that also includes low frequencies. I think mostly relevant for RF. But yeah even if you turn it off you don't want to run indefinitely (the DC component won't decay anyway...) you just might need to do some extra normalization for the low-frequency components.
tidy3d/components/simulation.py
Outdated
run_time: pydantic.PositiveFloat = pydantic.Field( | ||
..., | ||
run_time: pydantic.PositiveFloat | RunTimeSpec = pydantic.Field( | ||
RunTimeSpec(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little nervous setting this as default - I'd rather keep it a required field and we can just add it to various examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventually it would be nice to be able to just not specify anything for run_time but I think for the testing phase we can make it required and see how it goes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah cause we do charge a minimum of 10% of estimated cost, so if the run time is often way overestimated, it may not be good for users.
tidy3d/components/simulation.py
Outdated
) | ||
|
||
""" Accounting """ | ||
|
||
@cached_property | ||
def _run_time(self) -> float: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check if run_time
is used on the backend and replace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, should I give that a shot or do you want to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually didn't see anything in tidy3d-core (at least on the python side) that uses .run_time
explicitly. (or that seemed like it should use _run_time
. So maybe it's best you take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found one place
tidy3d/components/run_time_spec.py
Outdated
) | ||
|
||
quality_factor: pd.PositiveFloat = pd.Field( | ||
100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lucas-flexcompute does this value mean that for a pretty feed-forward simulation, say a directional coupler, the run time will be overestimated by about a factor of 100?
I'm also curious how it will compare in some of the notebooks vs. the |
It also occurred to me that this will potentially conflict with #1473 so just a note to self that the adjoint run_time calculation will probably need to also change to |
@momchil-flex @lucas-flexcompute
In general, it seems to over estimate the run time by about 1e2 for non-resonant devices.. but does pretty well for the resonant ones. Kind of as we expected given a default Q value of 100. Maybe this doesn't bode well for the usefulness of the run_time spec? at least as a default value for EDIT: you can see my tests here: |
Or set the default Q to 1 if we want to provide a default at all. |
I guess it just so happens that the resonant ones have characteristic Qs of about 100?
Yeah so that's what I kinda thought we would do at the start of this, i.e. have a good estimate for feed-forward, and then ask user to give us a Q estimate if it's not feed-forward. Or like use a default of like 3 (or a "safety factor" of 3x) to make sure we don't underestimate but also we don't way overestimate in the feedforward case.
Making it required would definitely be safer, just a little more annoying - but maybe still worth it? |
Maybe a safe, default value of 1-10 would make sense. But I do worry about people getting confused if they have resonant devices. Also a major advantage of this (in my mind) would be to make the |
until then, this would basically just be a convenient way to estimate the run time, perhaps that's already useful enough, even if it doesn't replace the run time as a default. |
I forget all our discussions about this, but I don't think we'd ever have something like this by default, because of the danger of it running way too long in some cases? So even if we implement something like this I would still think it would be a "use at your own risk" kinda thing. |
Alright, so let's try to wrap this up for 2.7 or just close it. I think based on the discussions above, we've come to the following conclusions:
Maybe my preference is to keep both Thoughts? |
3b76859
to
b8b3803
Compare
So to clarify what you are proposing is keep |
Yea basically the most conservative option, because why not.. if people like using this feature (and I think it's actually more convenient than setting run_time in a lot of cases) then we can enhance it later or make it more streamlined to use |
Yeah, let's do that. |
f49906d
to
492a10a
Compare
k, got this ready to go. Not sure if there's an associated backend commit? |
492a10a
to
b33c233
Compare
…ally based on simulation properties.
b33c233
to
45c98f6
Compare
Took a first stab at this. It's a bit messy and there are some edge cases but seems to work. We should discuss before I do anything more to it.
Note: the evaluated run_time is now
Simulation._run_time
so there will be bugs unless we change this in eg. the backend. I think I got all the instances in the front end.