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

static jax structures & dispersive adjoint #1281

Merged
merged 1 commit into from
Dec 3, 2023

Conversation

tylerflex
Copy link
Collaborator

Support for dispersive materials in adjoint (with shape / boundary optimization).
Adds two new adjoint structure classes:

  • JaxStructureStaticMedium combines a jax geometry with a tidy3d medium.
  • JaxStructureStaticGeometry combines a tidy3d geometry with a jax medium.

The former can be used to pair a differentiable geometry (JaxPolySlab) with any medium, eg a dispersive medium or something from the material library (like a metal).

This PR mainly generalizes the JaxGeometry internals to an abstract class and then splits into the three JaxStructure, JaxStructureStaticMedium, and JaxStructureStaticGeometryto handle the field definitions and to do different adjoint handling depending on their _differentiable_fields class attribute.

Among another static geometry structure, the tests have a JaxStructureStaticMedium containing a JaxBox and silver from our material library. So I think we can begin using this for eg metallic antenna design.

@tylerflex tylerflex marked this pull request as draft December 1, 2023 19:07
…entiable and static geometry / medium in JaxStructure
@tylerflex tylerflex force-pushed the tyler/adjoint/dispersive/static2 branch from f69f70b to ca7872c Compare December 1, 2023 23:18
@tylerflex tylerflex marked this pull request as ready for review December 1, 2023 23:18
@tylerflex tylerflex requested a review from e-g-melo December 1, 2023 23:18
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.

Awesome. Somewhat related, and also related to our discussion yesterday, we should (or do we already?) validate that JaxSimulations do not have nonlinear media in either their static structures or their JaxStructureStaticMedium ones.

@@ -253,6 +257,14 @@ def make_sim(

jax_geo_group = JaxGeometryGroup(geometries=[jax_polyslab1, jax_polyslab1])
jax_struct_group = JaxStructure(geometry=jax_geo_group, medium=jax_med1)

jax_struct_static_med = JaxStructureStaticMedium(
geometry=jax_box1, medium=td.Medium() # material_library["Ag"]["Rakic1998BB"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you forget to uncomment the silver?

@tylerflex
Copy link
Collaborator Author

Yea good point. I can either do that in this PR or a separate one but would be a good idea. We could also consider just warning because the gradients might be approximately correct in some contexts?

@momchil-flex
Copy link
Collaborator

I guess warning could be fine too yeah.

@e-g-melo
Copy link
Collaborator

e-g-melo commented Dec 2, 2023

Hi @tylerflex!

I tried the JaxStructureStaticMedium and JaxStructureStaticGeometry within the adjoint examples 5 and 3, respectively, and both finished with an error (16:54:02 -03 ERROR: Error running task!).

In the JaxStructureStaticMedium class, the error happened when inserting both a non-dispersive or a dispersive medium (['Si3N4']['Philipp1973Sellmeier']): task id

In the JaxStructureStaticGeometry test, I've replaced the JaxBox by a Box object, and the same error has happened: task id.

@tylerflex
Copy link
Collaborator Author

This is probably because we'd need to build a solver to use this front end commit. Can you try with a run_local instead of run?

@tylerflex
Copy link
Collaborator Author

Note this PR adds a new field to the Jax info datastructure to remember what kind of input structures were used. So we need to make sure this is handled in the backend too. It might not even work with run local. @momchil-flex if it doesn't maybe could you build a solver using this commit so i can test?

@e-g-melo
Copy link
Collaborator

e-g-melo commented Dec 2, 2023

Ok.. got it!

@momchil-flex
Copy link
Collaborator

I've built a release and associated it to frontend version 2.5.0, modify version.py to use.

@tylerflex
Copy link
Collaborator Author

Thanks!

Copy link
Collaborator

@e-g-melo e-g-melo left a comment

Choose a reason for hiding this comment

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

Hi, @tylerflex and @momchil-flex!

It is working now! The gradients were calculated with no errors in both examples.

Thanks for this feature Tyler! Taking into account dispersive materials in the simulation adds another level of interest to the adjoint.

@tylerflex
Copy link
Collaborator Author

Great! Maybe we can update those examples to use the new structure and materials from your test. Could you open a PR in the docs repo? (Assuming everything else worked the same too, if there were some complications like poor performance, we can leave them out for now). Also at some point it might be good to do a metallic inverse design example. Maybe an antenna. I will get to field projection support hopefully in the coming weeks

@e-g-melo
Copy link
Collaborator

e-g-melo commented Dec 3, 2023

Sure, I will run the complete optimizations and update them in docs.

@tylerflex tylerflex merged commit 86d9a76 into pre/2.5 Dec 3, 2023
@tylerflex tylerflex deleted the tyler/adjoint/dispersive/static2 branch December 3, 2023 15:05
@tylerflex
Copy link
Collaborator Author

Thanks Emerson. @momchil-flex ill do nonlinear warnings in a separate PR

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