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

Introduce SubpixelSpec to allow for selecting subpixel averaging methods on different materials #1689

Open
wants to merge 2 commits into
base: pre/2.7
Choose a base branch
from

Conversation

weiliangjin2021
Copy link
Collaborator

@weiliangjin2021 weiliangjin2021 commented May 8, 2024

New API

subpixel = td.SubpixelSpec(
    dielectric = True,
    metal = td.Staircasing()/td.VolumetricAveraging(staircase_normal_component=True),
    pec = td.Staircasing()/td.HeuristicPECStaircasing()/td.PECConformal(timestep_reduction=0.1),
)

Metal is defined as Re[eps]<1 at the central frequency.

You can still set subpixel=True/False:

  • True using the default SubpixelSpec(): dielectric subpixel averaging on dielectric interface, staircasing on metal interface, and conformal (previously called Benkler) scheme on PEC;
  • False: staircasing on any material interface.

TODO

  • Fix failed adjoint tests, test_IO, etc.
  • Update API in doc
  • Various places validating subpixel field

Note

  • The default subpixel method for PEC is now Benkler (renamed to MetalConformal). The default setting will decrease the time step size by 30%. But this deduction will only take effect if we find any material is PEC in scene.mediums.
  • In Volumetric Averaging, it has a field staircase_normal_component. When True, apply staircasing if the field component is mostly normal to the interface, since volumetric averaging won't help there.

Open question:

  • For dielectric materials, it's always worse to apply volume averaging. So currently, dielectric still only take boolean values. I'm not sure if it's better to be consistent with other materials (pec, metal) for dielectric to also take Staircasing and detailed subpixel method name.

@weiliangjin2021 weiliangjin2021 marked this pull request as draft May 8, 2024 18:31
@weiliangjin2021 weiliangjin2021 added the awaiting backend not to be merged as backend is not finalized label May 8, 2024
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.

I think the API looks pretty good. Nothing stands out to me as an issue.

One thing is that we should choose the class names carefully. Specifically,

BenklerSubpixel
HeuristicSubpixel

are both not clear from the title what exactly they are and when to use them. I'm not sure about the specific details, eg maybe these are commonly used names in the field, but if there are any more intuitive names for these, we should consider using them? Or even making up our own.

@weiliangjin2021
Copy link
Collaborator Author

One thing is that we should choose the class names carefully. Specifically,

BenklerSubpixel
HeuristicSubpixel

are both not clear from the title what exactly they are and when to use them. I'm not sure about the specific details, eg maybe these are commonly used names in the field, but if there are any more intuitive names for these, we should consider using them? Or even making up our own.

Good point. I have concerns about the names as well, but forgot to bring it up. E.g. Benkler is too specific. How about a general name ConformalSubpixel, since people usually refers to it as conformal mesh in RF?

Regarding Heuristic, how about HeuristicStaircasingSubpixel? @momchil-flex

@momchil-flex
Copy link
Collaborator

Yeah, I agree with both of those suggestions. Conformal is commonly used. Heuristic is just something Victor had implemented a long time ago that we are keeping for backwards compatibility. :D It is not in any way commonly known in the literature.

@weiliangjin2021
Copy link
Collaborator Author

One more question on names: is it necessary for each of them ending inSubpixel? StaircasingSubpixel and ConformalSubpixel sounds strange, because the two words in the former are contradictory; while the two in the latter mean the same.

@momchil-flex
Copy link
Collaborator

One more question on names: is it necessary for each of them ending inSubpixel? StaircasingSubpixel and ConformalSubpixel sounds strange, because the two words in the former are contradictory; while the two in the latter mean the same.

Yeah, I think dropping Subpixel makes sense.

For dielectric materials, it's always worse to apply volume averaging. So currently, dielectric still only take boolean values. I'm not sure if it's better to be consistent with other materials (pec, metal) for dielectric to also take Staircasing and detailed subpixel method name.

I think it's probably better in the long run yeah. You don't have to allow volumetric to be an actual option if it requires more effort on the backend. What should we call the dielectric subpixel?

@weiliangjin2021
Copy link
Collaborator Author

Still haven't figured out a good name for dielectric subpixel averaging, so it remains as boolean for now. Docstrings have been updated. Now the new API looks like this

subpixel = td.SubpixelSpec(
    dielectric = True,
    metal = td.Staircasing()/td.VolumetricAveraging(),
    pec = td.Staircasing()/td.HeuristicPECStaircasing()/td.MetalConformal(timestep_reduction=0.1),
)

@tylerflex how do I fix the failing test_IO.py that loads an incompatible tests/sims/simulation_sample.h5 and tests/sims/simulation_sample.json from 2.7.0rc1 and rc2?

@tylerflex
Copy link
Collaborator

@weiliangjin2021 weiliangjin2021 marked this pull request as ready for review May 14, 2024 22:37
@weiliangjin2021
Copy link
Collaborator Author

hm, try running this script? https://github.com/flexcompute/tidy3d/blob/pre/2.7/scripts/sample.py

Thanks, that fixes it.

@weiliangjin2021 weiliangjin2021 changed the title Introduce SubpixelSpec to allow for several subpixel averaging methods on different materials Introduce SubpixelSpec to allow for selecting subpixel averaging methods on different materials May 14, 2024
@weiliangjin2021
Copy link
Collaborator Author

Sorry another question @tylerflex: it seems that allowing a simulation field to be the union of a basic type (e.g. bool in subpixel and float in run_time) and a class is causing issues in test_log here: the warning list is empty when subpixel or runt_time take an object although I can see the warning on screen. It's not empty if the two fields take bool/float.

@tylerflex
Copy link
Collaborator

Sorry another question @tylerflex: it seems that allowing a simulation field to be the union of a basic type (e.g. bool in subpixel and float in run_time) and a class is causing issues in test_log here: the warning list is empty when subpixel or runt_time take an object although I can see the warning on screen. It's not empty if the two fields take bool/float.

Hm, not sure about this, sorry. Maybe @dbochkov-flexcompute has some idea?

@dbochkov-flexcompute
Copy link
Contributor

Sorry another question @tylerflex: it seems that allowing a simulation field to be the union of a basic type (e.g. bool in subpixel and float in run_time) and a class is causing issues in test_log here: the warning list is empty when subpixel or runt_time take an object although I can see the warning on screen. It's not empty if the two fields take bool/float.

It seems to be related to the fact that pydantic tries to initialize a field with all possible options, if no guidance for it is given. That is, adding discriminator=TYPE_TAG_STR into metal and pec fields of SubpixelSpec resolves the issue

@weiliangjin2021
Copy link
Collaborator Author

Sorry another question @tylerflex: it seems that allowing a simulation field to be the union of a basic type (e.g. bool in subpixel and float in run_time) and a class is causing issues in test_log here: the warning list is empty when subpixel or runt_time take an object although I can see the warning on screen. It's not empty if the two fields take bool/float.

It seems to be related to the fact that pydantic tries to initialize a field with all possible options, if no guidance for it is given. That is, adding discriminator=TYPE_TAG_STR into metal and pec fields of SubpixelSpec resolves the issue

That is working! thanks

Copy link
Contributor

@dbochkov-flexcompute dbochkov-flexcompute 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! just one thing: would it make sense to rename MetalConformal to PECConformal since it goes into pec: but not metal: field?

tidy3d/components/eme/simulation.py Outdated Show resolved Hide resolved
@weiliangjin2021
Copy link
Collaborator Author

looks good to me! just one thing: would it make sense to rename MetalConformal to PECConformal since it goes into pec: but not metal: field?

We plan to add good conductor handling in the near quarter (a new field good_conductor in SubpixelSpec). I hope I can reuse MetalConformal class in the field.

@weiliangjin2021
Copy link
Collaborator Author

looks good to me! just one thing: would it make sense to rename MetalConformal to PECConformal since it goes into pec: but not metal: field?

We plan to add good conductor handling in the near quarter (a new field good_conductor in SubpixelSpec). I hope I can reuse MetalConformal class in the field.

Now as I read more about good conductor subpixel, it's likely to have quite different fields compared to PEC-type conformal. In that regard, there is no need to share this class between PEC and metal, so it's a good idea to rename it to PECConformal.

@weiliangjin2021 weiliangjin2021 force-pushed the weiliang/subpixel branch 3 times, most recently from 5f8fb18 to df349c3 Compare May 21, 2024 18:42
Copy link
Collaborator

@momchil-flex momchil-flex left a comment

Choose a reason for hiding this comment

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

Few minor comments about the current code. Otherwise, two more questions to discuss further:

  • for dielectric, should we avoid using boolean but define an explicitly named spec instead (also in view of defining different ones in the future)
  • are we eventually going to have a good_conductor kind of field in SubpixelSpec too, and how is that going to interact with metal?

title="Subpixel Averaging",
description="If ``True``, uses subpixel averaging of the permittivity "
"based on structure definition, resulting in much higher accuracy for a given grid size.",
"based on structure definition, resulting in much higher accuracy for a given grid size. "
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to flip this message around and say what SubpixelSpec does; then say what setting subpixel=True corresponds to in terms of a SubpixelSpec (dielectric subpixel, everything else staircased).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

when subpixel=True, now conformal is also applied to PEC, as it is in general much more accurate than staircasing.

tidy3d/components/simulation.py Outdated Show resolved Hide resolved
tidy3d/components/subpixel_spec.py Outdated Show resolved Hide resolved
tidy3d/components/subpixel_spec.py Outdated Show resolved Hide resolved
@weiliangjin2021
Copy link
Collaborator Author

  • are we eventually going to have a good_conductor kind of field in SubpixelSpec too, and how is that going to interact with metal?

In the 1st release, we might just limit good_conductor to Medium type, as surface-impedance model is usually applied to approximate the permittivity as purely imaginary coming from DC conductivity. In the next step, maybe we can add a field to medium to indicate whether it's allowed to be handled as surface-impedance model. If allowed and the material has Im[ep]/Re[ep] larger than a threshold, it'll be approximated as Medium type at the central frequency.

…s on different materials

Validate dielectric subpixel in adjoint plugin

Enable VolumetricAveraging to automatically switch to Staircasing if the field is substantially normal to the interface
@weiliangjin2021 weiliangjin2021 added the 2.7 will go into version 2.7.* label May 24, 2024
@tylerflex tylerflex added the blocking This version can't be released until this PR is merged label May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.7 will go into version 2.7.* awaiting backend not to be merged as backend is not finalized blocking This version can't be released until this PR is merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants