Skip to content

Commit

Permalink
tyler fixes remaining autograd
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflex committed Aug 16, 2024
1 parent 4a7ed1e commit 0478a7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
49 changes: 24 additions & 25 deletions tidy3d/plugins/autograd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,63 +109,61 @@ Finally, the regular `web.run()` and `web.run_async()` functions have their deri

The following components are traceable as inputs to the `td.Simulation`

rectangular prisms
- `Box.center`
- `Box.size`

polyslab (including those with dilation or slanted sidewalls)
- `PolySlab.vertices`

regular mediums
- `Medium.permittivity`
- `Medium.conductivity`

spatially varying mediums (for topology optimization mainly)
- `CustomMedium.permittivity`
- `CustomMedium.eps_dataset`

groups of geometries with the same medium (for faster processing)
- `GeometryGroup.geometries`

<<<<<<< HEAD
complex and self-intersecting polyslabs
- `ComplexPolySlab.vertices`

=======
>>>>>>> develop
dispersive materials
- `PoleResidue.eps_inf`
- `PoleResidue.poles`

spatially dependent dispersive materials:
- `CustomPoleResidue.eps_inf`
- `CustomPoleResidue.poles`

The following components are traceable as outputs of the `td.SimulationData`
The following data types are traceable as outputs of the `td.SimulationData`

- `ModeData.amps`
- `DiffractionData.amps`
- `FieldData.field_components`
- `FieldData` operations:
- `FieldData.flux`
- `SimulationData.get_intensity(fld_monitor_name)`
- `SimulationData.get_poynting(fld_monitor_name)`

We currently have the following restrictions:

- All monitors in the `Simulation` must be single frequency only.
- Only 500 max structures containing tracers can be added to the `Simulation` to cut down on processing time. In the future, `GeometryGroup` support will allow us to relax this restriction.
- `web.run_async` for simulations with tracers does not return a `BatchData` but rather a `dict` mapping task name to `SimulationData`. There may be high memory usage with many simulations or a lot of data for each.
- Gradient calculations are done client-side, meaning the field data in the traced structure regions must be downloaded. This can be a large amount of data for large, 3D structures.
We also support the following high level features

### To be supported soon
- gradients for objective functions depending on multi-frequency data with single broadband adjoint source.
- server-side gradient processing by passing `local_gradient=False` to the `web.run()` and related functions.

Next on our roadmap (targeting 2.8 and 2.9, summer 2024) is to support:
We currently have the following restrictions:

- support for multi-frequency monitors in certain situations (single adjoint source).
- server-side gradient processing.
- Only 500 max structures containing tracers can be added to the `Simulation` to cut down on processing time. If you hit this, try using `GeometryGroup` to group any structures with the same `.medium` to relax the requirement.

- `FieldData` operations:
- `FieldData.flux`
- `SimulationData.get_intensity`
- `SimulationData.get_poynting`
### To be supported soon

- `PoleResidue` and other dispersive models.
- custom (spatially-dependent) dispersive models, allowing topology optimization with metals.
Next on our roadmap (targeting 2.8 and 2.9, fall 2024) is to support:

<<<<<<< HEAD
=======
- `ComplexPolySlab`
- Field projection support
- Automatic handling of all broadband objective functions using a fitting approach.

>>>>>>> develop
Later this year (2024), we plan to support:

- `TriangleMesh`.
Expand All @@ -185,5 +183,6 @@ To convert existing tidy3d front end code to be autograd compatible, will need t
- `float()` is not supported as far as I can tell.
- `isclose()` -> `np.isclose()`
- `array[i] = something` needs a different approach (happens in mesher a lot)
- be careful with `+=` in autograd, it can fail silently..
- whenever we pass things to other modules, like `shapely` especially, we need to be careful that they are untraced.
- I just made structures static before any meshing, as a cutoff point. So if we add a new `make_grid()` call somewhere, eg in a validator, just need to be aware.
- I just made structures static (`obj = obj.to_static()`) before any meshing, as a cutoff point. So if we add a new `make_grid()` call somewhere, eg in a validator, just need to be aware.
8 changes: 0 additions & 8 deletions tidy3d/web/api/autograd/autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import tidy3d as td
from tidy3d.components.autograd import AutogradFieldMap, get_static
from tidy3d.components.autograd.derivative_utils import DerivativeInfo
<<<<<<< HEAD
=======
from tidy3d.components.data.sim_data import AdjointSourceInfo
>>>>>>> develop

from ...core.s3utils import download_file, upload_file
from ..asynchronous import DEFAULT_DATA_DIR
Expand Down Expand Up @@ -802,12 +799,7 @@ def postprocess_adj(
# todo: handle multi-frequency, move to a property?
frequencies = {src.source_time.freq0 for src in sim_data_adj.simulation.sources}
frequencies = list(frequencies)
<<<<<<< HEAD
assert len(frequencies) == 1, "Multiple adjoint freqs found"
freq_adj = frequencies[0]
=======
freq_adj = frequencies[0] or None
>>>>>>> develop

eps_in = np.mean(structure.medium.eps_model(freq_adj))
eps_out = np.mean(sim_data_orig.simulation.medium.eps_model(freq_adj))
Expand Down

0 comments on commit 0478a7b

Please sign in to comment.